-
Notifications
You must be signed in to change notification settings - Fork 0
Reversible Jump #51
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
Draft
alecksphillips
wants to merge
90
commits into
main
Choose a base branch
from
refactor/bridge-stan-w-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Reversible Jump #51
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In order to avoid problems with cmdstan/redding-stan
Added painfully basic RJMCMC sampler (just doing random-walk with fixed step size in continuous dimensions for now) and a simple example using the mixturemodel example in StanForRJMCMCProblems. Calls mixturemodel.stan to evaluate target density for a given number of mixture components, which is parameterised using the SpectrumDimension variable type. Fix linting
…ernative algorithm for continuous RJMCMC moves
In order to avoid problems with cmdstan/redding-stan
Added painfully basic RJMCMC sampler (just doing random-walk with fixed step size in continuous dimensions for now) and a simple example using the mixturemodel example in StanForRJMCMCProblems. Calls mixturemodel.stan to evaluate target density for a given number of mixture components, which is parameterised using the SpectrumDimension variable type. Fix linting
…ernative algorithm for continuous RJMCMC moves
Remove the need to specify continuous_dim_function to get the number of unconstrained parameters. Instead wrap the function param_unc_num from bridgestan.
- The RJMCMC sampler now contains methods to do forward and reverse grid search proposals. - The new proposals required transformations between the constrained and unconstrained parameter space so I also added these to a new file "util.py" (note this is not complete - assumes the parameters are real variables so things like simplex and covariance matrices won't work). - Also corrected the RJMCMC acceptance ratio which was missing the ratio of the continuous proposal probabilities. This is currently returned by a user-defined function called "continuous_proposal" and could therefore be made more robust. - Added a sonar example to demonstrate the new functionality. I had to modify this example due to an issue with ReddingStan not providing precision in the logprob values when the base -logprob is large.
- Updated rjmcmc_example.py so that it now has a continuous_proposal function rather than a transformation_function. - Fixed a line of code in the death move which I *think* was a mistake. - Moved sonar_example.py to examples folder. - Set the CMDSTAN_PATH variable in stan_model.py as it I couldn't see where it was being set and I was getting an error.
- Moved algorithms to sample continuous parameters (NUTS, random walk) to new file. - The NUTS step size can now be optimised in a warmup period upon entering a new continuous parameter space specified by different discrete parameters (which is needed for RJMCMC-NUTS). - Also included the mass matrix, which is set as the identity matrix, in case we need to implement mass matrix adaptation later. - Continual adaptation within SMC (without warmup) is not yet implemented.
- Moved grid search algorithms to new file "continuous_proposals.py" - Continuous proposal functions now also provide initial proposal for the continuous parameters (since this is essentially a birth move from 0 dimensions) - Stan model is now initialised within the user file since this needs to be passed via the continuous_proposal function
- Added a new discrete variable type called ReversibleJumpVariable which stores separate discrete and continuous parameters and samples / evaluates the proposal using an RJMCMC with the proposal probability set to the acceptance probability. - In order not to duplicate code, the RJMCMC algorithm has been restructured with the addition of separate proposal and evaluate steps. - Added two new grid search functions in order to evalutate the reverse proposal probability when we do a discrete move followed by a continuous move (needed when using NUTS with SMC / comparing across particles). - Included a new example "sonar_example_smc.py", which demonstrates the new functionality. To evaluate the proposal probabilities the continuous proposal functions store the current logprob and other relevant paramters by piggybacking onto the array of the continuous parameters (might be worth thinking about other approaches but it will make do for now!). - NUTS now has two modes, toggled via the "do_warmup" parameter. If warmup is enabled (i.e. for RJMCMC) it will run NUTS as normal for an initial adapatation period when entering a new continuous parameter space. If disabled (i.e. for SMC), NUTS will continue to adapt the step size each time a NUTS sample is generated.
Removing bridgestan submodule Add bridgestan (installing from git) to requirements for pip Fix imports accordingly Remove requirement to specify path to bridgestan in stan_model
Path to cmdstan is now expected in environment variable `CMDSTAN` For tests cmdstan is installed via cmdstanpy which sets this environment variable Users can install cmdstan using cmdstanpy, or install manuall and set environment variable manually.
Re-add bridgestan submodule Use environment variable to point to bridgestan If not set, use <root of repo>/bridgestan Fix setup.py to ignore bridgestan directory
Add test for Executor_MPI.gather
Test currently broken. Test fails on decode of generic variable type: ``` E _pickle.UnpicklingError: invalid load key, '\x00'. ```
On MPI decoding would result in unpickling error. Force dtype to uint8 to fix.
Trees should be considered equal if training data, tree structure and leaves are equal (lastAction need not be equal)
Add tests for: * Tree * TreeProposal * TreeInitialProposal * TreeTarget
Tests for check_stability
Bridgestan no longer required as submodule
Update examples/stan_model_example.py
Update sample offsets to work with refactored RJMCMC
Update continuous_samplers.py to use base.random.RNG
Changes to reversible_jump and sonar_example_smc to fix
New stan syntax for arrays
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add StanModel with bridgestan for continuous parameter space evaluation
Add Reversible Jump variable types:
Add continuous samplers:
Add examples for the above