The interface of sample
is different according to the specific model used. This makes it extremely cumbersome to abstract and modularize the model.
For example, this is how you sample from a model that contains both discrete and continuous variables:
trace = pm.sample(
nuts={'target_accept': 0.95, 'max_treedepth': 25}
)
And this is how to do it when the model only has continuous variables:
trace = pm.sample(
target_accept=0.95, max_treedepth=25
)
And what is worse is that these two are not compatible. Using the first version with a model that does not have discrete variables gives the error:
TypeError: function() got an unexpected keyword argument 'nuts'
While using the second version with a model containing discrete variables gives the error:
ValueError: Unused step method arguments: {'target_accept', 'max_treedepth'}
Is it possible to find a way that works in both cases? Possibly the simplest solution is to check if 'nuts'
is in the kwargs before calling init_nuts
(here). I am open to work on a pull request for this.
Use case: I am comparing two models that are very similar except that one contains a “sparsity prior” through a Bernoulli distribution. Since the models are otherwise very similar, I abstracted away this sparsity part and the rest of the model. The inconsistent interface of sample
, however, makes this quite ugly, as I am essentially forced to try one method and use the other if I an exception is thrown.