|
130 | 130 |
|
131 | 131 | # Use finite differencing to compute reverse-mode sensitivities. |
132 | 132 | x̄s_fdm = FDM.j′vp(central_fdm(5, 1), f, ȳ, x...) |
133 | | - |
| 133 | + |
134 | 134 | if AD == "All" || AD == "Zygote" |
135 | 135 | # Use Zygote to compute reverse-mode sensitivities. |
136 | 136 | y_zygote, back_zygote = Zygote.pullback(f, x...) |
|
180 | 180 |
|
181 | 181 | # Check that Tracker forwards-pass produces the correct answer. |
182 | 182 | @test isapprox(y, Tracker.data(y_tracker), atol=atol, rtol=rtol) |
183 | | - |
| 183 | + |
184 | 184 | # Check that Tracker reverse-mode sensitivities are correct. |
185 | 185 | @test all(zip(x̄s_tracker, x̄s_fdm)) do (x̄_tracker, x̄_fdm) |
186 | 186 | isapprox(Tracker.data(x̄_tracker), x̄_fdm; atol=atol, rtol=rtol) |
187 | 187 | end |
188 | 188 | end |
189 | 189 | end |
190 | | - _to_cov(B) = B + B' + 2 * size(B, 1) * Matrix(I, size(B)...) |
| 190 | + _to_cov(B) = B + B' + 2 * size(B, 1) * Matrix(I, size(B)...) |
191 | 191 |
|
192 | 192 | @testset "logsumexp" begin |
193 | 193 | x, y = rand(3), rand() |
|
257 | 257 | @testset "Params" begin |
258 | 258 | m = rand(10) |
259 | 259 | sigmas = randexp(10) |
260 | | - |
| 260 | + |
261 | 261 | d = TuringDiagMvNormal(m, sigmas) |
262 | 262 | @test params(d) == (m, sigmas) |
263 | 263 |
|
|
335 | 335 | @test s2 isa Matrix{Float64} |
336 | 336 | @test size(s2) == (dim, n) |
337 | 337 | end |
| 338 | + |
| 339 | + # https://github.com/TuringLang/DistributionsAD.jl/issues/158 |
| 340 | + let |
| 341 | + d = TuringDirichlet(rand(2)) |
| 342 | + z = rand(d) |
| 343 | + logpdf_z = logpdf(d, z) |
| 344 | + pdf_z = pdf(d, z) |
| 345 | + |
| 346 | + for x in ([0.5, 0.8], [-0.5, 1.5]) |
| 347 | + @test logpdf(d, x) == -Inf |
| 348 | + @test iszero(pdf(d, x)) |
| 349 | + |
| 350 | + xmat = hcat(x, x) |
| 351 | + @test all(==(-Inf), logpdf(d, xmat)) |
| 352 | + @test all(iszero, pdf(d, xmat)) |
| 353 | + |
| 354 | + xzmat = hcat(x, z) |
| 355 | + @test logpdf(d, xzmat) == [-Inf, logpdf_z] |
| 356 | + @test pdf(d, xzmat) == [0, pdf_z] |
| 357 | + end |
| 358 | + end |
338 | 359 | end |
339 | 360 | end |
0 commit comments