Giter VIP home page Giter VIP logo

jgbrasier / kfestimate.jl Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 871 KB

Julia package for KF and EKF parameter estimation using Automatic Differentiation

License: MIT License

Julia 100.00%
state-space-model hidden-markov-models gaussian-processes gaussian-filter kalman-filter kalman-filtering parameter-estimation em-algorithm gradient-descent machine-learning julia package automatic-differentiation

kfestimate.jl's Introduction

KFEstimate.jl

KFEstimate is a Julia package for parameter estimation in linear and non linear state space models, using automatic differentiation. This is achieved by using stochastic gradient descent on a standard energy log-likelihood to compute a maximum a-priori (MAP) estimate of the model parameters

It is developped by Jean-Guillaume Brasier at Inria Paris in the DYOGENE team.

pkg> add https://github.com/jgbrasier/KFEstimate.jl

Parametrised State Space Models (PSSM)

If you are unfamiliar with Kalman Filtering see: Kalman Filters

This package supports standard KF and EKF filtering as well their parametrised version.

Parameter Estimation

Traditional parameter estimation in SSMs is done using MCMC methods or EM Algorithms.

Our gradient based approach consists of computing the log-likelihood of our posterior estimation and then minimizing it using stochastic gradient descent.

At each epoch e:

  • filter measured states using classical KF or EKF algorithms, with current parameters θ.
  • compute the gradient ∇ of the pre-fit residual likelihood ℒ.
  • update the parameters θ.

Automatic Differentiation (AD)

Often, manually calculating the gradient ∇ of the log-likelihood ℒ is intractable. However it is easily computed using standard AD libraries. In our case we use Zygote as it is readily implemented in Flux.

Quick Start

  • The package works with the States structure which encapsulates both the mean x and covariance P of a state
s = State(x::AbstractVector, P::AbstractMatrix)
  • Setting up a Kalman Filter:
kf = KalmanFilter(A, B, Q, H, R)

here A, B, H, Q, R are all of type AbstractMatrix

  • The package supports simulating measurements for a given action sequence (input vector), with initial estimate x0.
sim_states, sim_measurements = run_simulation(filter::AbstractFilter, x0::AbstractVector, action_seq::AbstractArray)
  • Classical KF filtering:
filtered_states = run_filter(filter::AbstractFilter, s0::State, action_history::AbstractArray,
    measurement_history::AbstractArray)
  • Setting up a Parametrised Kalman Filter
param_kf = ParamKalmanFilter(A, B, Q, H, R)

A, B, H, Q, R must all be functions with input θ. See /examples/linear.jl

  • Running gradient descent on unknown parameters θ for a given number of epochs:
θ, loss = run_kf_gradient(θ, param_kf::ParamKalmanFilter, s0::State, action_history::AbstractArray, measurement_history::AbstractArray,
    opt, epochs)

The package handily integrates Flux Optimisers.

Idem for non-linear functions and Extended Kalman Filtering.

Examples

Linear

Parameter estimation for a classical dynamic model with control input where process matrix A is unknown: example/linear.jl

A matrix estimate

Non linear

Parameter estimation for a non linear pendulum model with no control input where coefficients (g/L) of state space process are unknown: example/non_linear.jl

g/l estimate

kfestimate.jl's People

Contributors

jgbrasier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

mfkiwl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.