Skip to content

Commit

Permalink
new test
Browse files Browse the repository at this point in the history
  • Loading branch information
bvdmitri committed Mar 15, 2024
1 parent 580dbc6 commit 248e24d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/graph_construction_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,27 @@ end
@test length(collect(filter(as_variable(:b), model))) === 0
@test length(collect(filter(as_variable(:x), model))) === 10
end

@testitem "Using distribution objects as priors" begin
using Distributions
import GraphPPL: create_model, getorcreate!, NodeCreationOptions, LazyIndex

include("testutils.jl")

@model function coin_model_priors(y, prior)
θ ~ prior
for i in eachindex(y)
y[i] ~ Bernoulli(θ)
end
end

ydata = rand(10)
prior = Beta(1, 1)

model = create_model(coin_model_priors(prior = prior)) do model, context
return (; y = getorcreate!(model, context, NodeCreationOptions(kind = :data), :y, LazyIndex(ydata)))
end

@test length(collect(filter(as_node(Bernoulli), model))) === 10
@test length(collect(filter(as_node(prior), model))) === 1
end

0 comments on commit 248e24d

Please sign in to comment.