{"id":16599956,"url":"https://github.com/dirmeier/ssnl","last_synced_at":"2026-04-17T23:03:16.547Z","repository":{"id":185580238,"uuid":"630004992","full_name":"dirmeier/ssnl","owner":"dirmeier","description":"Simulation-based inference using SSNL","archived":false,"fork":false,"pushed_at":"2023-08-02T11:23:53.000Z","size":59,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-17T06:45:47.059Z","etag":null,"topics":["approximate-bayesian-computation","approximate-inference","bayesian-inference","jax","normalizing-flows","simulation-based-inference"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dirmeier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-19T13:20:59.000Z","updated_at":"2024-07-09T11:52:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"2d6e2b35-3a27-4263-b96a-611ea1f24abd","html_url":"https://github.com/dirmeier/ssnl","commit_stats":null,"previous_names":["dirmeier/ssnl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirmeier%2Fssnl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirmeier%2Fssnl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirmeier%2Fssnl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirmeier%2Fssnl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dirmeier","download_url":"https://codeload.github.com/dirmeier/ssnl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242538977,"owners_count":20145882,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["approximate-bayesian-computation","approximate-inference","bayesian-inference","jax","normalizing-flows","simulation-based-inference"],"created_at":"2024-10-12T00:13:07.339Z","updated_at":"2026-04-17T23:03:16.537Z","avatar_url":"https://github.com/dirmeier.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Surjective sequential neural likelihood estimation\n\n[![ci](https://github.com/dirmeier/ssnl/actions/workflows/ci.yaml/badge.svg)](https://github.com/dirmeier/ssnl/actions/workflows/ci.yaml)\n[![arXiv](https://img.shields.io/badge/arXiv-2308.01054-b31b1b.svg)](https://arxiv.org/abs/2308.01054)\n\n## About\n\nThis repository contains the Python code for reproducing the experimental results in the manuscript\n\n\u003e Simon Dirmeier, Carlo Albert, Fernando Perez-Cruz, *Simulation-based Inference for High-dimensional Data using Surjective Sequential Neural Likelihood Estimation*, UAI 2025\n\u003e [[arXiv]](https://arxiv.org/abs/2308.01054)\n\n- `configs` contains configuration files for the different inferential algorithms,\n- `data_and_models` contains implementation of experimental benchmark models,\n- `envs` contains requires conda environment files,\n- `ssnl` implements the method SSNL and all baselines,\n- `experiments` contains source code for SSNL/SNL/SNPE/SNRE with the logic to run the experiments,\n- `.*py` files are entry point scripts that execute the experiments.\n\n## Installation\n\nIf you run the Snakemake workflow, no installation of dependencies is requires except having access to `conda` on the command line. E.g., check if this works on the command-line interface:\n\n```bash\nconda --version\n```\n\nIf it is showing a conda version, you are set. Otherwise install Miniconda from [here](https://docs.conda.io/projects/miniconda/en/latest/).\n\n## Usage\n\nTo run the experiments, make sure you have access to a `zsh` or `bash` shell.\nYou can either run experiments manually or use Snakemake to run everything in an automated fashion.\n\n### Automatic execution (recommended)\n\nIf you want to run all experiments from the manuscript and the appendix you can do it automatically using Snakemake.\n*Note*: this will run all experiments which will require a significant amount of compute hours.\nFirst, install Snakemake via:\n\n```bash\npip install snakemake==9.3.0\n```\n\nThen, on a HPC cluster use\n\n```bash\nsnakemake --cluster {sbatch/qsub/bsub} --use-conda --configfile=snake_config.yaml --jobs N_JOBS\n```\n\nwhere `--cluster {sbatch/qsub/bsub}` specifies the command your cluster uses for job management and `--jobs N_JOBS` sets the number of jobs submitted at the same time. For instance, to run on a SLURM cluster:\n\n```bash\nsnakemake --cluster sbatch --use-conda  --configfile=snake_config.yaml --jobs 100\n```\n\nYou can also directly specify your job scheduler:\n\n```bash\nsnakemake \\\n  --use-conda \\\n  --slurm \\\n  --configfile=snake_config.yaml \\\n  --jobs 100\n```\n\nAll the rules have default resources set.\n\n### Manual execution (not recommended)\n\nIf you want to manually execute all jobs, first install these conda environments.\n\n```bash\nconda env create -f envs/jax-environment.yaml -n ssnl-jax\nconda env create -f envs/torch-environment.yaml -n ssnl-torch\nconda env create -f envs/eval-environment.yaml -n ssnl-eval\n```\n\nWe demonstrate running a training job for a specific example (SIR).\nFirst, train SSNL using the command below:\n\n```bash\nconda activate ssnl-jax\npython 01-main.py  \\\n    --outdir=\u003c\u003coutpath\u003e\u003e \\\n    --mode=fit \\\n    --data_config=data_and_models/sir.py \\\n    --data_config.rng_key=\u003c\u003cseed\u003e\u003e \\\n    --config=configs/ssnl.py \\\n    --config.rng_key=\u003c\u003cseed\u003e\u003e \\\n    --config.model.reduction_factor=0.75 \\\n    --config.training.n_rounds=15\n```\n\nwhere `\u003c\u003coutpath\u003e\u003e` is a target directory where results will be stored and `\u003c\u003cseed\u003e\u003e` is an int (which needs to be the same between config and data config).\nThe same call for SNL would look like this:\n\n```bash\nconda activate ssnl-jax\npython 01-main.py  \\\n    --outdir=\u003c\u003coutpath\u003e\u003e \\\n    --mode=fit \\\n    --data_config=data_and_models/sir.py \\\n    --data_config.rng_key=\u003c\u003cseed\u003e\u003e \\\n    --config=configs/snl.py \\\n    --config.rng_key=\u003c\u003cseed\u003e\u003e \\\n    --config.training.n_rounds=15\n```\n\nFor SNRE and SNPE, the call is the same EXCEPT that the data config needs to be suffixed by `_torch`. For instance, for SNPE:\n\n```bash\nconda activate ssnl-torch\npython 01-main.py  \\\n    --outdir=\u003c\u003coutpath\u003e\u003e \\\n    --mode=fit \\\n    --data_config=data_and_models/sir_torch.py \\\n    --data_config.rng_key=\u003c\u003cseed\u003e\u003e \\\n    --config=configs/snpe.py \\\n    --config.rng_key=\u003c\u003cseed\u003e\u003e \\\n    --config.training.n_rounds=15\n```\n\nThe above commands generate several parameter files with suffix `-params.pkl` that contain the trained neural network parameters. To get posterior samples, you would run\n\n```bash\nconda activate ssnl-jax\npython 01-main.py  \\\n    --outdir=\u003c\u003coutpath\u003e\u003e \\\n    --mode=sample \\\n    --data_config=data_and_models/sir.py \\\n    --data_config.rng_key=\u003c\u003cseed\u003e\u003e \\\n    --config=configs/ssnl.py \\\n    --config.rng_key=\u003c\u003cseed\u003e\u003e \\\n    --config.model.reduction_factor=0.75 \\\n    --config.training.n_rounds=\u003c\u003cround\u003e\u003e \\\n    --checkpoint=\u003c\u003coutpath\u003e\u003e/sbi-sir-ssnl-seed_\u003c\u003cseed\u003e\u003e-reduction_factor=0.75-n_rounds=\u003c\u003cround\u003e\u003e-params.pkl\n```\n\nwhere `\u003c\u003cround\u003e\u003e` specified a round between 1 and 15 (since above` n_rounds` equalled 15). The `checkpoint` is the file that has been created during training. This creates a file  with suffix `posteriors.pkl`.\n\nTo draw samples from the posterior using MCMC:\n\n```bash\nconda activate ssnl-jax\npython 01-main.py  \\\n    --outdir=\u003c\u003coutpath\u003e\u003e \\\n    --mode=sample \\\n    --data_config=data_and_models/sir.py \\\n    --data_config.rng_key=\u003c\u003cseed\u003e\u003e \\\n    --config=configs/mcmc.py \\\n    --config.rng_key=\u003c\u003cseed\u003e\u003e\n```\n\nThis creates a file  with suffix `posteriors.pkl`, too.\n\nTo compute divergences between true and surrogate posterior, call:\n\n```bash\nconda activate ssnl-eval\npython compute_mmd.py \\\n  \u003c\u003coutpath\u003e\u003e/sbi-sir-mcmc-seed_\u003c\u003cseed\u003e\u003e\u003e-posteriors.pkl \\\n  \u003c\u003coutpath\u003e\u003e/sbi-sir-ssnl-seed_\u003c\u003cseed\u003e\u003e-reduction_factor=0.75-n_rounds=\u003c\u003cround\u003e\u003e-posteriors.pkl \\\n  \u003c\u003coutpath/\u003c\u003coutfile\u003e\u003e\n  10000\n```\n\nYou will need to repeat that for seeds 1-10, the models in `data_and_models` and the different methods (SSNL, SNL, SNASS, SNASSS, SNRE, SNPE).\n\n## Citation\n\nIf you find our work relevant to your research, please consider citing:\n\n```\n@inproceedings{\n  dirmeier2025surjective,\n  title={Simulation-based Inference for High-dimensional Data using Surjective Sequential Neural Likelihood Estimation},\n  author={Dirmeier, Simon and Albert, Carlo and Perez-Cruz Fernando},\n  year={2025},\n  booktitle={Proceedings of the Forty-First Conference on Uncertainty in Artificial Intelligence}\n}\n```\n\n## Author\n\nSimon Dirmeier \u003ca href=\"mailto:simd @ mailbox org\"\u003esimd @ mailbox org\u003c/a\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirmeier%2Fssnl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdirmeier%2Fssnl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirmeier%2Fssnl/lists"}