How to change adapt_delta on pystan 3.9.1?

Hi everyone.
Basically, I am new to Pystan, I used to work with Rstan. In R stan this was easy:

...,control = list(adapt_delta = 0.999, stepsize = 0.001, max_treedepth = 12)

It was also easy on the previous versions of Pystan, however, I can’t find any note of how to change adapt_delta on the API guide of Pystan 3.9.1. https://pystan.readthedocs.io/en/latest/reference.html

Any help would be greatly appreciated.

if you’re new to PyStan, may I recommend using CmdStanPy instead?
It supports everything in the latest Stan release, including cool stuff like Pathfinder.

https://mc-stan.org/cmdstanpy/

In CmdStanPy, you instantiate a model, then invoke the sample method, which does indeed allow for adapt_delta: API Reference — CmdStanPy 1.2.2 documentation

examples here: MCMC Sampling — CmdStanPy 1.2.2 documentation
and here: Using Variational Estimates to Initialize the NUTS-HMC Sampler — CmdStanPy 1.2.2 documentation

1 Like

Thank you so much for all the examples and links in such a short notice, yes, after so much searching, switching to CmdStanPy seems to be the easier option.

1 Like

Hi guys, I am already deep inside in a project using pystan, I could not change to cmdstanpy. Is there a way to ser adapt_delta in the pystan command? I’ve tried

model = stan.build(my_mixture, data=my_data, delta = 0.95, random_seed=1);

and variations, but it doesn’t work.

Thank you, Sequi

Hi Guys again (2h later…haha):

I have found the answer to my question, the secret is to set the adapt_delta (and any other control such as max_depth, etc), in the model.sample() directive, and not in the stan.build().

This worked out perfect:

fit = model.sample(num_chains=4, num_samples=1000, delta=0.95)

I’ve got this solution after reading this other question:

2 Likes