@@ -29,7 +29,8 @@ using Test
29
29
@test Set (keys (VarInfo (outer ()))) == Set ([@varname (a. x), @varname (a. y)])
30
30
31
31
# With conditioning/fixing
32
- @testset " $model " for model in [with_inner_op, with_outer_op]
32
+ models = [(" inner" , with_inner_op), (" outer" , with_outer_op)]
33
+ @testset " $name " for (name, model) in models
33
34
# Test that the value was correctly set
34
35
@test model ()[1 ] == x_val
35
36
# Test that the logp was correctly set
@@ -44,7 +45,7 @@ using Test
44
45
@model function inner ()
45
46
x ~ Normal ()
46
47
y ~ Normal ()
47
- return x
48
+ return (x, y)
48
49
end
49
50
@model function outer ()
50
51
return a ~ to_submodel (inner (), false )
@@ -60,7 +61,8 @@ using Test
60
61
@test Set (keys (VarInfo (outer ()))) == Set ([@varname (x), @varname (y)])
61
62
62
63
# With conditioning/fixing
63
- @testset " $model " for model in [with_inner_op, with_outer_op]
64
+ models = [(" inner" , with_inner_op), (" outer" , with_outer_op)]
65
+ @testset " $name " for (name, model) in models
64
66
# Test that the value was correctly set
65
67
@test model ()[1 ] == x_val
66
68
# Test that the logp was correctly set
@@ -75,7 +77,7 @@ using Test
75
77
@model function inner ()
76
78
x ~ Normal ()
77
79
y ~ Normal ()
78
- return x
80
+ return (x, y)
79
81
end
80
82
@model function outer ()
81
83
return a ~ to_submodel (prefix (inner (), :b ), false )
@@ -91,7 +93,8 @@ using Test
91
93
@test Set (keys (VarInfo (outer ()))) == Set ([@varname (b. x), @varname (b. y)])
92
94
93
95
# With conditioning/fixing
94
- @testset " $model " for model in [with_inner_op, with_outer_op]
96
+ models = [(" inner" , with_inner_op), (" outer" , with_outer_op)]
97
+ @testset " $name " for (name, model) in models
95
98
# Test that the value was correctly set
96
99
@test model ()[1 ] == x_val
97
100
# Test that the logp was correctly set
@@ -115,18 +118,20 @@ using Test
115
118
end
116
119
117
120
# No conditioning
118
- @test Set (keys (VarInfo (h ()))) == Set ([@varname (a. b. x), @varname (a. b. y)])
121
+ vi = VarInfo (h ())
122
+ @test Set (keys (vi)) == Set ([@varname (a. b. x), @varname (a. b. y)])
123
+ @test getlogp (vi) ==
124
+ logpdf (Normal (), vi[@varname (a. b. x)]) +
125
+ logpdf (Normal (), vi[@varname (a. b. y)])
119
126
120
127
# Conditioning/fixing at the top level
121
128
op_h = op (h (), (@varname (a. b. x) => x_val))
122
- @test Set (keys (VarInfo (op_h))) == Set ([@varname (a. b. y)])
123
129
124
130
# Conditioning/fixing at the second level
125
131
op_g = op (g (), (@varname (b. x) => x_val))
126
132
@model function h2 ()
127
133
return a ~ to_submodel (op_g)
128
134
end
129
- @test Set (keys (VarInfo (h2 ()))) == Set ([@varname (a. b. y)])
130
135
131
136
# Conditioning/fixing at the very bottom
132
137
op_f = op (f (), (@varname (x) => x_val))
@@ -136,7 +141,13 @@ using Test
136
141
@model function h3 ()
137
142
return a ~ to_submodel (g2 ())
138
143
end
139
- @test Set (keys (VarInfo (h3 ()))) == Set ([@varname (a. b. y)])
144
+
145
+ models = [(" top" , op_h), (" middle" , h2 ()), (" bottom" , h3 ())]
146
+ @testset " $name " for (name, model) in models
147
+ vi = VarInfo (model)
148
+ @test Set (keys (vi)) == Set ([@varname (a. b. y)])
149
+ @test getlogp (vi) == x_logp + logpdf (Normal (), vi[@varname (a. b. y)])
150
+ end
140
151
end
141
152
end
142
153
0 commit comments