@@ -113,7 +113,8 @@ def __init__(
113
113
shape = self .shape ,
114
114
)
115
115
self .normal = NormalSampler (mu_std , self .shape )
116
- self .uniform = UniformSampler (0.33 , 0.75 , self .shape )
116
+ self .uniform = UniformSampler (0 , 1 )
117
+ self .uniform_kf = UniformSampler (0.33 , 0.75 , self .shape )
117
118
self .prior_prob_leaf_node = compute_prior_probability (self .bart .alpha )
118
119
self .ssv = SampleSplittingVariable (self .alpha_vec )
119
120
@@ -253,7 +254,6 @@ def get_particle_tree(self, particles, normalized_weights):
253
254
discrete_uniform_sampler (self .num_particles )
254
255
]
255
256
new_particle = particles [new_index - 2 ]
256
- new_particle .log_weight = new_particle .old_likelihood_logp - self .log_num_particles
257
257
return new_particle , new_particle .tree
258
258
259
259
def systematic (self , normalized_weights ):
@@ -265,7 +265,7 @@ def systematic(self, normalized_weights):
265
265
Note: adapted from https://github.com/nchopin/particles
266
266
"""
267
267
lnw = len (normalized_weights )
268
- single_uniform = (self .uniform .random ()[ 0 ] + np .arange (lnw )) / lnw
268
+ single_uniform = (self .uniform .random () + np .arange (lnw )) / lnw
269
269
return inverse_cdf (single_uniform , normalized_weights ) + 2
270
270
271
271
def init_particles (self , tree_id : int ) -> np .ndarray :
@@ -285,7 +285,7 @@ def init_particles(self, tree_id: int) -> np.ndarray:
285
285
286
286
for _ in self .indices :
287
287
particles .append (
288
- ParticleTree (self .a_tree , self .uniform .random () if self .tune else p0 .kfactor )
288
+ ParticleTree (self .a_tree , self .uniform_kf .random () if self .tune else p0 .kfactor )
289
289
)
290
290
291
291
return np .array (particles )
@@ -575,7 +575,7 @@ def update(self):
575
575
class UniformSampler :
576
576
"""Cache samples from a uniform distribution."""
577
577
578
- def __init__ (self , lower_bound , upper_bound , shape ):
578
+ def __init__ (self , lower_bound , upper_bound , shape = None ):
579
579
self .size = 1000
580
580
self .upper_bound = upper_bound
581
581
self .lower_bound = lower_bound
@@ -585,15 +585,21 @@ def __init__(self, lower_bound, upper_bound, shape):
585
585
def random (self ):
586
586
if self .idx == self .size :
587
587
self .update ()
588
- pop = self .cache [:, self .idx ]
588
+ if self .shape is None :
589
+ pop = self .cache [self .idx ]
590
+ else :
591
+ pop = self .cache [:, self .idx ]
589
592
self .idx += 1
590
593
return pop
591
594
592
595
def update (self ):
593
596
self .idx = 0
594
- self .cache = np .random .uniform (
595
- self .lower_bound , self .upper_bound , size = (self .shape , self .size )
596
- )
597
+ if self .shape is None :
598
+ self .cache = np .random .uniform (self .lower_bound , self .upper_bound , size = self .size )
599
+ else :
600
+ self .cache = np .random .uniform (
601
+ self .lower_bound , self .upper_bound , size = (self .shape , self .size )
602
+ )
597
603
598
604
599
605
@njit
@@ -629,7 +635,7 @@ def inverse_cdf(single_uniform, normalized_weights):
629
635
630
636
631
637
def logp (point , out_vars , vars , shared ): # pylint: disable=redefined-builtin
632
- """Compile Aesara function of the model and the input and output variables.
638
+ """Compile PyTensor function of the model and the input and output variables.
633
639
634
640
Parameters
635
641
----------
0 commit comments