Closed ColtAllen closed 8 months ago
CC @michaelraczycki
Choosing other step methods wasn't something I was aware of on the earlier stages, and as I see now, the way step functions are defined in pymc is requiring them to be used with the context on stack, which prevents it from being passed by itself. I'll create a PR where I change sample_model() to include:
with self.model: sampler_args = {**self.sampler_config, **kwargs} if 'step' in sampler_args: sampler_args['step'] = sampler_args['step']() idata = pm.sample(**sampler_args)
also, to properly use the ModelBuilder fit, the sampler config should be passed as a parameter, or additional kwargs can be passed to fit() itself, but it shouldn't be called by adding one more context on the stack, as the fit in basic.py creates it under the hood.
@ricardoV94 is it something that should be always allowed for all models (therefore is worth being included on the model builder level), or will be used either only in the CLV context or even only Pareto?
(This is @ColtAllen, responding from my work account).
I can't speak for the other models, but before @ricardoV94 made some pytensor
enhancements, ParetoNBDModel
could only be used with gradient-free methods like SliceSampler
. I want to see if the new enhancements enable NUTS to converge more quickly than SliceSampler
, but am currently blocked from doing so.
The ability to use external samplers across all models would be a great addition I think, as they tend to be much faster. However, JAX samplers cannot currently be used with the ParetoNBDModel
because the hyp2f1
Op in the Likelihood isn't supported. I've also installed nutpie
, but haven't tested it yet because rust requires a bit more initial setup for a Macbook.
Just to save you trouble @ColtAllen nutpie won't work either because we didn't implement those Ops on the Numba backend
@lucianopaz showed me how to get the slice sampler to work by replacing pnbd.fit(**sampler_config)
with pm.sample(**sampler_config)
in the above example.
External samplers can be used via a similar approach that can be shared in a tutorial notebook, and is probably the way to go unless there is a lot of user interest in the fit
method supporting external samplers (which could be a rather heavy lift).
Closing this because specifying another sampler is easy with the following convention:
with clv_model.model:
clv_model.idata = pm.sample(step=pm.SAMPLER())
I do think it's worth adding an option for a gradient-free sampler to ParetoNBDModel
though, as well as a nutpie
example in the docs. I'll get issues created for both.
When attempting to use a sampler other than the default (NUTS), a
ValueError
is raised because the model variables are being assigned twice. The following example is for theParetoNBDModel
, but it's the same deal withBetaGeoModel
:It's also worth noting that external samplers like
numpyro
cannot be used at all the way the baseCLVModel
is currently written.