Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented wrapper for KalmanFilters.jl SRKF #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

THargreaves
Copy link
Collaborator

A simple wrapper for the square-root Kalman filter from KalmanFilters.jl. Still a bit of a draft and lacking documentation. Will add when implementation details sorted out.

They implemented their algorithm in a very modular way so it was a breeze to write the wrapper. They also look pretty memory efficient and rely on low-level LAPACK operations so should be speedy. They also implement the Unscented KF but not the extended.

They do not compute the incremental marginal log-likelihood but this is easy since they return the innovation mean and covariance (the likelihood is the density of a Gaussian with these parameters at zero).

The one sticking point is that the QR decomposition they use for updating does not enforce positive diagonals for R so that this is not a valid Cholesky decomposition and logpdf(MvNormal(...), ...) fails. I have a hacky manual computation of the log density to handle this case for now but I've raised an issue here JuliaGNSS/KalmanFilters.jl#16.

There are still some minor performance improvements that could be made either in this repo or in the original depending on their needs. Specifically, it is not necessary to compute the Kalman gain since we have

x_post = x_pred - (Ksqrt(Y)) * inv(sqrt(Y)) * y_tilde

And Ksqrt(Y) and sqrt(Y) are contained in the QR decomposition output. Maybe there is a need for compute K directly though?

There are also algorithms for updating (x, P) as well as doing a joint time+measurement update that avoids a second QR decomposition—but that feels like an issue for way down the line. These algorithms should also be amenable to the GPU using batch LUs from CuSolver.

yebai added a commit that referenced this pull request Mar 4, 2025
* Initial commit

* Readme

* Project

