{"id":21372416,"url":"https://github.com/christophmark/bayesianfridge","last_synced_at":"2025-08-01T10:43:23.082Z","repository":{"id":57414225,"uuid":"128050340","full_name":"christophmark/bayesianfridge","owner":"christophmark","description":"Sequential Monte Carlo sampler for PyMC2 models.","archived":false,"fork":false,"pushed_at":"2018-04-04T11:20:16.000Z","size":56,"stargazers_count":13,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-19T09:37:03.502Z","etag":null,"topics":["inference","inference-engine","model-selection","monte-carlo","sequential-monte-carlo"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/christophmark.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":"2018-04-04T11:04:43.000Z","updated_at":"2024-04-15T06:44:22.000Z","dependencies_parsed_at":"2022-08-26T20:45:25.323Z","dependency_job_id":null,"html_url":"https://github.com/christophmark/bayesianfridge","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophmark%2Fbayesianfridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophmark%2Fbayesianfridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophmark%2Fbayesianfridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophmark%2Fbayesianfridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christophmark","download_url":"https://codeload.github.com/christophmark/bayesianfridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225863905,"owners_count":17536191,"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":["inference","inference-engine","model-selection","monte-carlo","sequential-monte-carlo"],"created_at":"2024-11-22T08:19:51.176Z","updated_at":"2024-11-22T08:19:51.689Z","avatar_url":"https://github.com/christophmark.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![bayesianfridge](https://raw.githubusercontent.com/christophmark/bayesianfridge/master/docs/images/logo-500px.png)\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![DOI](https://zenodo.org/badge/128050340.svg)](https://zenodo.org/badge/latestdoi/128050340)\n\nThis package implements Bayesian annealed sequential importance sampling (BASIS), a Sequential Monte Carlo sampling technique described by [Wu2017](https://doi.org/10.1115/1.4037450). In particular, it implements the special case with a maximum chain length of one (l_max = 1). Sequential Monte Carlo methods stand out against MCMC or HMC methods as they are able to estimate the model evidence (also called marginal likelihood) which can be used to objectively compare models of varying complexity. We combine the algorithm by [Wu2017](https://doi.org/10.1115/1.4037450) with an optional tuning method for the proposal scaling factor beta, as described by [Minson2013](https://doi.org/10.1093/gji/ggt180). The sample function can perform parameter inference and model selection on any valid [PyMC2](https://pymc-devs.github.io/pymc/)-model object.\n\n## Installation\nThe easiest way to install the latest release version of *bayesianfridge* is via `pip`:\n```\npip install bayesianfridge\n```\nAlternatively, a zipped version can be downloaded [here](https://github.com/christophmark/bayesianfridge/releases). The module is installed by calling `python setup.py install`.\n\n## Development version\nThe latest development version of *bayesianfridge* can be installed from the master branch using pip (requires git):\n```\npip install git+https://github.com/christophmark/bayesianfridge\n```\nAlternatively, use this [zipped version](https://github.com/christophmark/bayesianfridge/zipball/master) or clone the repository.\n\n## Getting started\nThe following code provides a minimal example of an analysis carried out using *bayesloop*. The data here consists of the number of coal mining disasters in the UK per year from 1851 to 1962 (see this [article](https://academic.oup.com/biomet/article-pdf/66/1/191/600109/66-1-191.pdf) for further information). This example is also discussed in the official [PyMC2 documentation](https://pymc-devs.github.io/pymc/tutorial.html).\n\n```\nimport numpy as np\nimport pymc\nfrom bayesianfridge import sample\nimport matplotlib.pyplot as plt\n\ndata = np.array([5, 4, 1, 0, 4, 3, 4, 0, 6, 3, 3, 4, 0, 2, 6, 3, 3, 5, 4, 5, 3, 1, 4,\n                 4, 1, 5, 5, 3, 4, 2, 5, 2, 2, 3, 4, 2, 1, 3, 2, 2, 1, 1, 1, 1, 3, 0,\n                 0, 1, 0, 1, 1, 0, 0, 3, 1, 0, 3, 2, 2, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0,\n                 0, 2, 1, 0, 0, 0, 1, 1, 0, 2, 3, 3, 1, 1, 2, 1, 1, 1, 1, 2, 3, 3, 0,\n                 0, 0, 1, 4, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0])\n\n# Probabilistic model\nswitchpoint = pymc.DiscreteUniform('switchpoint', lower=0, upper=110)\nearly_mean = pymc.Exponential('early_mean', beta=1.)\nlate_mean = pymc.Exponential('late_mean', beta=1.)\n\n@pymc.deterministic\ndef rate(s=switchpoint, e=early_mean, l=late_mean):\n    out = np.empty(len(data))\n    out[:s] = e\n    out[s:] = l\n    return out\n\nobs = pymc.Poisson('disasters', mu=rate, value=data, observed=True)\n\nmodel = pymc.Model([switchpoint, early_mean, late_mean, obs])\n\n# Inference\nsamples, marglike = sample(model, 10000)\n\n# Plotting\nm1 = samples['early_mean']\nt = samples['switchpoint'] + 1852\nm2 = samples['late_mean']\n\nplt.figure()\n\nplt.subplot2grid((1, 2), (0, 0))\nplt.hist(m1, facecolor='C0', label='before')\nplt.hist(m2, facecolor='C1', label='after')\nplt.xlabel('Accident rate')\nplt.ylabel('Probability density')\nplt.yticks([])\nplt.grid()\nplt.legend()\n\nplt.subplot2grid((1, 2), (0, 1))\n\nplt.hist(t, bins=range(int(min(t)), int(max(t)) + 1, 1), facecolor='C2')\nplt.xlabel('Switchpoint')\nplt.ylabel('Probability')\nplt.yticks([])\nplt.grid()\n```\n\n![Analysis plot](https://raw.githubusercontent.com/christophmark/bayesianfridge/master/docs/images/minimal-example.png)\n\n## License\n[The MIT License (MIT)](https://github.com/christophmark/bayesianfridge/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristophmark%2Fbayesianfridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristophmark%2Fbayesianfridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristophmark%2Fbayesianfridge/lists"}