@@ -198,13 +198,14 @@ end
198
198
199
199
Create new unique keys for the particles in the ParticleContainer
200
200
"""
201
- function update_keys! (pc:: ParticleContainer )
201
+ function update_keys! (pc:: ParticleContainer , ref :: Union{Particle,Nothing} = nothing )
202
202
# Update keys to new particle ids
203
- for i in 1 : length (pc)
203
+ nparticles = length (pc)
204
+ n = ref === nothing ? nparticles : nparticles - 1
205
+ for i in 1 : n
204
206
pi = pc. vals[i]
205
207
k = split (pi . rng, 1 )
206
- seed! (pi . rng, k[1 ])
207
- set_counter! (pi . rng. rng, pi . rng. count)
208
+ update_rng! (pi . rng, k[1 ])
208
209
end
209
210
end
210
211
@@ -253,13 +254,13 @@ function resample_propagate!(
253
254
p = isref ? fork (pi , isref) : pi
254
255
255
256
seeds = split (p. rng, ni)
256
- seed ! (p. rng, seeds[1 ])
257
+ ! isref && update_rng ! (p. rng, seeds[1 ])
257
258
258
259
children[j += 1 ] = p
259
260
# fork additional children
260
261
for k in 2 : ni
261
262
part = fork (p, isref)
262
- seed ! (part. rng, seeds[k])
263
+ update_rng ! (part. rng, seeds[k])
263
264
children[j += 1 ] = part
264
265
end
265
266
end
@@ -288,10 +289,11 @@ function resample_propagate!(
288
289
# Compute the effective sample size ``1 / ∑ wᵢ²`` with normalized weights ``wᵢ``
289
290
ess = inv (sum (abs2, weights))
290
291
291
- if ess ≤ resampler. threshold * length (pc)
292
+ # if ess ≤ resampler.threshold * length(pc)
293
+ if true
292
294
resample_propagate! (rng, pc, resampler. resampler, ref; weights= weights)
293
295
else
294
- update_keys! (pc)
296
+ update_keys! (pc, ref )
295
297
end
296
298
297
299
return pc
0 commit comments