@@ -6,6 +6,7 @@ using LinearAlgebra
6
6
using KeywordCalls
7
7
using Statistics
8
8
9
+
9
10
function draw2 (μ)
10
11
x = rand (μ)
11
12
y = rand (μ)
@@ -26,19 +27,40 @@ const sqrt2π = sqrt(2π)
26
27
MeasureBase. logdensity (d:: Normal{(:μ,:σ)} , x) = - log (d. σ) - (x - d. μ)^ 2 / (2 * d. σ^ 2 )
27
28
MeasureBase. logdensity (d:: Normal{(:μ,)} , x) = - (x - d. μ)^ 2 / 2
28
29
MeasureBase. logdensity (d:: Normal{()} , x) = - x^ 2 / 2
29
-
30
+
30
31
Base. rand (rng:: Random.AbstractRNG , T:: Type , d:: Normal{(:μ,:σ)} ) = d. μ + d. σ * randn (rng, T)
31
32
Base. rand (rng:: Random.AbstractRNG , T:: Type , d:: Normal{(:μ,)} ) = d. μ + randn (rng, T)
32
33
Base. rand (rng:: Random.AbstractRNG , T:: Type , d:: Normal{()} ) = randn (rng, T)
33
34
35
+ MeasureBase. representative (d:: Normal{(:μ,:σ)} ) = σ > 0.0 ? Lebesgue (ℝ) : Dirac (d. μ)
36
+ MeasureBase. representative (d:: Normal{(:μ,)} ) = Lebesgue (ℝ)
37
+
38
+ # Leave this undefined to test fallback inference algorithm
39
+ # MeasureBase.representative(::Normal) = Lebesgue(ℝ)
40
+
34
41
@test Normal (2 ,4 ) == Normal (μ= 2 , σ= 4 )
35
42
@test Normal (σ= 4 , μ= 2 ) == Normal (μ= 2 , σ= 4 )
36
43
@test logdensity (Normal (), 3 ) == logdensity (Normal (0 ,1 ), 3 )
44
+
45
+ x = randn ()
46
+ @test_broken logdensity (Normal (3 ,2 ), Lebesgue (ℝ), x) ≈ logdensity (Normal (3 ,2 ), Normal (), x ) + logdensity (Normal (), Lebesgue (ℝ),x)
47
+ @test_broken 𝒹 (Normal (3 ,2 ), Normal ())(x) ≈ logdensity (Normal (3 ,2 ), Normal (), x)
48
+ end
49
+
50
+ @testset " Density" begin
51
+ x = randn ()
52
+ f (x) = - x^ 2
53
+ μ = Normal ()
54
+ ν = Lebesgue (ℝ)
55
+ @test_broken 𝒹 (∫ (f, μ), μ)(x) ≈ f (x)
56
+ @test_broken logdensity (∫ (𝒹 (μ, ν), ν), x) ≈ logdensity (μ, x)
37
57
end
38
58
59
+
39
60
@testset " Kernel" begin
40
- κ = MeasureBase . kernel (identity, MeasureBase . Dirac)
61
+ κ = kernel (identity, Dirac)
41
62
@test rand (κ (1.1 )) == 1.1
63
+ @test kernelize (Normal (0 ,1 )) == (Kernel {Normal, UnionAll} (NamedTuple{(:μ , :σ ), T} where T<: Tuple ), (0 , 1 ))
42
64
end
43
65
44
66
@testset " SpikeMixture" begin
0 commit comments