Skip to main content

performance tuning - Integration strategies for oscillatory multidimensional function


I am seeking to integrate a highly oscillatory, multidimensional function. I am currently using NIntegrate's QuasiMonteCarlo approach. However, this is time-consuming and, given my current resources, not very accurate. How can I obtain more reliable estimates of the beasty integral given below? As the function itself will be integrated at a later stage, I am also interested in speeding up the function evaluation.


The integral to be solved:


fun[r_?NumericQ, d_?NumericQ, c_, opts:OptionsPattern[]]:=
NIntegrate[
Cos[(c (d^2+r^2-2 d r Cos[ta] - 3 ((-r+d Cos[ta]) Cos[tb]+d Cos[a] Sin[ta] Sin[tb])^2)) / Abs[d^2+r^2-2 d r Cos[ta]]^(5/2)]
Cos[(c (d^2+r^2+2 d r Cos[ta] - 3 ((r+d Cos[ta]) Cos[tb]+d Cos[a] Sin[ta] Sin[tb])^2)) / Abs[d^2+r^2+2 d r Cos[ta]]^(5/2)]

* Sin[ta]*Sin[tb]/(2*Pi),
{ta,0,Pi},
{tb,0,Pi/2},
{a,0,Pi},
Evaluate@FilterRules[{opts},Options[NIntegrate]]
]

Typically, $d$ = 2, $r$ is in the range from 0 to Infinity (with the small values and $r$=$d$ posing problems), and $c$ is in the range from 100 to 3000. A typical function call is:


AbsoluteTiming[fun[3, 2, 400, Method -> "QuasiMonteCarlo", PrecisionGoal -> 6, 
MaxPoints -> 40000000]]

(* -> {102.3215798,-0.00442278} *)

This issues a NIntegrate::maxp warning and indicates an error estimate of 0.00011. Using the default strategy I obtain:


AbsoluteTiming[
fun[3, 2, 400, MaxRecursion -> 20, Method -> {GlobalAdaptive, MaxErrorIncreases -> 10000}]]
(* -> {9.3912165,-0.00439357} *)

and a NIntegrate::eincr warning. Estimated error: 0.0369.


How to proceed from here? Thank you for your help.



Answer




Since no comment or answer has given as of the time I saw this post, and I don't have enough reputations to leave a comment, let me give a quick answer I used to solve the same kind of problems. I'm sure there must be a better way to do it with Mathematica, so this is just a beginning.


To evaluate an N-dimensional integral with a highly oscillatory integrand (which may peak at a particular small region in the N-dimensional space), I think all built-in methods and strategies of NIntegrate are not applicable. They are either super slow, or give a very inaccurate result which is easy to be proven wrong. Particularly, although to my knowledge Monte Carlo seems to be the best candidate for integrating a general multi-dimensional function (i.e., not knowing the symmetries in the integration region, so can't further simplify it and/or attack it with other strategies designed for special purposes), only when the integrand is smooth enough can Monte Carlo give a relatively good estimate and fast convergence. As a result, I would suggest using so-called "importance-sampling" Monte Carlo, which is not provided in built-in functions yet. (That's odd!)


Fortunately, Thomas Hahn (the author of FormCalc, FeynArts, etc.) has implemented this kind of algorithm in Mathematica (and C/C++ and Fortran as well). It's called the Cuba library. It provides both importance sampling and stratified sampling algorithms, and also the mixture of both. It is still being developed and under maintenance, so at least it works with Mathematica 8. Particularly, I would suggest using its Vegas routine, which is exactly designed for evaluating multi-dimensional integral, to solve your problem. Since it has a good user manual, I would simply refer you to that without further explanation.


However, if you don't mind doing the integral with C/C++, I would say that the Vegas routine provided in the GNU Scientific Library (GSL) converges way faster than the Cuba library does. Not sure why, maybe it has to do with the MathLink interface. Anyway, this is beyond the scope of this site.


Comments

Popular posts from this blog

plotting - Filling between two spheres in SphericalPlot3D

Manipulate[ SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, Mesh -> None, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], {n, 0, 1}] I cant' seem to be able to make a filling between two spheres. I've already tried the obvious Filling -> {1 -> {2}} but Mathematica doesn't seem to like that option. Is there any easy way around this or ... Answer There is no built-in filling in SphericalPlot3D . One option is to use ParametricPlot3D to draw the surfaces between the two shells: Manipulate[ Show[SphericalPlot3D[{1, 2 - n}, {θ, 0, Pi}, {ϕ, 0, 1.5 Pi}, PlotPoints -> 15, PlotRange -> {-2.2, 2.2}], ParametricPlot3D[{ r {Sin[t] Cos[1.5 Pi], Sin[t] Sin[1.5 Pi], Cos[t]}, r {Sin[t] Cos[0 Pi], Sin[t] Sin[0 Pi], Cos[t]}}, {r, 1, 2 - n}, {t, 0, Pi}, PlotStyle -> Yellow, Mesh -> {2, 15}]], {n, 0, 1}]

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1.