Skip to content

Conversation

aseyboldt
Copy link
Member

@aseyboldt aseyboldt commented Jun 17, 2017

This implements adaptation for diagonal mass matrices during tuning.

sample gets a new option for init, namely advi+adapt_diag, which first runs advi to get an initial estimate for the mass matrix and then further adapts it using the covariance of the tuning samples.

The approach for computing adapting the mass matrix differs a bit from that in stan. Stan keeps the mass matrix constant within a window and then uses the variances in the latest window as mass matrix for the next window.

In this PR I use an online algorithm for computing the variance and change it continuously. It starts with the estimate from advi with a weight of 30 and updates the variance for each new sample. After 200 samples it starts computing new variances from ground up, but still uses the first variance for sampling. after 400 samples it switches to the second set of variances. This should prevent bad initialization from advi to ruin the whole trace. (see quadpotential.QuadpotentialDiagAdapt.adapt)

Still needs a lot of unit tests/doc/tinkering and we should compare it to the stan approach carefully.
It would probably also be an option to change weights over time and therefore achieve a similar effect as using windows.

@aseyboldt aseyboldt added the WIP label Jun 17, 2017
@aseyboldt aseyboldt added this to the 3.2 milestone Jun 17, 2017
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@junpenglao
Copy link
Member

junpenglao commented Jul 14, 2017

Should we actually use this for tuning (unrelated to init) in NUTS?

@aseyboldt aseyboldt force-pushed the nuts-adapt branch 5 times, most recently from dffba11 to fec319e Compare July 16, 2017 13:25
@aseyboldt
Copy link
Member Author

I think this is ready to be merged now.
I disabled a couple of tests in test_quadpotential because I need to change those for #2345 anyway, and I'd rather not do it twice.

return {k: np.asarray(v) for k, v in ppc.items()}


def init_nuts(init='ADVI', njobs=1, n_init=500000, model=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldnt init='auto' as default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, fixed now.
It was the default in pm.sample.

@twiecki twiecki merged commit 8fb942c into pymc-devs:master Jul 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants