Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Language for fast numerical integration

  1. Feb 16, 2014 #1
    I have thousands of triple integrals with very ugly integrands to run. Each of those computations takes about an hour in R on a mediocre machine. For uninteresting reasons, when I was initially coding this up, that's the language and machine I had to work with. But now my options are wide open. Does anyone know which languages are particularly fast for numerical integration?

    The truth is I know very little about computers, and am just now being acquainted with basic ideas like environments, compilers, etc. Luckily, I can get some of the intuition from math. But what I generally do best with are languages with less baggage. I've been told that C++ would be hard for me because there's a lot more than just typing in some code that I have to familiarize myself with.

    From what I've seen Fortran and Python are more likely to be useful for computations and that Python is a little slower, but prettier.
     
  2. jcsd
  3. Feb 16, 2014 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

  4. Feb 16, 2014 #3

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    An efficient language is only one aspect of this. Using an efficient algorithm for your particular functions, the shape of the 3-D regions, etc, could give you orders of magnitude speedup compared with something you coded up based on "numerical methods 101".

    But it's impossible to recommend anything without a LOT of information about your problem.
     
  5. Feb 16, 2014 #4
    I hadn't considered that perhaps my issue has more to do with the method employed rather than the language. Is the method more likely the culprit behind an hour-long integration? I was using the cubature package in R that uses the adaptive Genz-Malik algorithm (not that I pretend to understand it). But as I said earlier, I've got an ugly integrand, so perhaps it plays into a weakness of the algorithm. If it helps at all, I'm trying to calculate covariance and cokurtosis of different Gaussian functions of random variables that have normal distributions that have means that are random variables drawn from the same distribution. That's a lot of math in words. I can't find the equation inserter though.

    I understand the general concept of why an interpreter is slower than a compiler, but would the fact that R is an interpreter impact one integration? Would being a compiler speed up doing it multiple times?
     
  6. Feb 16, 2014 #5

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    That's what benchmarks are for.
     
  7. Feb 16, 2014 #6
    I had to look up what that was. So, correct me if I'm wrong, what you're telling me is that I should try out one integration in each of the languages I was considering, run it, and output the time the computation took?
     
  8. Feb 20, 2014 #7

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    If you have 'thousands' of integrals to evaluate, benchmarking could help you decide on which language or numerical method to use to evaluate these integrals.
     
  9. Feb 20, 2014 #8
    Actually, I think it was indeed the algorithm. I split it up into two integrals and added them together. Instead of an hour, this took about four seconds. I guess I'm going to need to learn about numerical methods. Normally, my adviser is totally against me learning math for fun, but he is totally on board with that.
     
  10. Feb 20, 2014 #9
    I'm not sure what you mean by benchmarking. I understand the concept: comparing speed of different languages/methods for the same task. In my last post, I was trying to make sure I understood that your suggestion really meant to get a hold of a bunch of languages and methods and try them out for one specific integral of the basic form I'm dealing with. So am I correct?
     
  11. Feb 21, 2014 #10

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    Benchmarking doesn't have to necessarily include a bunch of different languages and methods. You can use other means to narrow the field. For example, since you are doing intensive numerical calculations, using COBOL, a business language, would be a non-starter. Since you presumably place a premium on speed, this would tend to eliminate interpreted, rather than compiled, languages. If you don't want to develop your integration code from scratch, you would select a language which has a large base of developed code to tackle integration problems, like FORTRAN or C, for example.

    Once the language issue has been whittled down, you can then investigate to determine if there are competing numerical methods which can be used to solve your problem. Not every programmer writes the most efficient code, or even uses the most advanced numerical methods for analysis.

    It's your project. Maybe you have thousands of hours to devote to it. Or maybe you would like to 'Get 'R Done' and move on to something else. You have to make that decision on your own.
     
  12. Feb 21, 2014 #11

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    That sounds a bit more sensible :smile:

    Your original timing didn't make any sense to me. A modern PC will do about 10^9 floating point calculations per second. Call that 10^12 per hour. So if you are integrating a horrible function that takes 1000 operations to calculate each value, and you do something as naive as taking a grid of 1000 x 1000 x 1000 points in your 3-D region, that would take about an hour.

    But Genz-Malik (at least the description I found on the web) claims to be high accuracy (5th or 7th order), so 1000 points in each direction would give you an insane amount of accuracy if it was working the way it's supposed to.

    Since you have found and fixed the basic problem somehow, you might want to quit while you are winning. You got a speed up of about 1000 times by doing something simple. If that's quick enough to get the job done, why put a lot more effort into getting another factor of maybe 2, or 10 if you get lucky?

    Using the same (over-simplistic!) estimates, your factor of 1000 has changed the 1000 x 1000 x 1000 points into 100 x 100 x 100 points (which will be unevenly spaced, if G-M is doing its thing properly). I don't think there is much chance you will get another factor of 1000 by reducing that to 10 x 10 x 10 points. If your functions were smooth enough for 10 x 10 x 10 to give good answers, you wouldn't have hit the original problem.
     
    Last edited: Feb 21, 2014
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Language for fast numerical integration
Loading...