* Prototype design.  (#2)

* prototype

* Update SSMProblems.jl

* add logM (#3)

* Convert example into docstring.

* Move `logM`.

---------

Co-authored-by: FredericWantiez <[email protected]>

* export

* example

* Fred/ancestor (#5)

* Gibbs

* Add ancestor resampling

* Better names

* Clean up package (#6)

* Gibbs

* Setup github

* Update Readme

* Docs

* GH actions

* Format

* Upgrade node

* Use GH token

* Fix links

* Clean up

* Write a proper example implementation (#7)

* SMC

* remove old file

* Fix types

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Some minor changes (#8)

* use recommended style for interface methods

* minor changes to example

* Update smc.jl

* Update smc.jl

---------

Co-authored-by: Hong Ge <[email protected]>

* Particle filter example bug fix and refactoring (#10)

* fix: corrected observation generation for
particle filter example

* refactor: tidied particle filter example code

- Removed recursive particle show method which flooded REPL
- Removed redundant resampling logic
- Replaced variance with std in Normal() calls
- Tidied final scatter plot

* Updated formatting for named argument

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: corrected flipped noise standard deviations

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Fix format action (#13)

* Fix docs action (#12)

* Fix docs action

* Add DOCUMENTER_KEY

* Use julia-docdeploy action

* Show link to docs preview (#15)

* Update documentation (#16)

* Add details to doc

* Fix source

* Typo

* Update SSM Interface

* Fix linearize bug

* Interface

* Format

* Trying things

* Fix transition!!

* Format

* Fix doc

* Helper

* Format

* Forget about particles

* Optional timestep

* Add utils

* Apply suggestions from code review

Co-authored-by: David Widmann <[email protected]>

* Utils module

---------

Co-authored-by: David Widmann <[email protected]>

* Update README.md (#17)

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update index.md

* Update documentation to match new interface (#18)

* Update documentation to match new interface

* Update index.md

---------

Co-authored-by: Hong Ge <[email protected]>

* Build examples with doc (#19)

* Build examples with doc

* Reduce size of plot

* Colors

* Size option

* Increase size per page

* Update README.md

* Update Project.toml

* Modify SSMProblems to work with AbstractMCMC interface (#22)

* Update documentation to match new interface

* Incorporate SSMProblems into AbstractMCMC

* Update Project.toml (#24)

* Update Project.toml

* Update make.jl

---------

Co-authored-by: Hong Ge <[email protected]>

* Add Kalman filter example (#26)

* Add Kalman filter example

* Fix formatting issues

* Add literate for docs

* add missing deps

* Comments for literate

* Format

* Use `Gaussian` (#28)

* Format, use `Gaussian`

* Fix the maths

* Format

* Tweaks

* Update script.jl

* Update script.jl

---------

Co-authored-by: Hong Ge <[email protected]>

* Update Project.toml

---------

Co-authored-by: FredericWantiez <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: Hong Ge <[email protected]>

* Update script.jl

* Update script.jl

* Create DocsNav.yml

* Add example script for PMMH (#37)

* Add example script for PMMH

* Add Literate.jl

* Update script.jl

* Update script.jl

* Update DocsNav.yml

* Update SSMProblems.jl interface (#38)

* Add split dynamics/observation interface with "extra" variables

* Add utilities for forward simulation and distribution definitions

* Removed redundant particle container code

* Update naming convention for initialisation log-density

Co-authored-by: Hong Ge <[email protected]>

* Update initialisation naming

Co-authored-by: Hong Ge <[email protected]>

* Update naming convention

Co-authored-by: Hong Ge <[email protected]>

* Change sampler to AbstractMCMC

Co-authored-by: Hong Ge <[email protected]>

* Add section heading for SSM

Co-authored-by: Hong Ge <[email protected]>

* Remove redundant method check

* Correct dependencies

* Revert to positional arguments

* Correct forward simulation element type

* Update Kalman filter example to new interface

* Fix formatting issue

* Add missing import

Co-authored-by: Charles Knipp <[email protected]>

* Add default rngs to samplers through macro

* Remove unnecessary section heading

* Add missing dependency

* Tidied Kalman filter example

* Update documentation main page

* Fully document Kalman filter example

* Remove outdated examples

* Add documentation for extra argument

* Apply suggestions from code review

* Update script.jl

* Update examples/kalman-filter/script.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update script.jl

* Remove PMMH (until new API)

* Remove ref to 'Utils'

* Fix broken link

* Remove default RNG macro

* Simplify interface methods

* Correct old function names

* Add parametric type to Kalman filter

* Update main doc page

* Update README

* Make parameter order consistent

---------

Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: Charles Knipp <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: FredericWantiez <[email protected]>

* Minor tweaks and typo fixes  (#41)

* Update index.md

* Update index.md

* Update Project.toml

* Suppress output in example script

---------

Co-authored-by: THargreaves <[email protected]>

* Split method definitions to avoid docstring overwriting (#42)

* Function docstring formatting (#45)

* added TagBot & CompatHelper workflows (#47)

* added TagBot & CompatHelper workflows

* using existing Documenter Key for CompatHelper

* CompatHelper: add new compat entry for Distributions at version 0.25, (keep existing compat) (#48)

Co-authored-by: CompatHelper Julia <[email protected]>

* Update DocsPreviewCleanup.yml

* TagBot Permission Issue fixed (#50)

* Add DOCUMENTER_KEY to Docs workflow (#52)

* Update DocsPreviewCleanup.yml

* Correct type signature for forward simulation method

* Alignment of obs/dyn time steps and refactored forward simulation (#55)

* Update interface documentation to align dyn/obs time steps

* Refactor forward simulation, add type parameters, add unit test

* Add type parameters to docstrings

* Update kalman example

* Add extra for initialisation and simplify obs type parameter

* Bump minor version

* Update unit tests to match aligned interface

* Fix code comment rendering

* Interface Changes for Use in Filtering (#56)

* added basic particle methods and filters

* added qualifiers

* added parameter priors

* added adaptive resampling to bootstrap filter (WIP)

* Julia fomatter changes

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* changed eltype for <: StateSpaceModel

* updated naming conventions

* formatter

* fixed adaptive resampling

* added particle ancestry

* formatter issues

* fixed metropolis and added rejection resampler

* Keep track of free indices using stack

* updated particle types and organized directory

* weakened SSM type parameter assertions

* improved particle state containment and resampling

* added hacky sparse ancestry to example

* fixed RNG in rejection resampling

* improved callbacks and resamplers

* formatting

* added conditional SMC

* improved linear model type structure

* formatter

* replaced extra with kwargs

* formatter

* migrated filtering code

* Add unittests for new interface

* Update documentation to match kwargs

* Rename extras/kwargs docs file

* remove redundant forward simulations

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tim Hargreaves <[email protected]>

* Bump 0.4.0 (#58)

* Update docs to match kwargs interface

* Add method definitions for batch simulation/log-densities

* Bump minor version

* Correct docstring overwriting for batch methods

* Update type parameters to contain both arithmetic and element type

* Correct docstring indentations

* Correct RBPF forward simulation

* Documentation and Turing Navigation CI improvement (#61)

* Update Docs.yml

* Update DocsNav.yml

* No need of deploydocs() after using new Docs & DocsNav workflows

* Remove research files from repository

* removed SSMProblems README, LICENSE, GHA workflow, JULIAFORMATTER in favor of merger

* SSMProblems: added missing docstring to avoid documentation failure

* added pkg_path in Docs workflow to fix package development

---------

Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: FredericWantiez <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tor Erlend Fjelde <[email protected]>
Co-authored-by: Tim Hargreaves <[email protected]>
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: Charles Knipp <[email protected]>
Co-authored-by: THargreaves <[email protected]>
Co-authored-by: Will Tebbutt <[email protected]>
Co-authored-by: CompatHelper Julia <[email protected]>
Co-authored-by: Penelope Yong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant