{"id":13699461,"url":"https://github.com/tingiskhan/pyfilter","last_synced_at":"2025-05-04T16:34:20.499Z","repository":{"id":34133140,"uuid":"89852842","full_name":"tingiskhan/pyfilter","owner":"tingiskhan","description":"Particle filtering and sequential parameter inference in Python","archived":true,"fork":false,"pushed_at":"2023-04-22T07:34:43.000Z","size":31945,"stargazers_count":75,"open_issues_count":1,"forks_count":15,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-03T20:04:22.132Z","etag":null,"topics":["bayesian-inference","particle-filter","pytorch","sequential-monte-carlo","time-series"],"latest_commit_sha":null,"homepage":"","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/tingiskhan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"roadmap":null,"authors":null}},"created_at":"2017-04-30T13:37:26.000Z","updated_at":"2024-04-29T21:54:34.000Z","dependencies_parsed_at":"2024-01-12T20:00:44.329Z","dependency_job_id":"2abaac8d-7bcd-47b3-ba09-256740a6027d","html_url":"https://github.com/tingiskhan/pyfilter","commit_stats":null,"previous_names":[],"tags_count":71,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tingiskhan%2Fpyfilter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tingiskhan%2Fpyfilter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tingiskhan%2Fpyfilter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tingiskhan%2Fpyfilter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tingiskhan","download_url":"https://codeload.github.com/tingiskhan/pyfilter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224398825,"owners_count":17304661,"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":["bayesian-inference","particle-filter","pytorch","sequential-monte-carlo","time-series"],"created_at":"2024-08-02T20:00:33.834Z","updated_at":"2024-11-13T05:31:03.681Z","avatar_url":"https://github.com/tingiskhan.png","language":"Python","readme":"# About the project\npyfilter is a package designed for joint parameter and state inference in state space models using\nparticle filters and particle filter based inference algorithms. It's borne out of my layman's interest in Sequential \nMonte Carlo methods, and a continuation of my [Master's thesis](http://urn.kb.se/resolve?urn=urn:nbn:se:kth:diva-177104).\n\nSome features include:\n1. Particle filters in the form of [SISR](https://en.wikipedia.org/wiki/Particle_filter) and [APF](https://en.wikipedia.org/wiki/Auxiliary_particle_filter) together with different proposal distributions.\n2. Both online and offline inference algorithms such as\n   1. [SMC2](https://arxiv.org/abs/1101.1528) \n   2. [NESS](https://arxiv.org/abs/1308.1883)\n   3. [SMC2FW](https://arxiv.org/pdf/1503.00266.pdf)\n   4. [PMMH](https://www.stats.ox.ac.uk/~doucet/andrieu_doucet_holenstein_PMCMC.pdf)\n   5. Variational inference targeting parameters coupled with particle filters for estimating log-likelihood. \n3. [pytorch](https://pytorch.org/) backend enables GPU accelerated inference - what took hours on a CPU now takes minutes (or even seconds).\n\n# Getting started\nFollow the below instructions in order to get started with pyfilter.\n\n## Prerequisites\nStart by [installing pytorch](https://pytorch.org/get-started/locally/). \n\n## Installation\nTo install pyfilter just copy the below command into your favourite terminal \n\n```cmd\npip install git+https://github.com/tingiskhan/pyfilter\n```\n\n# Usage\n\nAll examples are located [here](./examples), but you'll find a short one below in which we define a sine diffusion \nprocess which we observe with some noise, and then back out using the APF together with the \"optimal proposal\"\ndistribution\n\n```python\nfrom stochproc import timeseries as ts\nimport torch\nfrom pyro.distributions import Normal\nimport matplotlib.pyplot as plt\nfrom pyfilter.filters.particle import APF, proposals\nfrom math import sqrt\n\n\ndef f(x, gamma, sigma):\n    return torch.sin(x.value - gamma), sigma\n\n\ndef build_observation(x, a, s):\n    return Normal(loc=a * x.value, scale=s)\n\n\ndef initial_kernel(gamma, sigma):\n    return Normal(torch.zeros_like(gamma), torch.ones_like(gamma))\n\n\ndt = 0.1\n\ngamma = 0.0\nsigma = 1.0\n\ninc_dist = Normal(loc=0.0, scale=sqrt(dt))\nsine_diffusion = ts.AffineEulerMaruyama(f, (gamma, sigma), inc_dist, initial_kernel=initial_kernel, dt=dt)\n\na = 1.0\ns = 0.1\n\nssm = ts.StateSpaceModel(sine_diffusion, build_observation, (a, s))\n\nsample_result = ssm.sample_states(250)\nx, y = sample_result.get_paths()\n\nfig, ax = plt.subplots()\n\nax.set_title(\"Latent\")\nax.plot(sample_result.time_indexes, x, label=\"True\", color=\"gray\")\nax.plot(sample_result.time_indexes, y, marker=\"o\", linestyle=\"None\", label=\"Observed\", color=\"lightblue\")\n\nfilt = APF(ssm, 250, proposal=proposals.LinearGaussianObservations(0))\nresult = filt.batch_filter(y)\n\nax.plot(sample_result.time_indexes, result.filter_means.numpy()[1:], label=\"Filtered\", color=\"salmon\", alpha=0.5)\nax.legend()\n```\n\n\u003cdiv align=\"center\"\u003e \n    \u003cimg src=\"./static/filtering.jpg\" alt=\"Logo\" width=\"640\" height=\"480\"\u003e\n\u003c/div\u003e\n\n# Contributing\n\nContributions are always welcome! Simply\n1. Fork the project.\n2. Create your feature branch (I try to follow [Microsoft's naming](https://docs.microsoft.com/en-us/azure/devops/repos/git/git-branching-guidance?view=azure-devops)).\n3. Push the branch to origin.\n4. Open a pull request.\n\n# License\nDistributed under the MIT License, see `LICENSE` for more information.\n\n# Contact\nContact details are located under `setup.py`.\n\n\n","funding_links":[],"categories":["\u003cspan id=\"head30\"\u003e3.4. Bayesian Inference\u003c/span\u003e"],"sub_categories":["\u003cspan id=\"head33\"\u003e3.4.3. Data Assimilation (SMC, particles filter)\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftingiskhan%2Fpyfilter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftingiskhan%2Fpyfilter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftingiskhan%2Fpyfilter/lists"}