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

Minor mcmc refactor 770 #772

Merged
merged 8 commits into from
Mar 11, 2025

Conversation

njtierney
Copy link
Collaborator

Resolves #770

…t cleaner:

- inform_if_remote_machine
- inform_if_local_parallel_multiple_samplers
- set_progress_bar_type
- sampler_parallel_reporting
- build_samplers
- empty_matrices: abstraction of replicate(n, matrix(NA, 0, n), simplify = FALSE)
- samplers get "name" attribute, as we will likely need to create logic to manage different behaviour for different samplers
- Move "sampler" R6 class into "sampler_class.R"
- Move individual R6 sampler methods (hmc, rwmh, slice) into "samplers.R"
@njtierney njtierney marked this pull request as ready for review March 11, 2025 01:05
@njtierney
Copy link
Collaborator Author

njtierney commented Mar 11, 2025

This PR does the following:

  • Implements name attribute of samplers. E.g., hmc()$name returns "hmc". This should help make some future code for dispatch a bit simpler.

Some tidying up of samplers:

  • Creates "sampler_class.R" and moved relevant parts of "inference_class.R" into that
  • Moves R6 sampler objects into "samplers.R

Improves abstraction in run_samplers

  • Created self$run_warmup and self$run_sampling functions. This means we can now write our own custom warmup or sampling methods for each sampler, if we need to (which we will need to be able to do in order to get adaptive HMC working)

Created build_samplers in mcmc

  • Does the lapply(...build_sampler) step, plus the other bits around that, which are a bit distracting from the overall intention

Adds some helper functions to re-express code intent

  • create_empty_matrix
  • set_progress_bar_type
  • inform_if_remote_machine
  • inform_if_local_parallel_multiple_samplers
  • sampler_parallel_reporting - manage complexity around writing to log files and greta stash

I couldn't quite get the abstraction of the progress bars down. I think there is scope for that, but in the grand scheme of things, it's actually quite a small issue, it's only about 25 lines of code. It might be a nice idea to come back to as something bite sized. I'll make an issue for it.

@njtierney njtierney merged commit fbc1632 into greta-dev:master Mar 11, 2025
10 checks passed
@njtierney njtierney deleted the minor-mcmc-refactor-770 branch March 11, 2025 01:28
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.

minor refactor of mcmc internals
1 participant