14
14
15
15
import logging
16
16
17
- from copy import copy
17
+ from copy import copy , deepcopy
18
18
19
19
import aesara
20
20
import numpy as np
@@ -39,12 +39,12 @@ class PGBART(ArrayStepShared):
39
39
vars: list
40
40
List of value variables for sampler
41
41
num_particles : int
42
- Number of particles for the conditional SMC sampler . Defaults to 40
42
+ Number of particles. Defaults to 40
43
43
max_stages : int
44
- Maximum number of iterations of the conditional SMC sampler . Defaults to 100.
44
+ Maximum number of iterations. Defaults to 100.
45
45
batch : int or tuple
46
46
Number of trees fitted per step. Defaults to "auto", which is the 10% of the `m` trees
47
- during tuning and after tuning. If a tuple is passed the first element is the batch size
47
+ during and after tuning. If a tuple is passed the first element is the batch size
48
48
during tuning and the second the batch size after tuning.
49
49
model: PyMC Model
50
50
Optional model for sampling step. Defaults to None (taken from context).
@@ -81,10 +81,10 @@ def __init__(self, vars=None, num_particles=40, max_stages=100, batch="auto", mo
81
81
# if data is binary
82
82
Y_unique = np .unique (self .Y )
83
83
if Y_unique .size == 2 and np .all (Y_unique == [0 , 1 ]):
84
- self .mu_std = 6 / (self .k * self .m ** 0.5 )
84
+ self .mu_std = 3 / (self .k * self .m ** 0.5 )
85
85
# maybe we need to check for count data
86
86
else :
87
- self .mu_std = ( 2 * self .Y .std () ) / (self .k * self .m ** 0.5 )
87
+ self .mu_std = self .Y .std () / (self .k * self .m ** 0.5 )
88
88
89
89
self .num_observations = self .X .shape [0 ]
90
90
self .num_variates = self .X .shape [1 ]
@@ -229,8 +229,7 @@ def init_particles(self, tree_id: int) -> np.ndarray:
229
229
Initialize particles
230
230
"""
231
231
p = self .all_particles [tree_id ]
232
- particles = [p ]
233
- particles .append (copy (p ))
232
+ particles = [p , p .copy ()]
234
233
235
234
for _ in self .indices :
236
235
particles .append (ParticleTree (self .a_tree ))
@@ -275,6 +274,9 @@ def __init__(self, tree):
275
274
self .old_likelihood_logp = 0
276
275
self .used_variates = []
277
276
277
+ def copy (self ):
278
+ return deepcopy (self )
279
+
278
280
def sample_tree (
279
281
self ,
280
282
ssv ,
0 commit comments