Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transformations for infinite and semi infinite integral. #33

Merged
merged 10 commits into from
Sep 2, 2020
Prev Previous commit
Next Next commit
Add testcase and fix bugs
  • Loading branch information
ashutosh-b-b committed Aug 14, 2020
commit d44eeda83ab7a1738945c1786ebc05b6e8d1e159
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "1.3.0"
[deps]
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
HCubature = "19dc6840-f33b-545b-b366-655c7e3ffd49"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
6 changes: 3 additions & 3 deletions src/Quadrature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function transform_inf(t , p , f)
end

function transform_semiinf(t , p , f , lb)
v(t) = lb .+ t ./ (1 .- t)
v(t) = lb .+ (t ./ (1 .- t))
if t isa Number
j = ForwardDiff.derivative(v, t)
else
Expand All @@ -80,7 +80,7 @@ function transformation_if_inf(prob)
prob = QuadratureProblem(h , lb ,ub, p = prob.p , nout = prob.nout , batch = prob.batch , prob.kwargs)
elseif (!(prob.lb isa Number) && !all(prob.lb .== -Inf) && all(prob.ub .== Inf)) || (prob.lb != -Inf && prob.ub == Inf)
if prob.lb isa Number
lb = -1.00
lb = 0.00
else
lb = zeros(size(prob.lb)[1])
end
Expand Down Expand Up @@ -194,7 +194,7 @@ function __init__()
reltol = 1e-8, abstol = 1e-8,
maxiters = typemax(Int),
kwargs...)
prob = transformation_if_inf(prob) #intercept for infinite transformation
prob = transformation_if_inf(prob) #intercept for infinite transformation
nout = prob.nout
if nout == 1
if prob.batch == 0
Expand Down
19 changes: 19 additions & 0 deletions test/inf_integral_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Quadrature , Distributions , Test

μ = [0.00 , 0.00]
Σ = [0.4 0.0 ; 0.00 0.4]
d = MvNormal(μ , Σ)
m(x , p) = pdf(d, x)
prob = QuadratureProblem(m, [-Inf , -Inf] , [Inf , Inf])
sol = solve(prob,HCubatureJL(),reltol=1e-3,abstol=1e-3)
@test (1.00 - sol.u)^2 < 1e-6

f(x , p) = pdf(Normal(0.00 , 1.00) , x)
prob = QuadratureProblem(f, -Inf , Inf)
sol = solve(prob,HCubatureJL(),reltol=1e-3,abstol=1e-3)
@test (1.00 - sol.u)^2 < 1e-6

f(x , p) = (1 / (x^2 + 1))
prob = QuadratureProblem(f, 0 , Inf)
sol = solve(prob,HCubatureJL(),reltol=1e-3,abstol=1e-3)
@test (pi/2 - sol.u)^2 < 1e-6
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ using Test

@time @safetestset "Interface Tests" begin include("interface_tests.jl") end
@time @safetestset "Derivative Tests" begin include("derivative_tests.jl") end
@time @safetestset "Infinite Integral Tests" begin include("inf_integral_tests.jl") end