File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -193,10 +193,13 @@ def initialize_population(self) -> dict[str, np.ndarray]:
193
193
)
194
194
195
195
model = self .model
196
+
196
197
prior_expression = make_initial_point_expression (
197
198
free_rvs = model .free_RVs ,
198
199
rvs_to_transforms = model .rvs_to_transforms ,
199
- initval_strategies = {},
200
+ initval_strategies = {
201
+ ** model .rvs_to_initial_values ,
202
+ },
200
203
default_strategy = "prior" ,
201
204
return_transformed = True ,
202
205
)
Original file line number Diff line number Diff line change 25
25
import pymc as pm
26
26
27
27
from pymc .backends .base import MultiTrace
28
+ from pymc .distributions .transforms import Ordered
28
29
from pymc .pytensorf import floatX
29
30
from pymc .smc .kernels import IMH , systematic_resampling
30
31
from tests .helpers import assert_random_state_equal
@@ -269,6 +270,30 @@ def test_deprecated_abc_args(self):
269
270
):
270
271
pm .sample_smc (draws = 10 , chains = 1 , save_log_pseudolikelihood = True )
271
272
273
+ def test_ordered (self ):
274
+ """
275
+ Test that initial population respects custom initval, especially when applied
276
+ to the Ordered transformation. Regression test for #7438.
277
+ """
278
+ with pm .Model () as m :
279
+ pm .Normal (
280
+ "a" ,
281
+ mu = 0.0 ,
282
+ sigma = 1.0 ,
283
+ size = (2 ,),
284
+ transform = Ordered (),
285
+ initval = [- 1.0 , 1.0 ],
286
+ )
287
+
288
+ smc = IMH (model = m )
289
+ out = smc .initialize_population ()
290
+
291
+ # initial point should not include NaNs
292
+ assert not np .any (np .isnan (out ["a_ordered__" ]))
293
+
294
+ # initial point should match for all particles
295
+ assert np .all (out ["a_ordered__" ][0 ] == out ["a_ordered__" ])
296
+
272
297
273
298
class TestMHKernel :
274
299
def test_normal_model (self ):
You can’t perform that action at this time.
0 commit comments