Skip to content

fix #2108 #2110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2017
Merged

fix #2108 #2110

merged 3 commits into from
May 3, 2017

Conversation

junpenglao
Copy link
Member

No description provided.

@junpenglao
Copy link
Member Author

fix #2108 @twiecki @ferrine

@twiecki twiecki requested a review from ferrine May 2, 2017 19:27
@ferrine
Copy link
Member

ferrine commented May 2, 2017

What is wrong with order? Is it the best place for fix?

@junpenglao
Copy link
Member Author

junpenglao commented May 2, 2017

@ferrine basically, the problem is that the somehow the bijection.map in approximation class is different than the model.bijection.map. So in the
https://github.com/pymc-devs/pymc3/blob/master/pymc3/sampling.py#L588-L589, the cov has a different order compare to start.
As a result, the pm.NUTS get the wrong scaling.

In the old advi init, it does cov = np.power(model.dict_to_array(v_params.stds), 2) to make sure the cov has the right order.
https://github.com/pymc-devs/pymc3/blob/bb25d7bb43aa0684fdbd7628546be044c873b27b/pymc3/sampling.py#L474

@twiecki
Copy link
Member

twiecki commented May 2, 2017 via email

@junpenglao
Copy link
Member Author

@twiecki I agree - something must happen during pm.fit, which somehow operate on model.
However, it might be useful to have this fix in place as a fail-safe

@@ -573,7 +573,15 @@ def init_nuts(init='ADVI', njobs=1, n_init=500000, model=None,
progressbar=progressbar
) # type: pm.MeanField
start = approx.sample(draws=njobs)
cov = approx.cov.eval()
Copy link
Member

@ferrine ferrine May 2, 2017

Choose a reason for hiding this comment

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

that's more pretty

stds = mf.gbij.rmap((tt.diag(mf.cov).eval()))
cov = model.dict_to_array(stds)

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks! I will go with this.
If I understand correctly the posterior cov of advi is a diagonal matrix right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

@twiecki
Copy link
Member

twiecki commented May 3, 2017

>           stds = approx.gbij.rmap((tt.diag(approx.cov).eval()))
E           NameError: global name 'tt' is not defined

@junpenglao
Copy link
Member Author

Oops, thanks @twiecki

@twiecki twiecki merged commit 42e9bcf into pymc-devs:master May 3, 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