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

Add support for constructing target distribution from formula #66

Merged
merged 13 commits into from
Jan 6, 2025

Conversation

matt-graham
Copy link
Collaborator

@matt-graham matt-graham commented Dec 11, 2024

Adds support for specifying target distribution by specifying a formula for log density using R ~ formula syntax (only right-hand side of formula is used). A function to compute log density and its gradient is then constructed using the stats::deriv function along with a function to trace variables from chain state.

As well as adding a utility function for this conversion, this PR also changes the behaviour of sample_chain to allow accepting formulas and bridgestan Stan models directly as the target_distribution argument, with these then converted internally to a list of functions. As part of this the separate trace_function optional argument has been removed in favour of assuming this is specified as part of the target_distribution list (or constructed from the formula / Stan model).

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (95acd2d) to head (6efa4f1).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #66   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           11        11           
  Lines          525       564   +39     
=========================================
+ Hits           525       564   +39     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@matt-graham matt-graham marked this pull request as ready for review January 6, 2025 12:40
@matt-graham matt-graham merged commit 7f87e4b into main Jan 6, 2025
11 checks passed
@matt-graham matt-graham deleted the mmg/deriv-support branch January 6, 2025 12:40
@matt-graham matt-graham added the enhancement New feature or request label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant