Skip to content

Commit ce7c8b1

Browse files
mosesmakolamosesmakolagithub-actions[bot]mhauru
authored
issue 737 and issue 789 (#977)
* removed all upper bounds of inf when truncated method is called * removed all upper bounds of inf for truncated method call * Removed tests from abstract.jl * Update test/compiler.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update test/varinfo.jl Co-authored-by: Markus Hauru <[email protected]> --------- Co-authored-by: mosesmakola <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Markus Hauru <[email protected]>
1 parent b4ee208 commit ce7c8b1

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

src/test_utils/models.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ A model with variables `m` and `x` with `x` having support depending on `m`.
1414
"""
1515
@model function demo_dynamic_constraint()
1616
m ~ Normal()
17-
x ~ truncated(Normal(), m, Inf)
17+
x ~ truncated(Normal(); lower=m)
1818

1919
return (m=m, x=x)
2020
end
2121
function logprior_true(model::Model{typeof(demo_dynamic_constraint)}, m, x)
22-
return logpdf(Normal(), m) + logpdf(truncated(Normal(), m, Inf), x)
22+
return logpdf(Normal(), m) + logpdf(truncated(Normal(); lower=m), x)
2323
end
2424
function loglikelihood_true(model::Model{typeof(demo_dynamic_constraint)}, m, x)
2525
return zero(float(eltype(m)))
@@ -30,7 +30,7 @@ end
3030
function logprior_true_with_logabsdet_jacobian(
3131
model::Model{typeof(demo_dynamic_constraint)}, m, x
3232
)
33-
b_x = Bijectors.bijector(truncated(Normal(), m, Inf))
33+
b_x = Bijectors.bijector(truncated(Normal(); lower=m))
3434
x_unconstrained, Δlogp = Bijectors.with_logabsdet_jacobian(b_x, x)
3535
return (m=m, x=x_unconstrained), logprior_true(model, m, x) - Δlogp
3636
end

test/compiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ module Issue537 end
501501
@model function demo(y)
502502
α ~ Uniform()
503503
μ ~ Normal()
504-
σ ~ truncated(Normal(), 0, Inf)
504+
σ ~ truncated(Normal(); lower=0)
505505
num_steps = length(y[1])
506506
num_obs = length(y)
507507
@inbounds for i in 1:num_obs

test/varinfo.jl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,8 @@ end
6767

6868
@testset "Base" begin
6969
# Test Base functions:
70-
# string, Symbol, ==, hash, in, keys, haskey, isempty, push!!, empty!!,
70+
# in, keys, haskey, isempty, push!!, empty!!,
7171
# getindex, setindex!, getproperty, setproperty!
72-
csym = gensym()
73-
vn1 = @varname x[1][2]
74-
@test string(vn1) == "x[1][2]"
75-
@test Symbol(vn1) == Symbol("x[1][2]")
76-
77-
vn2 = @varname x[1][2]
78-
@test vn2 == vn1
79-
@test hash(vn2) == hash(vn1)
8072

8173
function test_base(vi_original)
8274
vi = deepcopy(vi_original)
@@ -179,14 +171,14 @@ end
179171
@testset "setval! & setval_and_resample!" begin
180172
@model function testmodel(x)
181173
n = length(x)
182-
s ~ truncated(Normal(), 0, Inf)
174+
s ~ truncated(Normal(); lower=0)
183175
m ~ MvNormal(zeros(n), I)
184176
return x ~ MvNormal(m, s^2 * I)
185177
end
186178

187179
@model function testmodel_univariate(x, ::Type{TV}=Vector{Float64}) where {TV}
188180
n = length(x)
189-
s ~ truncated(Normal(), 0, Inf)
181+
s ~ truncated(Normal(); lower=0)
190182

191183
m = TV(undef, n)
192184
for i in eachindex(m)
@@ -444,10 +436,10 @@ end
444436
end
445437

446438
@testset "istrans" begin
447-
@model demo_constrained() = x ~ truncated(Normal(), 0, Inf)
439+
@model demo_constrained() = x ~ truncated(Normal(); lower=0)
448440
model = demo_constrained()
449441
vn = @varname(x)
450-
dist = truncated(Normal(), 0, Inf)
442+
dist = truncated(Normal(); lower=0)
451443

452444
### `VarInfo`
453445
# Need to run once since we can't specify that we want to _sample_

0 commit comments

Comments
 (0)