@@ -4,6 +4,7 @@ using Base.Iterators: take
4
4
using Random
5
5
using LinearAlgebra
6
6
using KeywordCalls
7
+ using Statistics
7
8
8
9
function draw2 (μ)
9
10
x = rand (μ)
17
18
const sqrt2π = sqrt (2 π)
18
19
19
20
@testset " Parameterized Measures" begin
20
- @measure Normal (μ,σ)
21
- @kwstruct Normal ()
22
-
23
- MeasureBase. basemeasure (:: Normal )= (1 / sqrt2π) * Lebesgue (ℝ)
24
-
25
- MeasureBase. logdensity (d:: Normal{(:μ,:σ)} , x) = - log (d. σ) - (x - d. μ)^ 2 / (2 * d. σ^ 2 )
26
- MeasureBase. logdensity (d:: Normal{()} , x) = - 0.5 * x^ 2
21
+ @measure Normal (μ,σ)
22
+ @kwstruct Normal (μ)
23
+ @kwstruct Normal ()
24
+
25
+ MeasureBase. basemeasure (:: Normal )= (1 / sqrt2π) * Lebesgue (ℝ)
26
+ MeasureBase. logdensity (d:: Normal{(:μ,:σ)} , x) = - log (d. σ) - (x - d. μ)^ 2 / (2 * d. σ^ 2 )
27
+ MeasureBase. logdensity (d:: Normal{(:μ,)} , x) = - (x - d. μ)^ 2 / 2
28
+ MeasureBase. logdensity (d:: Normal{()} , x) = - x^ 2 / 2
29
+
30
+ Base. rand (rng:: Random.AbstractRNG , T:: Type , d:: Normal{(:μ,:σ)} ) = d. μ + d. σ * randn (rng, T)
31
+ Base. rand (rng:: Random.AbstractRNG , T:: Type , d:: Normal{(:μ,)} ) = d. μ + randn (rng, T)
32
+ Base. rand (rng:: Random.AbstractRNG , T:: Type , d:: Normal{()} ) = randn (rng, T)
27
33
28
- @test Normal (2 ,4 ) == Normal (μ= 2 , σ= 4 )
29
- @test Normal (σ= 4 , μ= 2 ) == Normal (μ= 2 , σ= 4 )
30
- @test logdensity (Normal (), 3 ) == logdensity (Normal (0 ,1 ), 3 )
34
+ @test Normal (2 ,4 ) == Normal (μ= 2 , σ= 4 )
35
+ @test Normal (σ= 4 , μ= 2 ) == Normal (μ= 2 , σ= 4 )
36
+ @test logdensity (Normal (), 3 ) == logdensity (Normal (0 ,1 ), 3 )
31
37
end
32
38
33
39
@testset " Kernel" begin
0 commit comments