@@ -9,11 +9,12 @@ import ChainRulesCore: NoTangent
9
9
import ZygoteRules
10
10
11
11
"""
12
- QuadGKJL(; order = 7)
12
+ QuadGKJL(; order = 7, norm=norm )
13
13
14
14
One-dimensional Gauss-Kronrod integration from QuadGK.jl.
15
- This method also takes the optional argument `order`,
16
- which is the order of the integration rule.
15
+ This method also takes the optional arguments `order` and `norm`.
16
+ Which are the order of the integration rule
17
+ and the norm for calculating the error, respectively
17
18
## References
18
19
@article{laurie1997calculation,
19
20
title={Calculation of Gauss-Kronrod quadrature rules},
@@ -25,16 +26,18 @@ which is the order of the integration rule.
25
26
year={1997}
26
27
}
27
28
"""
28
- struct QuadGKJL <: SciMLBase.AbstractIntegralAlgorithm
29
+ struct QuadGKJL{F} <: SciMLBase.AbstractIntegralAlgorithm where {F}
29
30
order:: Int
31
+ norm:: F
30
32
end
31
33
"""
32
- HCubatureJL(; initdiv=1)
34
+ HCubatureJL(; norm=norm, initdiv=1)
33
35
34
36
Multidimensional "h-adaptive" integration from HCubature.jl.
35
- This method also takes the optional argument `initdiv`,
36
- which is the intial number of segments
37
- each dimension of the integration domain is divided into.
37
+ This method also takes the optional arguments `initdiv` and `norm`.
38
+ Which are the intial number of segments
39
+ each dimension of the integration domain is divided into,
40
+ and the norm for calculating the error, respectively.
38
41
## References
39
42
@article{genz1980remarks,
40
43
title={Remarks on algorithm 006: An adaptive algorithm for numerical integration over an N-dimensional rectangular region},
@@ -47,18 +50,20 @@ each dimension of the integration domain is divided into.
47
50
publisher={Elsevier}
48
51
}
49
52
"""
50
- struct HCubatureJL <: SciMLBase.AbstractIntegralAlgorithm
53
+ struct HCubatureJL{F} <: SciMLBase.AbstractIntegralAlgorithm where {F}
51
54
initdiv:: Int
55
+ norm:: F
52
56
end
53
57
"""
54
- VEGAS(; nbins = 100, ncalls = 1000)
58
+ VEGAS(; nbins = 100, ncalls = 1000, debug=false )
55
59
56
60
Multidimensional adaptive Monte Carlo integration from MonteCarloIntegration.jl.
57
61
Importance sampling is used to reduce variance.
58
- This method also takes two optional arguments `nbins` and `ncalls`,
62
+ This method also takes three optional arguments `nbins`, `ncalls` and `debug`
59
63
which are the intial number of bins
60
- each dimension of the integration domain is divided into
61
- and the number of function calls per iteration of the algorithm.
64
+ each dimension of the integration domain is divided into,
65
+ the number of function calls per iteration of the algorithm,
66
+ and whether debug info should be printed, respectively.
62
67
## References
63
68
@article{lepage1978new,
64
69
title={A new algorithm for adaptive multidimensional integration},
@@ -74,10 +79,11 @@ and the number of function calls per iteration of the algorithm.
74
79
struct VEGAS <: SciMLBase.AbstractIntegralAlgorithm
75
80
nbins:: Int
76
81
ncalls:: Int
82
+ debug:: Bool
77
83
end
78
- QuadGKJL (; order = 7 ) = QuadGKJL (order)
79
- HCubatureJL (; initdiv = 1 ) = HCubatureJL (initdiv)
80
- VEGAS (; nbins = 100 , ncalls = 1000 ) = VEGAS (nbins, ncalls)
84
+ QuadGKJL (; order = 7 , norm = norm ) = QuadGKJL (order, norm )
85
+ HCubatureJL (; initdiv = 1 , norm = norm ) = HCubatureJL (initdiv, norm )
86
+ VEGAS (; nbins = 100 , ncalls = 1000 , debug = false ) = VEGAS (nbins, ncalls, debug )
81
87
82
88
abstract type QuadSensitivityAlg end
83
89
struct ReCallVJP{V}
@@ -276,8 +282,7 @@ __solvebp(args...; kwargs...) = __solvebp_call(args...; kwargs...)
276
282
277
283
function __solvebp_call (prob:: IntegralProblem , alg:: QuadGKJL , sensealg, lb, ub, p;
278
284
reltol = 1e-8 , abstol = 1e-8 ,
279
- maxiters = typemax (Int),
280
- kwargs... )
285
+ maxiters = typemax (Int))
281
286
if isinplace (prob) || lb isa AbstractArray || ub isa AbstractArray
282
287
error (" QuadGKJL only accepts one-dimensional quadrature problems." )
283
288
end
@@ -286,15 +291,13 @@ function __solvebp_call(prob::IntegralProblem, alg::QuadGKJL, sensealg, lb, ub,
286
291
p = p
287
292
f = x -> prob. f (x, p)
288
293
val, err = quadgk (f, lb, ub,
289
- rtol = reltol, atol = abstol, order = alg. order,
290
- kwargs... )
294
+ rtol = reltol, atol = abstol, order = alg. order, norm = alg. norm)
291
295
SciMLBase. build_solution (prob, QuadGKJL (), val, err, retcode = ReturnCode. Success)
292
296
end
293
297
294
298
function __solvebp_call (prob:: IntegralProblem , alg:: HCubatureJL , sensealg, lb, ub, p;
295
299
reltol = 1e-8 , abstol = 1e-8 ,
296
- maxiters = typemax (Int),
297
- kwargs... )
300
+ maxiters = typemax (Int))
298
301
p = p
299
302
300
303
if isinplace (prob)
@@ -308,19 +311,18 @@ function __solvebp_call(prob::IntegralProblem, alg::HCubatureJL, sensealg, lb, u
308
311
if lb isa Number
309
312
val, err = hquadrature (f, lb, ub;
310
313
rtol = reltol, atol = abstol,
311
- maxevals = maxiters, initdiv = alg. initdiv, kwargs ... )
314
+ maxevals = maxiters, norm = alg. norm, initdiv = alg . initdiv )
312
315
else
313
316
val, err = hcubature (f, lb, ub;
314
317
rtol = reltol, atol = abstol,
315
- maxevals = maxiters, initdiv = alg. initdiv, kwargs ... )
318
+ maxevals = maxiters, norm = alg. norm, initdiv = alg . initdiv )
316
319
end
317
320
SciMLBase. build_solution (prob, HCubatureJL (), val, err, retcode = ReturnCode. Success)
318
321
end
319
322
320
323
function __solvebp_call (prob:: IntegralProblem , alg:: VEGAS , sensealg, lb, ub, p;
321
324
reltol = 1e-8 , abstol = 1e-8 ,
322
- maxiters = typemax (Int),
323
- kwargs... )
325
+ maxiters = typemax (Int))
324
326
p = p
325
327
@assert prob. nout == 1
326
328
if prob. batch == 0
@@ -340,8 +342,8 @@ function __solvebp_call(prob::IntegralProblem, alg::VEGAS, sensealg, lb, ub, p;
340
342
end
341
343
ncalls = prob. batch == 0 ? alg. ncalls : prob. batch
342
344
val, err, chi = vegas (f, lb, ub, rtol = reltol, atol = abstol,
343
- maxiter = maxiters, nbins = alg. nbins,
344
- ncalls = ncalls, batch = prob. batch != 0 , kwargs ... )
345
+ maxiter = maxiters, nbins = alg. nbins, debug = alg . debug,
346
+ ncalls = ncalls, batch = prob. batch != 0 )
345
347
SciMLBase. build_solution (prob, alg, val, err, chi = chi, retcode = ReturnCode. Success)
346
348
end
347
349
0 commit comments