|
176 | 176 | t0 = 0.0
|
177 | 177 | θ0 = randn(d)
|
178 | 178 | x0 = randn(d)
|
179 |
| - M = UpperTriangular(I + 0.4randn(d,d)) |
| 179 | + M = UpperTriangular(I + 0.4randn(d,d)') |
180 | 180 | c = 20.0
|
181 | 181 | B = BouncyParticle(missing, missing, # ignored
|
182 | 182 | 1.0, # momentum refreshment rate
|
|
206 | 206 | @test mean(abs.(cov(xs) - inv(Matrix(Γ)))) < 3/sqrt(length(ts))
|
207 | 207 | end
|
208 | 208 |
|
| 209 | +@testset "Bouncy Particle Sampler (arbitrary mass matrix 2)" begin |
| 210 | + Random.seed!(2) |
| 211 | + t0 = 0.0 |
| 212 | + θ0 = randn(d) |
| 213 | + x0 = randn(d) |
| 214 | + M = LowerTriangular(I + 0.4randn(d,d)) |
| 215 | + c = 20.0 |
| 216 | + B = BouncyParticle(missing, missing, # ignored |
| 217 | + 1.0, # momentum refreshment rate |
| 218 | + 0.9, # momentum correlation / only gradually change momentum in refreshment/momentum update |
| 219 | + missing, # metric |
| 220 | + M |
| 221 | + ) |
| 222 | + |
| 223 | + ∇ϕ!(y, t, x, args...) = mul!(y, Γ, x) |
| 224 | + dϕ(t, x, v, args...) = dot(v, Γ, x), dot(v, Γ, v) |
| 225 | + n = 800 |
| 226 | + trace, _, acc, more = @time pdmp( |
| 227 | + dϕ, # return first two directional derivatives of negative target log-likelihood in direction v |
| 228 | + ∇ϕ!, # return gradient of negative target log-likelihood |
| 229 | + t0, x0, θ0, # initial state and duration |
| 230 | + n, # number of samples |
| 231 | + ZigZagBoomerang.LocalBound(c), # use Hessian information |
| 232 | + B; # sampler |
| 233 | + adapt=false, # adapt bound c |
| 234 | + progress=true, # show progress bar |
| 235 | + ) |
| 236 | + @show more |
| 237 | + @show acc[1]/acc[2] |
| 238 | + ts, xs = sep(trace) |
| 239 | + @show length(ts) |
| 240 | + @test mean(abs.(mean(xs))) < 3/sqrt(length(ts)) |
| 241 | + @test mean(abs.(cov(xs) - inv(Matrix(Γ)))) < 3/sqrt(length(ts)) |
| 242 | +end |
| 243 | + |
209 | 244 | @testset "Bouncy Particle Sampler (adapted mass matrix)" begin
|
210 | 245 | Random.seed!(2)
|
211 | 246 | t0 = 0.0
|
|
0 commit comments