Hi there,
I came across an issue with the following function in smc/kernels.py. I’m trying to figure out a minimal example but what I can say for now is that I have an index out of bounds for idx for
weight_accu += weights[idx]
It happens only for some random seed values. I can always hard code a boundary test for idx but I’m wondering whether that error implies a model that is problematic in any way?
Cheers,
Vian
def systematic_resampling(weights, rng):“”"Systematic resampling.
Parameters
----------
weights :
The weights should be probabilities and the total sum should be 1.
Returns
-------
new_indices: array
A vector of indices in the interval 0, ..., len(normalized_weights)
"""
lnw = len(weights)
arange = np.arange(lnw)
uniform = (rng.random(1) + arange) / lnw
idx = 0
weight_accu = weights[0]
new_indices = np.empty(lnw, dtype=int)
for i in arange:
while uniform[i] > weight_accu:
idx += 1
weight_accu += weights[idx]
new_indices[i] = idx
return new_indices