pabloferz / NIntegration.jl

Multidimensional numerical integration in pure Julia
MIT License
20 stars 1 forks source link

installation error (`LoadError: LoadError: UndefVarError: integral_type not defined`) #10

Closed mmikhasenko closed 4 years ago

mmikhasenko commented 4 years ago
(DoubleRegge) pkg> add https://github.com/pabloferz/NIntegration.jl.git
   Cloning git-repo `https://github.com/pabloferz/NIntegration.jl.git`
  Updating git-repo `https://github.com/pabloferz/NIntegration.jl.git`
[ Info: Assigning UUID bb117bb7-f1e1-572f-856f-2ab8fff0d3c2 to NIntegration
  Updating git-repo `https://github.com/pabloferz/NIntegration.jl.git`
 Resolving package versions...
....
ERROR: LoadError: LoadError: UndefVarError: integral_type not defined

I would love to try the package, as neither QuadGK, nor Cubature fits my needs entirely. https://github.com/giordano/Cuba.jl/issues/28#issuecomment-643221588

any suggestions, how to fix the installation? Thanks in advance

pabloferz commented 4 years ago

I haven't really updated the package in a long time. Let me try to bring it up to date, shouldn't be too hard.

pabloferz commented 4 years ago

You should be able to download the package now.

Notice however that NIntegration has only been written to work with functions with domain in ℝ³ (I should really make the API more general). To get your example in https://github.com/giordano/Cuba.jl/issues/28#issuecomment-643221588 working, you need to run it like this:

using  ForwardDiff
using NIntegration

b(cosθ, ϕ, c) = c[1] * cosθ * sin(ϕ) + c[2] * cosθ^2 * cos(ϕ)^2
f(c) = nintegrate((x, y, z) -> b(x, y, c), (-1.0, -π, 0.0), (1.0, π, 1.0))[1]
ForwardDiff.gradient(f, [1.1, 1.1])

P.S. I don't know if this would give sensible results, but seems to work.

mmikhasenko commented 4 years ago

thanks a lot for checking and updating! It works now, even the automatic differentiation that is super cool. It is faster even than the other pure-julia package HCubature, but significantly slower than c++ Cuba.

I benchmark it against other routines:

Cuba.cuhre    ~  1.3s
HCubature     ~ 30s
NIntegration  ~ 13s

I will try to publish my benchmark example that anyone can run it. Perhaps, it might give some hints for further optimization.

mmikhasenko commented 4 years ago

Thanks again. The issue can be closed

mmikhasenko commented 4 years ago

posted MWE on discourse https://discourse.julialang.org/t/multidimentional-integrals-in-julia-speed-and-automatic-differentiation/41375

pabloferz commented 4 years ago

As far as I know Cuba uses a different strategy than HCubature and NIntegration to subdivide the regions, which might be making it faster here. I have thought on improving the strategy used here but have never gotten to do it (and unfortunately right now I cannot make any promises to work on it soon).

mmikhasenko commented 4 years ago

no problem, thanks for the replies. I used Cuba.cuhre. That is what I found about the algorithm (the description does look similar to yours):

Cuhre Implementation in CUBA
• Deterministic algorithm (uses Genz–Malik cubature rules
of polynomial degree).
• Variance reduction: Globally adaptive subdivision.
• Algorithm: Until the requested accuracy is reached, bisect the region with the largest error along the axis with the largest fourth difference.
• Consistent interface only, same as original DCUHRE
(TOMS Algorithm 698).

from http://www.feynarts.de/cuba/acat05.pdf

pabloferz commented 4 years ago

Of course, there is also some performance left out of the table as the current algorithm is doing unnecessary extra work for your example that is two dimensional (I'll try to generalize it sooner than later).

The point of Steven over discourse is also important, you would have to compare with the same target accuracy.