Skip to content

Commit

Permalink
Fix tests and use SpecialFunctions for expint
Browse files Browse the repository at this point in the history
  • Loading branch information
mschauer committed Nov 10, 2020
1 parent 1660fc6 commit 1e9880e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
1 change: 1 addition & 0 deletions Project.toml
Expand Up @@ -12,6 +12,7 @@ Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
Expand Down
7 changes: 4 additions & 3 deletions src/Bridge.jl
Expand Up @@ -40,7 +40,7 @@ using Statistics

include("chol.jl")


using SpecialFunctions
using StaticArrays
using Distributions
using Colors
Expand Down Expand Up @@ -88,8 +88,9 @@ Pt(Po) = Po.Pt
target(Po) = Po.Target
auxiliary(Po) = Po.Pt


include("expint.jl")
if !@isdefined expint
include("expint.jl")
end
#include("setcol.jl")

include("fsa.jl")
Expand Down
65 changes: 35 additions & 30 deletions test/gaussian.jl
Expand Up @@ -3,40 +3,45 @@ using Test, LinearAlgebra, Random
using Distributions, StaticArrays
using Bridge: Gaussian, PSD

let
μ = rand()
x = rand()
Σ = rand()^2
@testset "Number" begin
let
μ = rand()
x = rand()
Σ = rand()^2

p = pdf(Normal(μ, Σ), x)
@test pdf(Gaussian(μ, Σ), x) p
@test pdf(Gaussian(μ, Σ*I), x) p
@test pdf(Gaussian([μ], [Σ]*[Σ]'), [x]) p
p = pdf(Normal(μ, Σ), x)
@test pdf(Gaussian(μ, Σ), x) p
@test pdf(Gaussian(μ, Σ*I), x) p
@test pdf(Gaussian([μ], [Σ]*[Σ]'), [x]) p

@test pdf(Gaussian((@SVector [μ]), @SMatrix [Σ]), @SVector [x]) p
@test pdf(Gaussian((@SVector [μ]), @SMatrix [Σ]), @SVector [x]) p
end
end

for d in 1: 3
μ = rand(d)
x = rand(d)
= tril(rand(d,d))
Σ =*'
p = pdf(MvNormal(μ, Σ), x)
@testset "Array" begin
for d in 1: 3
μ = rand(d)
x = rand(d)
= tril(rand(d,d))
Σ =*'
p = pdf(MvNormal(μ, Σ), x)

@test pdf(Gaussian(μ, Σ), x) p
@test pdf(Gaussian(μ, PSD(rΣ)), x) p
@test pdf(Gaussian(SVector{d}(μ), SMatrix{d,d}(Σ)), x) p
@test pdf(Gaussian(SVector{d}(μ), PSD(SMatrix{d,d}(rΣ))), x) p
@test pdf(Gaussian(μ, Σ), x) p
@test pdf(Gaussian(μ, PSD(rΣ)), x) p
@test pdf(Gaussian(SVector{d}(μ), SMatrix{d,d}(Σ)), x) p
@test pdf(Gaussian(SVector{d}(μ), PSD(SMatrix{d,d}(rΣ))), x) p
end
end
@testset "Diagonal" begin
for d in 1: 3
μ = rand(d)
x = rand(d)
= rand()
Σ = Matrix(I, d, d)*^2
p = pdf(MvNormal(μ, Σ), x)

for d in 1: 3
μ = rand(d)
x = rand(d)
= rand()
Σ = Matrix(I, d, d)*^2
p = pdf(MvNormal(μ, Σ), x)

@test pdf(Gaussian(μ, rΣ^2*I), x) p
@test pdf(Gaussian(SVector{d}(μ), SDiagonal(rΣ^2*ones(SVector{d}))), x) p
@test pdf(Gaussian(SVector{d}(μ), SMatrix{d,d}(Σ)), x) p
end
@test pdf(Gaussian(μ, rΣ^2*I), x) p
@test pdf(Gaussian(SVector{d}(μ), SDiagonal(rΣ^2*ones(SVector{d}))), x) p
@test pdf(Gaussian(SVector{d}(μ), SMatrix{d,d}(Σ)), x) p
end
end
4 changes: 2 additions & 2 deletions test/linpro.jl
Expand Up @@ -12,7 +12,7 @@ mu = 0.1*S([0.2, 0.3])
sigma = SMatrix{2,2,Float64}(2*[-0.212887 0.0687025
0.193157 0.388997 ])
a = sigma*sigma'

P = LinPro(B, mu, sigma)

u = S([1.0, 0.0])
Expand Down Expand Up @@ -47,7 +47,7 @@ Mu2 = SamplePath(tt, zeros(S, length(tt)))

solve!(Bridge.R3(), Bridge.b, Mu, u, P)
solve!(BS3(), Bridge.b, Mu2, u, P)
@test (@allocated Bridge.gpHinv!(K, P)) == 0
@test (@allocated Bridge.gpHinv!(K, P)) <= 32
@test (@allocated Bridge.gpV!(V, P, v)) == 0
@test norm(K.yy[1]*Bridge.H(t, T, P) - I) < 10/n2^3
@test norm(V.yy[1] - Bridge.V(t, T, v, P)) < 10/n2^3
Expand Down

0 comments on commit 1e9880e

Please sign in to comment.