36
36
37
37
def sample_smc (
38
38
draws = 2000 ,
39
- kernel = "metropolis" ,
39
+ kernel = None ,
40
40
n_steps = 25 ,
41
41
* ,
42
42
start = None ,
43
43
tune_steps = True ,
44
44
p_acc_rate = 0.85 ,
45
45
threshold = 0.5 ,
46
- save_sim_data = False ,
47
- save_log_pseudolikelihood = True ,
46
+ save_sim_data = None ,
47
+ save_log_pseudolikelihood = None ,
48
48
model = None ,
49
49
random_seed = - 1 ,
50
50
parallel = None ,
@@ -63,9 +63,6 @@ def sample_smc(
63
63
draws: int
64
64
The number of samples to draw from the posterior (i.e. last stage). And also the number of
65
65
independent chains. Defaults to 2000.
66
- kernel: str
67
- Kernel method for the SMC sampler. Available option are ``metropolis`` (default) and `ABC`.
68
- Use `ABC` for likelihood free inference together with a ``pm.Simulator``.
69
66
n_steps: int
70
67
The number of steps of each Markov Chain. If ``tune_steps == True`` ``n_steps`` will be used
71
68
for the first stage and for the others it will be determined automatically based on the
@@ -83,13 +80,6 @@ def sample_smc(
83
80
Determines the change of beta from stage to stage, i.e.indirectly the number of stages,
84
81
the higher the value of `threshold` the higher the number of stages. Defaults to 0.5.
85
82
It should be between 0 and 1.
86
- save_sim_data : bool
87
- Whether or not to save the simulated data. This parameter only works with the ABC kernel.
88
- The stored data corresponds to a samples from the posterior predictive distribution.
89
- save_log_pseudolikelihood : bool
90
- Whether or not to save the log pseudolikelihood values. This parameter only works with the
91
- ABC kernel. The stored data can be used to compute LOO or WAIC values. Computing LOO/WAIC
92
- values from log pseudolikelihood values is experimental.
93
83
model: Model (optional if in ``with`` context)).
94
84
random_seed: int
95
85
random seed
@@ -157,6 +147,30 @@ def sample_smc(
157
147
%282007%29133:7%28816%29>`__
158
148
"""
159
149
150
+ if isinstance (kernel , str ) and kernel .lower () == "abc" :
151
+ warnings .warn (
152
+ f'The kernel "{ kernel } " in sample_smc has been deprecated. '
153
+ f"It is no longer needed to specify it." ,
154
+ DeprecationWarning ,
155
+ stacklevel = 2 ,
156
+ )
157
+
158
+ if save_sim_data is not None :
159
+ warnings .warn (
160
+ "save_sim_data has been deprecated. Use pm.sample_posterior_predictive "
161
+ "to obtain the same type of samples." ,
162
+ DeprecationWarning ,
163
+ stacklevel = 2 ,
164
+ )
165
+
166
+ if save_log_pseudolikelihood is not None :
167
+ warnings .warn (
168
+ "save_log_pseudolikelihood has been deprecated. This information is "
169
+ "now saved as log_likelihood in models with Simulator distributions." ,
170
+ DeprecationWarning ,
171
+ stacklevel = 2 ,
172
+ )
173
+
160
174
if parallel is not None :
161
175
warnings .warn (
162
176
"The argument parallel is deprecated, use the argument cores instead." ,
@@ -199,22 +213,13 @@ def sample_smc(
199
213
if not isinstance (random_seed , Iterable ):
200
214
raise TypeError ("Invalid value for `random_seed`. Must be tuple, list or int" )
201
215
202
- if kernel .lower () == "abc" :
203
- if len (model .observed_RVs ) != 1 :
204
- warnings .warn ("SMC-ABC only works properly with models with one observed variable" )
205
- if model .potentials :
206
- _log .info ("Potentials will be added to the prior term" )
207
-
208
216
params = (
209
217
draws ,
210
- kernel ,
211
218
n_steps ,
212
219
start ,
213
220
tune_steps ,
214
221
p_acc_rate ,
215
222
threshold ,
216
- save_sim_data ,
217
- save_log_pseudolikelihood ,
218
223
model ,
219
224
)
220
225
@@ -245,9 +250,7 @@ def sample_smc(
245
250
246
251
(
247
252
traces ,
248
- sim_data ,
249
253
log_marginal_likelihoods ,
250
- log_pseudolikelihood ,
251
254
betas ,
252
255
accept_ratios ,
253
256
nsteps ,
@@ -263,7 +266,6 @@ def sample_smc(
263
266
trace .report ._n_draws = draws
264
267
trace .report ._n_tune = _n_tune
265
268
trace .report .log_marginal_likelihood = log_marginal_likelihoods
266
- trace .report .log_pseudolikelihood = log_pseudolikelihood
267
269
trace .report .betas = betas
268
270
trace .report .accept_ratios = accept_ratios
269
271
trace .report .nsteps = nsteps
@@ -313,23 +315,16 @@ def sample_smc(
313
315
trace .report ._run_convergence_checks (idata , model )
314
316
trace .report ._log_summary ()
315
317
316
- posterior = idata if return_inferencedata else trace
317
- if save_sim_data :
318
- return posterior , {modelcontext (model ).observed_RVs [0 ].name : np .array (sim_data )}
319
- else :
320
- return posterior
318
+ return idata if return_inferencedata else trace
321
319
322
320
323
321
def _sample_smc_int (
324
322
draws ,
325
- kernel ,
326
323
n_steps ,
327
324
start ,
328
325
tune_steps ,
329
326
p_acc_rate ,
330
327
threshold ,
331
- save_sim_data ,
332
- save_log_pseudolikelihood ,
333
328
model ,
334
329
random_seed ,
335
330
chain ,
@@ -339,43 +334,26 @@ def _sample_smc_int(
339
334
in_out_pickled = type (model ) == bytes
340
335
if in_out_pickled :
341
336
# function was called in multiprocessing context, deserialize first
342
- (
343
- draws ,
344
- kernel ,
345
- n_steps ,
346
- start ,
347
- tune_steps ,
348
- p_acc_rate ,
349
- threshold ,
350
- save_sim_data ,
351
- save_log_pseudolikelihood ,
352
- model ,
353
- ) = map (
337
+ (draws , n_steps , start , tune_steps , p_acc_rate , threshold , model ,) = map (
354
338
cloudpickle .loads ,
355
339
(
356
340
draws ,
357
- kernel ,
358
341
n_steps ,
359
342
start ,
360
343
tune_steps ,
361
344
p_acc_rate ,
362
345
threshold ,
363
- save_sim_data ,
364
- save_log_pseudolikelihood ,
365
346
model ,
366
347
),
367
348
)
368
349
369
350
smc = SMC (
370
351
draws = draws ,
371
- kernel = kernel ,
372
352
n_steps = n_steps ,
373
353
start = start ,
374
354
tune_steps = tune_steps ,
375
355
p_acc_rate = p_acc_rate ,
376
356
threshold = threshold ,
377
- save_sim_data = save_sim_data ,
378
- save_log_pseudolikelihood = save_log_pseudolikelihood ,
379
357
model = model ,
380
358
random_seed = random_seed ,
381
359
chain = chain ,
@@ -411,9 +389,7 @@ def _sample_smc_int(
411
389
412
390
results = (
413
391
smc .posterior_to_trace (),
414
- smc .sim_data ,
415
392
smc .log_marginal_likelihood ,
416
- smc .log_pseudolikelihood ,
417
393
betas ,
418
394
accept_ratios ,
419
395
nsteps ,
0 commit comments