Bring your own likelihood: external trainers¶
You trained a likelihood surrogate outside the HSSM ecosystem's LAN pipeline — in sbi or BayesFlow. This page routes you to the right integration path.
The routes¶
| Route | Source | Mechanism | When to use | Tutorial |
|---|---|---|---|---|
| NRE → ONNX | sbi | lanfactory.onnx.transform_sbi_to_onnx → loglik="file.onnx" |
Portable, shareable artifact; ratio estimators | sbi NRE integration |
| NLE → ONNX | BayesFlow | lanfactory.onnx.transform_bayesflow_to_onnx → loglik="file.onnx" |
Portable artifact; flow-based density estimators | BayesFlow NLE integration |
| LRE → JAX callable | BayesFlow | in-memory JAX function → loglik=<callable> |
Fast iteration during model development; no export step | BayesFlow LRE integration |
Not yet supported: MNLE-style mixed discrete/continuous observations and
NSF-based flows (blocked on SearchSorted ONNX support).
The shared workflow¶
All three tutorials follow the same skeleton, so you can read any one of them and transfer the pattern:
- Simulate training data from a known ground truth (
ssm-simulatorsorhssm.simulate_data). - Train the surrogate in its home library.
- Export — for the ONNX routes, via LANfactory's exporters, which enforce the ONNX likelihood contract by construction (see LANfactory's sbi and BayesFlow export guides for the framework-specific constraints).
- Load into HSSM —
hssm.HSSM(loglik=..., loglik_kind="approx_differentiable"); HSSM does not need to know which framework trained the surrogate. - Validate — for the DDM you can compare against HSSM's analytical likelihood as a gold standard; in general, check recovery on simulated data before trusting the surrogate on real data.
See also¶
- The ONNX likelihood contract — the rules an ONNX artifact must satisfy, runnable
- Custom models from JAX callables — the same callable gesture without an external trainer
- Understanding likelihood functions in HSSM — where
approx_differentiablefits among the likelihood kinds