{"id":37702243,"url":"https://github.com/abhiagwl/vistan","last_synced_at":"2026-01-16T13:01:13.248Z","repository":{"id":62587573,"uuid":"318887166","full_name":"abhiagwl/vistan","owner":"abhiagwl","description":"A simple library to run variational inference on Stan models.","archived":false,"fork":false,"pushed_at":"2023-04-11T19:40:31.000Z","size":287,"stargazers_count":33,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-21T15:39:04.252Z","etag":null,"topics":["autograd","automatic-differentiation","inference","inference-algorithms","iw-sampling","normalizing-flows","posterior","pystan","rank-gaussian","realnvp","stan","stan-models","variational-bayes","variational-inference"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhiagwl.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}},"created_at":"2020-12-05T20:54:06.000Z","updated_at":"2025-09-11T22:25:38.000Z","dependencies_parsed_at":"2022-11-03T17:48:04.374Z","dependency_job_id":null,"html_url":"https://github.com/abhiagwl/vistan","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/abhiagwl/vistan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhiagwl%2Fvistan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhiagwl%2Fvistan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhiagwl%2Fvistan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhiagwl%2Fvistan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhiagwl","download_url":"https://codeload.github.com/abhiagwl/vistan/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhiagwl%2Fvistan/sbom","scorecard":{"id":160714,"data":{"date":"2025-08-11","repo":{"name":"github.com/abhiagwl/vistan","commit":"714cb8753d6f97e3cf131cf66cf49391e3c8e568"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: GNU General Public License v3.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-16T13:20:29.128Z","repository_id":62587573,"created_at":"2025-08-16T13:20:29.128Z","updated_at":"2025-08-16T13:20:29.128Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["autograd","automatic-differentiation","inference","inference-algorithms","iw-sampling","normalizing-flows","posterior","pystan","rank-gaussian","realnvp","stan","stan-models","variational-bayes","variational-inference"],"created_at":"2026-01-16T13:01:12.555Z","updated_at":"2026-01-16T13:01:13.242Z","avatar_url":"https://github.com/abhiagwl.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vistan\n\n`vistan` is a simple library to run variational inference algorithms on Stan models. \n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/abhiagwl/vistan/master/vistan-example.png\" title=\"A beta-bernoulli example with vistan\"\u003e\n\u003c/p\u003e\n\n`vistan` uses [autograd][1] and [PyStan][2] under the hood. The aim is to provide a \"petting zoo\" to make it easy to play around with the different variational methods discussed in the NeurIPS 2020 paper [Advances in BBVI][3]. \n\n[1]: https://github.com/HIPS/autograd\n[2]: https://github.com/stan-dev/pystan\n[3]: https://proceedings.neurips.cc/paper/2020/file/c91e3483cf4f90057d02aa492d2b25b1-Paper.pdf\n## Features\n\n\u003e - **Initialization:** Laplace's method to initialize full-rank Gaussian\n\u003e - **Gradient Estimators:** Total-gradient, STL, DReG, closed-form entropy   \n\u003e - **Variational Families:** Full-rank Gaussian, Diagonal Gaussian, RealNVP\n\u003e - **Objectives:** ELBO, IW-ELBO\n\u003e - **IW-sampling:** Posterior samples using importance weighting\n\n## Installation\n\n```\npip install vistan\n```\n\n## Usage\nThe typical usage of the package would have the following steps:\n1. Create an algorithm. This can be done in two wasy:\n - The easiest is to use a pre-baked recipe as `algo=vistan.recipe('meanfield')`. There are various options: \n    + `'advi'`: Run our implementation of ADVI's PyStan.\n    + `'meanfield'`: Full-factorized Gaussia a.k.a meanfield VI\n    + `'fullrank'`: Use a full-rank Gaussian for better dependence between latent variables \n    + `'flows'`: Use a RealNVP flow-based VI\n    + `'method x'`: Use methods from the paper [Advances in BBVI][3] where x is one of `[0, 1, 2, 3a, 3b, 4a, 4b, 4c, 4d]`\n- Alternatively, you can create a custom algorithm as `algo=vistan.algorithm()`. Some most frequent arguments:\n    + `vi_family`: This can be one of `['gaussian', 'diagonal', 'rnvp']` (Default: `gaussian`)\n    + `max_iter`: The maximum number of optimization iterations. (Default: 100)\n    + `optimizer`: This can be `'adam'` or `'advi'`. (Default: `'adam'`)\n    + `grad_estimator`: What gradient estimator to use. Can be `'Total-gradient'`, `'STL'`, `'DReG'`, or `'closed-form-entropy'`. (Default: `'DReG'`)\n    + `M_iw_train`: The number of importance samples. Use `1` for standard variational inference or more for importance-weighted variational inference. (Default: 1)\n    + `per_iter_sample_budget`: The total number of evaluations to use in each iteration. (Default: 100)\n2. Get an approximate posterior as `posterior=algo(code, data)`. This runs the algorithm on Stan model given by the string `code` with observations given by the `data`.\n3. Draw samples from the approximate posterior as `samples=posterior.sample(100)`. You can also draw samples using importance weighting as `posterior.sample(100, M_iw_sample=10)`. Further, you can evaluate the log-probability of the posterior as `posterior.log_prob(latents)`. \n\n## Citing vistan\nIf you use vistan, please, consider citing:\n\n```\n@inproceedings{aagrawal2020,\n  author    = {Abhinav Agrawal and\n               Daniel R. Sheldon and\n               Justin Domke},\n  title     = {Advances in Black-Box {VI:} Normalizing Flows, Importance Weighting,\n               and Optimization},\n  booktitle = {Advances in Neural Information Processing Systems 33: Annual Conference\n               on Neural Information Processing Systems 2020, NeurIPS 2020, December\n               6-12, 2020, virtual},\n  year      = {2020},\n}\n```\n\n## Recipes\nRecipies refers to set of predetermined hyperparameters that let you quickly run some common variational algorithms. \n### Meanfield Gaussian \n`'meanfield'` runs the fully factorized Gaussian VI optimized using `Adam`    \n\n```python\nimport vistan \nimport matplotlib.pyplot as plt\nimport numpy as np \nimport scipy\ncode = \"\"\"\ndata {\n    int\u003clower=0\u003e N;\n    int\u003clower=0,upper=1\u003e x[N];\n}\nparameters {\n    real\u003clower=0,upper=1\u003e p;\n}\nmodel {\n    p ~ beta(1,1);\n    x ~ bernoulli(p);\n}\n\"\"\"\ndata = {\"N\":5, \"x\":[0,1,0,0,0]}\nalgo = vistan.recipe() # runs Meanfield VI by default\nposterior = algo(code, data) \nsamples = posterior.sample(100000)\n\npoints = np.arange(0,1,.01)\nplt.hist(samples['p'], 200, density = True, histtype = 'step')\nplt.plot(points,scipy.stats.beta(2,5).pdf(points),label='True Posterior')\nplt.legend()\nplt.show()\n```\n\n### Full-rank Gaussian \n`'fullrank'`, as the name suggests, optimizes full-rank Gaussian VI using `Adam`\n```python\nalgo = vistan.recipe(\"fullrank\")  \nposterior = algo(code, data)\nsamples = posterior.sample(100000)\n\npoints = np.arange(0, 1, .01)\nplt.hist(samples['p'], 200, density=True, histtype='step')\nplt.plot(points, scipy.stats.beta(2, 5).pdf(points), label='True Posterior')\nplt.legend()\nplt.show()\n\n```\n\n### Flow-based VI\n`'flows'` optimizes a RealNVP inspired flow distribution for variational approximation using `Adam` \n```python\nalgo = vistan.recipe(\"flows\")  \nposterior = algo(code, data)\nsamples = posterior.sample(100000)\n\npoints = np.arange(0, 1, .01)\nplt.hist(samples['p'], 200, density=True, histtype='step')\nplt.plot(points, scipy.stats.beta(2, 5).pdf(points), label='True Posterior')\nplt.legend()\nplt.show()\n\n```\n\n### ADVI\n`'advi'` runs our implementation of PyStan's ADVI and uses their custom step-sequence scheme\n```python\nalgo = vistan.recipe(\"advi\")  \nposterior = algo(code, data)\nsamples = posterior.sample(100000)\n\npoints = np.arange(0, 1, .01)\nplt.hist(samples['p'], 200, density=True, histtype='step')\nplt.plot(points, scipy.stats.beta(2, 5).pdf(points), label='True Posterior')\nplt.legend()\nplt.show()\n```\n\n### Methods from [Advances in BBVI][3]\n`method x` runs implementation of different variational methods from [Advances in BBVI][3], where `x` is one of `[0, 1, 2, 3a, 3b, 4a, 4b, 4c, 4d]` \n```python\n# Try method 0, 1, 2, 3a, 3b, 4a, 4b, 4c, 4d\nalgo = vistan.recipe(\"method 4d\")  \nposterior = algo(code, data)\nsamples = posterior.sample(100000)\n\npoints = np.arange(0, 1, .01)\nplt.hist(samples['p'], 200, density=True, histtype='step')\nplt.plot(points, scipy.stats.beta(2, 5).pdf(points), label='True Posterior')\nplt.legend()\nplt.show()\n```\n\n## Custom algorithms\nYou can also specify custom VI algorithms to work with your Stan models using `vistan.algorithm`. Please, see the documentation of `vistan.algorithm` for a complete list of supported arguments. \n```python\nalgo = vistan.algorithm(\n                M_iw_train=2,\n                grad_estimator=\"DReG\",\n                vi_family=\"gaussian\",\n                per_iter_sample_budget=10,\n                max_iters=100)\nposterior = algo(code, data)\nsamples = posterior.sample(100000)\n\npoints = np.arange(0, 1, .01)\nplt.hist(samples['p'], 200, density=True, histtype='step')\nplt.plot(points, scipy.stats.beta(2, 5).pdf(points), label='True Posterior')\nplt.legend()\nplt.show()\n```\n### IW-sampling\nWe provide support to use IW-sampling at inference time; this importance weights `M_iw_sample` candidate samples and picks one (see [Advances in BBVI][3] for more information.) IW-sampling is a post-hoc step and can be used with almost any variational scheme.\n```python\nsamples = posterior.sample(100000, M_iw_sample=10)\n\npoints = np.arange(0, 1, .01)\nplt.hist(samples['p'], 200, density=True, histtype='step')\nplt.plot(points, scipy.stats.beta(2, 5).pdf(points), label='True Posterior')\nplt.legend()\nplt.show()\n```\n### Initialization\nWe provide support to use Laplace's method to initialize the parameters for Gaussian VI.\n```python\nalgo = vistan.algorithm(vi_family='gaussian', LI=True)\nposterior = algo(code, data) \nsamples = posterior.sample(100000)\n\npoints = np.arange(0, 1, .01)\nplt.hist(samples['p'], 200, density=True, histtype='step')\nplt.plot(points, scipy.stats.beta(2, 5).pdf(points), label='True Posterior')\nplt.legend()\nplt.show()\n```\n### Building your own inference algorithms\nWe provide access to the `model.log_prob` function we use internally for optimization. This allows you to evaluate the log density in the unconstrained space for your Stan model. Also, this function is differentiable in `autograd`.\n```python\nlog_prob = posterior.model.log_prob\n\n```\n\n\n## Limitations\n\n\n\u003e - We currently only support inference on all latent parameters in the model\n\u003e - No support for data sub-sampling.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhiagwl%2Fvistan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhiagwl%2Fvistan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhiagwl%2Fvistan/lists"}