Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

These tests should be in DynamicPPL or removed #2475

Open
penelopeysm opened this issue Jan 21, 2025 · 0 comments
Open

These tests should be in DynamicPPL or removed #2475

penelopeysm opened this issue Jan 21, 2025 · 0 comments

Comments

@penelopeysm
Copy link
Member

@testset "Contexts" begin
# Test LikelihoodContext
@model function testmodel1(x)
a ~ Beta()
lp1 = getlogp(__varinfo__)
x[1] ~ Bernoulli(a)
return global loglike = getlogp(__varinfo__) - lp1
end
model = testmodel1([1.0])
varinfo = Turing.VarInfo(model)
model(varinfo, Turing.SampleFromPrior(), Turing.LikelihoodContext())
@test getlogp(varinfo) == loglike
# Test MiniBatchContext
@model function testmodel2(x)
a ~ Beta()
return x[1] ~ Bernoulli(a)
end
model = testmodel2([1.0])
varinfo1 = Turing.VarInfo(model)
varinfo2 = deepcopy(varinfo1)
model(varinfo1, Turing.SampleFromPrior(), Turing.LikelihoodContext())
model(
varinfo2,
Turing.SampleFromPrior(),
Turing.MiniBatchContext(Turing.LikelihoodContext(), 10),
)
@test isapprox(getlogp(varinfo2) / getlogp(varinfo1), 10)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant