jgbrasier / KFEstimate.jl

Julia package for KF and EKF parameter estimation using Automatic Differentiation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Julia package for KF and EKF parameter estimation using Automatic Differentiation

License:MIT License


Languages

Language:Julia 100.0%