@@ -43,7 +43,7 @@ reset_model(f) = deepcopy(f)
43
43
delete_retained! (f) = nothing
44
44
45
45
# Task copying version of fork for Trace.
46
- function fork (trace:: Trace , isref:: Bool = false )
46
+ function fork (trace:: Trace , isref:: Bool = false )
47
47
newtrace = copy (trace)
48
48
isref && delete_retained! (newtrace. f)
49
49
58
58
function forkr (trace:: Trace )
59
59
newf = reset_model (trace. f)
60
60
61
- ctask = let f= trace. ctask. task. code
61
+ ctask = let f = trace. ctask. task. code
62
62
Libtask. CTask () do
63
63
res = f ()(trace. rng)
64
64
Libtask. produce (nothing )
115
115
function Base. push! (pc:: ParticleContainer , p:: Particle )
116
116
push! (pc. vals, p)
117
117
push! (pc. logWs, 0.0 )
118
- pc
118
+ return pc
119
119
end
120
120
121
121
# clones a theta-particle
@@ -126,7 +126,7 @@ function Base.copy(pc::ParticleContainer)
126
126
# copy weights
127
127
logWs = copy (pc. logWs)
128
128
129
- ParticleContainer (vals, logWs)
129
+ return ParticleContainer (vals, logWs)
130
130
end
131
131
132
132
"""
@@ -193,9 +193,9 @@ of the particle `weights`. For Particle Gibbs sampling, one can provide a refere
193
193
function resample_propagate! (
194
194
rng:: Random.AbstractRNG ,
195
195
pc:: ParticleContainer ,
196
- randcat = resample_systematic,
197
- ref:: Union{Particle, Nothing} = nothing ;
198
- weights = getweights (pc)
196
+ randcat= resample_systematic,
197
+ ref:: Union{Particle,Nothing} = nothing ;
198
+ weights= getweights (pc),
199
199
)
200
200
# check that weights are not NaN
201
201
@assert ! any (isnan, weights)
@@ -242,24 +242,24 @@ function resample_propagate!(
242
242
pc. vals = children
243
243
reset_logweights! (pc)
244
244
245
- pc
245
+ return pc
246
246
end
247
247
248
248
function resample_propagate! (
249
249
rng:: Random.AbstractRNG ,
250
250
pc:: ParticleContainer ,
251
251
resampler:: ResampleWithESSThreshold ,
252
- ref:: Union{Particle,Nothing} = nothing ;
253
- weights = getweights (pc)
252
+ ref:: Union{Particle,Nothing} = nothing ;
253
+ weights= getweights (pc),
254
254
)
255
255
# Compute the effective sample size ``1 / ∑ wᵢ²`` with normalized weights ``wᵢ``
256
256
ess = inv (sum (abs2, weights))
257
257
258
258
if ess ≤ resampler. threshold * length (pc)
259
- resample_propagate! (rng, pc, resampler. resampler, ref; weights = weights)
259
+ resample_propagate! (rng, pc, resampler. resampler, ref; weights= weights)
260
260
end
261
261
262
- pc
262
+ return pc
263
263
end
264
264
265
265
"""
@@ -300,9 +300,13 @@ function reweight!(pc::ParticleContainer)
300
300
301
301
# The posterior for models with random number of observations is not well-defined.
302
302
if numdone != 0
303
- error (" mis-aligned execution traces: # particles = " , n,
304
- " # completed trajectories = " , numdone,
305
- " . Please make sure the number of observations is NOT random." )
303
+ error (
304
+ " mis-aligned execution traces: # particles = " ,
305
+ n,
306
+ " # completed trajectories = " ,
307
+ numdone,
308
+ " . Please make sure the number of observations is NOT random." ,
309
+ )
306
310
end
307
311
308
312
return false
0 commit comments