Skip to content

Conversation

@alecksphillips
Copy link
Collaborator

  • Add StanModel with bridgestan for continuous parameter space evaluation

  • Add Reversible Jump variable types:

    • ReversibleJumpVariable
    • ReversibleJumpTarget
    • ReversibleJumpProposal
    • ReversibleJumpInitialProposal
  • Add continuous samplers:

    • NUTS
    • RandomWalk
  • Add examples for the above

alecksphillips and others added 30 commits July 8, 2022 11:55
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
alecksphillips and others added 30 commits July 27, 2023 18:21
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants