Skip to content

Use bayesflow lre through hssm#914

Merged
AlexanderFengler merged 3 commits intomainfrom
use-bayesflow-lre-through-hssm
Mar 5, 2026
Merged

Use bayesflow lre through hssm#914
AlexanderFengler merged 3 commits intomainfrom
use-bayesflow-lre-through-hssm

Conversation

@AlexanderFengler
Copy link
Member

This is the first of two PRs and should serve as the basis for a decision on what kind of glue-code to own on this front.

In principle, we should be able to incorporate these types of networks natively as an option / addition into our overall pipeline.

Small bugfix along the way, bug was discovered while testing.


This pull request introduces integration with BayesFlow LRE and updates documentation and dependencies accordingly. The most important changes are grouped below by theme.

BayesFlow LRE Integration:

  • Added an optional dependency group bayesflow in pyproject.toml to support BayesFlow integration, including required packages bayesflow and keras.
  • Added a new tutorial on BayesFlow LRE integration: tutorials/bayesflow_lre_integration.ipynb is now included in the documentation navigation and build process. [1] [2]

Inference Method Handling:

  • Simplified the inference method selection in the sample method of src/hssm/hssm.py by directly passing the sampler argument, allowing for more flexible integration of new inference engines like BayesFlow.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR lays groundwork for integrating BayesFlow likelihood-ratio estimators (LRE) into the HSSM workflow by adding an installable optional dependency set and exposing the new tutorial in the docs, alongside a small change to how HSSM.sample() forwards the chosen inference engine to Bambi.

Changes:

  • Forward sampler directly as inference_method into bmb.Model.fit() from HSSM.sample().
  • Add a bayesflow optional dependency extra (bayesflow, keras) to support the integration tutorial.
  • Register the new BayesFlow LRE tutorial notebook in the MkDocs navigation and (non-)execution configuration.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.

File Description
src/hssm/hssm.py Adjusts how the selected sampler/inference engine is passed into Bambi’s fit() call.
pyproject.toml Adds an optional dependency extra to enable pip install hssm[bayesflow].
mkdocs.yml Adds the BayesFlow LRE tutorial to the docs nav and mkdocs-jupyter config.
Comments suppressed due to low confidence (1)

src/hssm/hssm.py:794

  • hssm.HSSM.sample() now passes sampler straight through as inference_method to bmb.Model.fit(). There are existing tests that call sample(sampler="numpyro"), but they only assert that an InferenceData is returned, so they won’t catch regressions where the requested sampler is ignored or mapped incorrectly. Consider adding a regression check that the requested sampler/inference method is actually used (e.g., assert on metadata recorded in the returned InferenceData, or mock/spy on bmb.Model.fit to verify the argument value).
        self._inference_obj = self.model.fit(
            inference_method=sampler,
            init=init,
            include_response_params=include_response_params,
            omit_offsets=omit_offsets,
            **kwargs,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@AlexanderFengler
Copy link
Member Author

@digicosmos86 could you give a quick glance at the sampler routing logic and approve / request changes if you disagree with anything there?

Trying to get it into the release.

Copy link
Collaborator

@digicosmos86 digicosmos86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Seems like an easy integration with HSSM through a callable

@AlexanderFengler AlexanderFengler merged commit 86ccfe6 into main Mar 5, 2026
4 checks passed
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