Skip to content
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

SMC change initialization #2755

Merged
merged 8 commits into from Dec 18, 2017
Merged

Conversation

aloctavodia
Copy link
Member

Unfortunately #2749 is not a general solution of #2742. The problem arise when asking for random samples for distributions that have other distributions as parents, for example the z variable in @junpenglao example (#2742 (comment)). I am under the impression this problem have arisen before.

This PR takes a different approach, instead of getting samples from the prior by using random methods of each distribution, it just sample from the prior using metropolis. It seems to work OK, so far but I will like to run more tests to ensure this is a good approach.

@junpenglao
Copy link
Member

hmm, I am not sure this will actually work, as using metropolis is not the same as direct sampling from the prior

@aloctavodia
Copy link
Member Author

Hi @junpenglao I also had may concerns at first but then I realize that to get proper samples using SMC, you only need to start from any easy to sample distribution that covers the entire solution space and then slowly move from this distribution to the posterior distribution. Starting from the prior is just one convenient choice. In other domains (like statistical mechanics) where priors are not explicit, methods similar to SMC start from a high temperature that is equivalent to start from a flatter distribution and then slowly cool down the system.

The computation of the samples seems to be more or less insensitive to the details of the starting distribution, I use for example over-dispersed points. Contrary to this the computation of the marginal likelihood seems to be much more sensitive to the starting choice, one of the assumptions in the computation of the marginal likelihood using SMC is that the normalizing constant of the samples from the first stage is 1. Also the marginal likelihood should be sensitive to how fast you move from the initial distribution to the posterior distribution... I have been trying to improve the computation of the marginal likelihood, but is still very off for some models.

@junpenglao
Copy link
Member

Thanks for the explanation!
also cc @hvasbath

@aloctavodia aloctavodia changed the title [WIP] Initialize SMC using Metropolis [WIP] SMC change initialization and tunning Dec 14, 2017
@aloctavodia aloctavodia changed the title [WIP] SMC change initialization and tunning [WIP] SMC change initialization and tuning Dec 14, 2017
@aloctavodia
Copy link
Member Author

And we are back to initialize directly from the prior!!!

I also changed the way SMC auto-tune Metropolis proposal distribution. I basically follow the recommendations in Transitional Markov Chain Monte Carlo Method for Bayesian Model Updating, Model Class Selection, and Model Averaging. Briefly, they recommend to multiply the weighted covariance matrix (calc_covariance() inside SMC) by a scaling factor of 0.04. @hvasbath maybe can provide reasons against this change or correct me if I am doing something wrong about the tuning...

@hvasbath
Copy link
Contributor

hvasbath commented Dec 15, 2017

Hey guys! Thanks a lot for this explanation @aloctavodia ! I was totally unaware of these things as I am no statistician. I prefered to have the tuning adaptively based on the acceptance rate as it was already in the metropolis. Removing the adaptive scaling maybe better for some models but I found it was much better performing for my type of problems. Having the algorithm adaptively how it was, is from the Minson 2013 paper mentioned in the doc string. As I mentioned this implementation is not exactly the same as in the TMCMC paper. Just parts of it. So I would vote agains removing the adaptive scaling. If you dont want any adaptation simply set tune=False and set scaling=0.4 when you initialise the sampler .... But again if this interferes with calculating the evidence then we should discuss it further of course. SO for my problems the adaptive stepping is really important.

Ah cool I just saw that you worked on getting it working for transformed variables as well! Awesome! Good job!

@aloctavodia
Copy link
Member Author

@hvasbath Thanks for the feedback I will go back with the tunning changes. It is very interesting that your models works better with the metropolis auto-tunning and worst with the weighed covariance scaling, probably this, together with the results I am getting for the marginal likelihood are indications that there is room for improvement in the computations of the weights, I will work on this. Could you send me (maybe by e-mail) one of your models, I would like to have some real-world models beside my own to test SMC.

@aloctavodia aloctavodia changed the title [WIP] SMC change initialization and tuning SMC change initialization Dec 15, 2017
@hvasbath
Copy link
Contributor

All my real world models are in my "beat" repository. In src/models.py, but I fear the coding there maybe a little unusual for you. Also you would need some data which I would have to send you. As it is a real world application you have quite some other dependencies. In the website there is a description how to install beat and its dependencies. If you want to try it. I fear I have no simpler example- sorry for that!

@aloctavodia
Copy link
Member Author

Thanks @hvasbath. I will take a look at beat.

@aloctavodia aloctavodia merged commit da3ef19 into pymc-devs:master Dec 18, 2017
@aloctavodia aloctavodia deleted the smc_transformed2 branch December 18, 2017 12:41
@hvasbath
Copy link
Contributor

If I am not mistaken @junpenglao also had some real world applications which seemed much simpler to be implemented. Maybe you could do testing on one of his models as well in case getting beat to run takes too much time.

@junpenglao
Copy link
Member

I have codes to compare mixed effect model (with simulation and real data) in https://github.com/junpenglao/GLMM-in-Python

jordan-melendez pushed a commit to jordan-melendez/pymc3 that referenced this pull request Feb 6, 2018
* initialize smc using sample() insted of random numbers

* use metropolis

* init from random and modify scaling

* fix indentation

* update trace reference values

* revert tuning changes

* revert tuning changes

* update release notes
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.

None yet

3 participants