11using Test
22using KernelDensity
33
4- X = randn (100 )
5- Y = randn (100 )
6-
7- k = kde (X)
8- @test pdf (k, k. x) ≈ k. density
9-
10- k = kde ((X,Y))
11- @test pdf (k, k. x, k. y) ≈ k. density
12-
13- # Try to evaluate the KDE outside the interpolation domain
14- # The KDE is allowed to be zero, but it should not be greater than the exact solution
15- k = kde ([0.0 ], bandwidth= 1.0 )
16- @test pdf .(k, k. x) ≈ k. density
17- @test pdf (k, - 10.0 ) ≤ pdf (Normal (), - 10.0 )
18- @test pdf (k, + 10.0 ) ≤ pdf (Normal (), + 10.0 )
19-
20- k = kde (([0.0 ],[0.0 ]), bandwidth= (1.0 , 1.0 ))
21- @test pdf (k, k. x, k. y) ≈ k. density
22- @test pdf (k, - 10.0 , 0.0 ) ≤ pdf (MvNormal (2 , 1.0 ), [- 10.0 , 0.0 ])
23- @test pdf (k, + 10.0 , 0.0 ) ≤ pdf (MvNormal (2 , 1.0 ), [+ 10.0 , 0.0 ])
24- @test pdf (k, 0.0 , - 10.0 ) ≤ pdf (MvNormal (2 , 1.0 ), [0.0 , - 10.0 ])
25- @test pdf (k, 0.0 , + 10.0 ) ≤ pdf (MvNormal (2 , 1.0 ), [0.0 , + 10.0 ])
4+ @testset " interpolation computation" begin
5+ X = randn (100 )
6+ Y = randn (100 )
7+
8+ k = kde (X)
9+ @test pdf .(k, k. x) ≈ k. density
10+
11+ k = kde ((X,Y))
12+ @test pdf (k, k. x, k. y) ≈ k. density
13+
14+ # Try to evaluate the KDE outside the interpolation domain
15+ # The KDE is allowed to be zero, but it should not be greater than the exact solution
16+ k = kde ([0.0 ], bandwidth= 1.0 )
17+ @test pdf .(k, k. x) ≈ k. density
18+ @test pdf (k, - 10.0 ) ≤ pdf (Normal (), - 10.0 )
19+ @test pdf (k, + 10.0 ) ≤ pdf (Normal (), + 10.0 )
20+
21+ k = kde (([0.0 ],[0.0 ]), bandwidth= (1.0 , 1.0 ))
22+ @test pdf (k, k. x, k. y) ≈ k. density
23+ @test pdf (k, - 10.0 , 0.0 ) ≤ pdf (MvNormal (2 , 1.0 ), [- 10.0 , 0.0 ])
24+ @test pdf (k, + 10.0 , 0.0 ) ≤ pdf (MvNormal (2 , 1.0 ), [+ 10.0 , 0.0 ])
25+ @test pdf (k, 0.0 , - 10.0 ) ≤ pdf (MvNormal (2 , 1.0 ), [0.0 , - 10.0 ])
26+ @test pdf (k, 0.0 , + 10.0 ) ≤ pdf (MvNormal (2 , 1.0 ), [0.0 , + 10.0 ])
27+ end
2628
2729@testset " pdf method interface" begin
2830 k = kde ([- 1. , 1. ])
@@ -38,4 +40,4 @@ k = kde(([0.0],[0.0]), bandwidth=(1.0, 1.0))
3840 @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 )
3941 @test pdf (k2d, [0.5 1. ; 0.1 1. ]) ≈ [pdf (ik2d, 0.5 , 0.1 ), pdf (ik2d, 1. , 1. )]
4042 @test pdf (k2d, [0.5 ; 1. ;;; 0.1 ; 1. ]) ≈ [pdf (ik2d, 0.5 , 1. ) pdf (ik2d, 0.1 , 1. )]
41- end
43+ end
0 commit comments