|
276 | 276 | # See https://github.com/TuringLang/DynamicPPL.jl/issues/504 |
277 | 277 | @testset "Dimentionality checks" begin |
278 | 278 | @model function demo2d() |
279 | | - x ~ Dirichlet(2, 1.0) |
| 279 | + return x ~ Dirichlet(2, 1.0) |
280 | 280 | end |
281 | 281 | model = demo2d() |
282 | | - vi = VarInfo(model) # make VarInfo -> sample from prior and compute logdensity |
| 282 | + vi = VarInfo(model) # make VarInfo -> sample from prior and compute logdensity |
283 | 283 | getlogp(vi) ≈ 0.0 # zero because Dirichlet(1) == Uniform over Simplex |
284 | | - spl = SampleFromPrior() # create dummy sampler for linking |
| 284 | + spl = SampleFromPrior() # create dummy sampler for linking |
285 | 285 | DynamicPPL.link!!(vi, spl, model) # transform to unconstrained space |
286 | 286 | !(0.0 ≈ getlogp(last(DynamicPPL.evaluate!!(model, vi)))) # non-zero now due to log(abs(determinant(jacobian))) |
287 | 287 | x = vi[spl] # extract unconstrained values |
288 | | - newx = deepcopy(x) # simulate making a change to x |
| 288 | + newx = deepcopy(x) # simulate making a change to x |
289 | 289 | vinew = deepcopy(vi) |
290 | | - vinew[spl] = newx; |
| 290 | + vinew[spl] = newx |
291 | 291 | @test vinew[spl] == newx |
292 | 292 |
|
293 | 293 | @model function demo3d() |
294 | | - x ~ Dirichlet(3, 1.0) # increase K to 3 |
| 294 | + return x ~ Dirichlet(3, 1.0) # increase K to 3 |
295 | 295 | end |
296 | 296 | model = demo3d() |
297 | | - vi = VarInfo(model) # make VarInfo -> sample from prior and compute logdensity |
| 297 | + vi = VarInfo(model) # make VarInfo -> sample from prior and compute logdensity |
298 | 298 | getlogp(vi) ≈ 0.0 # zero because Dirichlet(1) == Uniform over Simplex |
299 | | - spl = SampleFromPrior() # create dummy sampler for linking |
| 299 | + spl = SampleFromPrior() # create dummy sampler for linking |
300 | 300 | DynamicPPL.link!!(vi, spl, model) # transform to unconstrained space |
301 | 301 | !(0.0 ≈ getlogp(last(DynamicPPL.evaluate!!(model, vi)))) # non-zero now due to log(abs(determinant(jacobian))) |
302 | 302 | x = vi[spl] # extract unconstrained values |
303 | | - newx = deepcopy(x) # simulate making a change to x |
| 303 | + newx = deepcopy(x) # simulate making a change to x |
304 | 304 | vinew = deepcopy(vi) |
305 | | - vinew[spl] = newx; |
| 305 | + vinew[spl] = newx |
306 | 306 |
|
307 | 307 | @test vinew[spl] == newx |
308 | 308 | end |
|
0 commit comments