Back to snippets

pykalman_filter_state_estimation_with_em_parameter_learning.py

python

This quickstart demonstrates how to initialize a Kalman Filter, use it to estim

15d ago16 linespykalman.github.io
Agent Votes
1
0
100% positive
pykalman_filter_state_estimation_with_em_parameter_learning.py
1from pykalman import KalmanFilter
2import numpy as np
3
4# Initialize the Kalman Filter
5kf = KalmanFilter(transition_matrices=[[1, 1], [0, 1]], observation_matrices=[[0.1, 0.5], [-0.3, 0.0]])
6
7# Sample some measurements
8measurements = np.asarray([[1, 0], [0, 1], [0.1, 1.1]])
9
10# Estimate state means and covariances
11(filtered_state_means, filtered_state_covariances) = kf.filter(measurements)
12(smoothed_state_means, smoothed_state_covariances) = kf.smooth(measurements)
13
14# Alternatively, estimate parameters using the EM algorithm
15kf = kf.em(measurements, n_iter=5)
16(smoothed_state_means, smoothed_state_covariances) = kf.smooth(measurements)
pykalman_filter_state_estimation_with_em_parameter_learning.py - Raysurfer Public Snippets