Skip to content

Commit

Permalink
tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
jaksle committed Feb 7, 2024
1 parent b30a950 commit 9974b8c
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions test/interp.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
using Test
using KernelDensity

X = randn(100)
Y = randn(100)

k = kde(X)
@test pdf(k, k.x) k.density

k = kde((X,Y))
@test pdf(k, k.x, k.y) k.density

# Try to evaluate the KDE outside the interpolation domain
# The KDE is allowed to be zero, but it should not be greater than the exact solution
k = kde([0.0], bandwidth=1.0)
@test pdf.(k, k.x) k.density
@test pdf(k, -10.0) pdf(Normal(), -10.0)
@test pdf(k, +10.0) pdf(Normal(), +10.0)

k = kde(([0.0],[0.0]), bandwidth=(1.0, 1.0))
@test pdf(k, k.x, k.y) k.density
@test pdf(k, -10.0, 0.0) pdf(MvNormal(2, 1.0), [-10.0, 0.0])
@test pdf(k, +10.0, 0.0) pdf(MvNormal(2, 1.0), [+10.0, 0.0])
@test pdf(k, 0.0, -10.0) pdf(MvNormal(2, 1.0), [0.0, -10.0])
@test pdf(k, 0.0, +10.0) pdf(MvNormal(2, 1.0), [0.0, +10.0])
@testset "interpolation computation" begin
X = randn(100)
Y = randn(100)

k = kde(X)
@test pdf.(k, k.x) k.density

k = kde((X,Y))
@test pdf(k, k.x, k.y) k.density

# Try to evaluate the KDE outside the interpolation domain
# The KDE is allowed to be zero, but it should not be greater than the exact solution
k = kde([0.0], bandwidth=1.0)
@test pdf.(k, k.x) k.density
@test pdf(k, -10.0) pdf(Normal(), -10.0)
@test pdf(k, +10.0) pdf(Normal(), +10.0)

k = kde(([0.0],[0.0]), bandwidth=(1.0, 1.0))
@test pdf(k, k.x, k.y) k.density
@test pdf(k, -10.0, 0.0) pdf(MvNormal(2, 1.0), [-10.0, 0.0])
@test pdf(k, +10.0, 0.0) pdf(MvNormal(2, 1.0), [+10.0, 0.0])
@test pdf(k, 0.0, -10.0) pdf(MvNormal(2, 1.0), [0.0, -10.0])
@test pdf(k, 0.0, +10.0) pdf(MvNormal(2, 1.0), [0.0, +10.0])
end

@testset "pdf method interface" begin
k = kde([-1., 1.])
Expand All @@ -38,4 +40,4 @@ k = kde(([0.0],[0.0]), bandwidth=(1.0, 1.0))
@test pdf(k2d, [0.5, 0.1]) pdf(k2d, [0.5; 0.1]) pdf(k2d, 0.5, 0.1) pdf(ik2d, 0.5, 0.1)
@test pdf(k2d, [0.5 1.; 0.1 1.]) [pdf(ik2d, 0.5, 0.1), pdf(ik2d, 1., 1.)]
@test pdf(k2d, [0.5; 1. ;;; 0.1; 1.]) [pdf(ik2d, 0.5, 1.) pdf(ik2d, 0.1, 1.)]
end
end

0 comments on commit 9974b8c

Please sign in to comment.