{"id":32382781,"url":"https://github.com/hugohadfield/bayesfilter","last_synced_at":"2025-10-25T01:50:29.996Z","repository":{"id":251646578,"uuid":"814645007","full_name":"hugohadfield/bayesfilter","owner":"hugohadfield","description":"Pure Python/Numpy Bayesian Filtering and Smoothing","archived":false,"fork":false,"pushed_at":"2024-10-16T20:00:55.000Z","size":16,"stargazers_count":27,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-23T03:38:40.466Z","etag":null,"topics":["data-analysis","ekf","filtering","smoothing","ukf"],"latest_commit_sha":null,"homepage":"https://hh409.user.srcf.net","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/hugohadfield.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-13T12:14:48.000Z","updated_at":"2025-08-07T00:00:56.000Z","dependencies_parsed_at":"2024-08-04T20:01:15.649Z","dependency_job_id":"2f1d6043-269c-4086-990b-3bd929ccab28","html_url":"https://github.com/hugohadfield/bayesfilter","commit_stats":null,"previous_names":["hugohadfield/bayesfilter"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/hugohadfield/bayesfilter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugohadfield%2Fbayesfilter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugohadfield%2Fbayesfilter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugohadfield%2Fbayesfilter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugohadfield%2Fbayesfilter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hugohadfield","download_url":"https://codeload.github.com/hugohadfield/bayesfilter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugohadfield%2Fbayesfilter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280893634,"owners_count":26409279,"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","status":"online","status_checked_at":"2025-10-24T02:00:06.418Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["data-analysis","ekf","filtering","smoothing","ukf"],"created_at":"2025-10-25T01:50:10.682Z","updated_at":"2025-10-25T01:50:29.988Z","avatar_url":"https://github.com/hugohadfield.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BayesFilter\n\nBayesFilter is a Python library for Bayesian filtering and smoothing. This library provides tools for implementing Bayesian filters, Rauch-Tung-Striebel smoothers, and other related methods. The only dependency is NumPy.\n\n## Installation\n\nTo install BayesFilter, just use `pip`:\n\n```bash\npip install bayesfilter\n```\n\n## Usage\n\n### Basic Structure\n\nThe library consists of several modules, each responsible for different parts of the Bayesian filtering and smoothing process:\n\n- `distributions.py`: Defines the distribution classes, including the Gaussian distribution used for the filters.\n- `filtering.py`: Implements the BayesianFilter class, which runs the filtering process.\n- `model.py`: Contains the StateTransitionModel class for state transitions.\n- `observation.py`: Defines the Observation class for observation models.\n- `smoothing.py`: Implements the RTS (Rauch-Tung-Striebel) smoother.\n- `unscented.py`: Provides functions for the unscented transform.\n- `utilities.py`: Contains utility functions used throughout the library.\n- `test_filtering_smoothing.py`: Contains tests for filtering and smoothing.\n\n### Example\n\nHere is a basic example of how to set up and run a Bayesian filter with the provided library:\n\n1. **Setup Functions**:\n\n```python\ndef setup_functions():\n    def transition_func(x, delta_t_s):\n        return np.array([x[0]])\n    \n    def transition_jacobian_func(x, delta_t_s):\n        return np.array([[1.0]])\n\n    def observation_func(x):\n        return np.array([np.sin(x[0]), np.cos(x[0])])\n    \n    def observation_jacobian_func(x):\n        return np.array([[np.cos(x[0])], [-np.sin(x[0])]])\n    \n    return transition_func, transition_jacobian_func, observation_func, observation_jacobian_func\n```\n\n2. **Setup Filter and Observations**:\n\n```python\ndef setup_filter_and_observations():\n    rng = np.random.default_rng(0)\n    transition_func, transition_jacobian_func, observation_func, observation_jacobian_func = setup_functions()\n\n    transition_model = StateTransitionModel(\n        transition_func, \n        1e-8*np.eye(1),\n        transition_jacobian_func\n    )\n    initial_state = Gaussian(np.array([0.0]), np.eye(1))\n    filter = BayesianFilter(transition_model, initial_state)\n\n    true_state = np.array([-0.1])\n    noise_std = 0.2\n    observations = []\n    for theta in np.linspace(0, 2*np.pi, 1000):\n        observation = observation_func(true_state) + rng.normal(0, noise_std, 2)\n        observations.append(Observation(observation, noise_std*np.eye(2), observation_func, observation_jacobian_func))\n    return filter, observations, true_state\n```\n\n3. **Run Filter**:\n\n```python\ndef test_filter_noisy_sin(use_jacobian=True):\n    filter, observations, true_state = setup_filter_and_observations()\n    filter.run(observations, np.linspace(0, 2*np.pi, 1000), 100.0, use_jacobian=use_jacobian)\n    np.testing.assert_allclose(filter.state.mean(), true_state, atol=1e-2)\n```\n\n### Tests\n\nThe library includes a set of tests to ensure the functionality of the filtering and smoothing algorithms. These can be run as follows:\n\n```bash\npython test_filtering_smoothing.py\n```\n\n## Documentation\n\n### `distributions.py`\n\nDefines the Gaussian distribution class used for state representation and propagation.\n\n### `filtering.py`\n\nImplements the `BayesianFilter` class, responsible for running the filtering process with predict and update steps.\n\n### `model.py`\n\nContains the `StateTransitionModel` class, representing the state transition model.\n\n### `observation.py`\n\nDefines the `Observation` class, representing the observation model.\n\n### `smoothing.py`\n\nImplements the `RTS` class for Rauch-Tung-Striebel smoothing.\n\n### `unscented.py`\n\nProvides functions for the unscented transform, including `unscented_transform` and `propagate_gaussian`.\n\n### `utilities.py`\n\nContains utility functions like `propagate_covariance`.\n\n### `test_filtering_smoothing.py`\n\nIncludes tests for filtering and smoothing to validate the implementation.\n\n## Author\n\nHugo Hadfield\n\n## License\n\nThis project is licensed under the MIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugohadfield%2Fbayesfilter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhugohadfield%2Fbayesfilter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugohadfield%2Fbayesfilter/lists"}