Skip to content

Commit

Permalink
Merge pull request #252 from ReactiveBayes/23-inference-using-a-dataa…
Browse files Browse the repository at this point in the history
…rray

Update graph_construction_tests.jl
  • Loading branch information
wouterwln authored Sep 30, 2024
2 parents a165516 + 6a2e4f4 commit 4807717
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/graph_construction_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1872,4 +1872,31 @@ end
node = context[inner_model, 1][NormalMeanVariance, 2]
@test hasextra(model[node], :factorization_constraint_indices)
@test getextra(model[node], :factorization_constraint_indices) == ([1], [2], [3])
end

@testitem "Inference with DataArray" begin
using Distributions
using GraphPPL
import GraphPPL: @model, create_model, datalabel, NodeCreationOptions, neighbors

@model function data_array_model(y)
σ ~ Gamma(1.0, 1.0)
for i in 1:10
y[i + 10] ~ Normal(y[i], σ)
end
end

model = create_model(data_array_model()) do model, ctx
y = datalabel(model, ctx, NodeCreationOptions(kind = :data), :y, rand(20))
return (y = y,)
end

@test length(collect(filter(as_node(Normal), model))) == 10
@test length(collect(filter(as_variable(:y), model))) == 20

y = model[][:y]

for i in 1:10
@test (y[i + 10] stack(neighbors.(Ref(model), collect(neighbors(model, y[i])))))
end
end

0 comments on commit 4807717

Please sign in to comment.