filterpy
This file contains modified methods and classes taken from the filterpy library.
Copyright 2015 Roger R Labbe Jr.
FilterPy library. http://github.com/rlabbe/filterpy
Documentation at: https://filterpy.readthedocs.org
Supporting book at: https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python
This is licensed under an MIT license. See the readme.MD file for more information.
Q_discrete_white_noise(dim, dt=1.0, var=1.0, block_size=1, order_by_dim=True)
¶
Create the discrete white noise covariance for a constant derivative model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
int
|
The number of derivatives, 2, 3, or 4, e.g., 2 for position and velocity. |
required |
dt
|
float
|
The time step. |
1.0
|
var
|
float
|
The variance of the white noise. |
1.0
|
block_size
|
int
|
The number of dimensions, e.g., 3 for x, y, z. |
1
|
order_by_dim
|
bool
|
If the matrix is ordered by dimension, else by derivative. |
True
|
Returns:
| Type | Description |
|---|---|
Array
|
The noise covariance of shape (dim * block_size, dim * block_size). |
Source code in drone_estimators/filterpy.py
ekf_correct(data, settings, mask=None)
¶
Correct the state with the measurement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
EstimatorData
|
The predicted state of the estimator, including the measurement. |
required |
settings
|
EKFSettings
|
The filter settings. |
required |
mask
|
Array | None
|
Optional, only batch elements where mask is True are updated. |
None
|
Returns:
| Type | Description |
|---|---|
EstimatorData
|
The corrected state. |
Source code in drone_estimators/filterpy.py
ekf_predict(data, settings, mask=None)
¶
Predict the state and covariance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
EstimatorData
|
The current state of the estimator, including the input and the time step. |
required |
settings
|
EKFSettings
|
The filter settings. |
required |
mask
|
Array | None
|
Optional, only batch elements where mask is True are updated. |
None
|
Returns:
| Type | Description |
|---|---|
EstimatorData
|
The predicted state. |
Source code in drone_estimators/filterpy.py
ekf_predict_correct(data, settings, mask=None)
¶
Predict and correct the state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
EstimatorData
|
The current state of the estimator, including the input and the measurement. |
required |
settings
|
EKFSettings
|
The filter settings. |
required |
mask
|
Array | None
|
Optional, only batch elements where mask is True are updated. |
None
|
Returns:
| Type | Description |
|---|---|
EstimatorData
|
The corrected state. |
Source code in drone_estimators/filterpy.py
order_by_derivative(Q, dim, block_size)
¶
Reorder a block diagonal noise matrix from being ordered by dimension to by derivative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Array
|
The noise matrix of one dimension, of shape (dim, dim). |
required |
dim
|
int
|
The number of derivatives in Q. |
required |
block_size
|
int
|
The number of dimensions, e.g., 3 for x, y, z. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The reordered noise matrix of shape (dim * block_size, dim * block_size). |
Source code in drone_estimators/filterpy.py
ukf_calculate_sigma_points(data, settings)
¶
Compute the sigma points of the state with the Van der Merwe scaling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
EstimatorData
|
The current state of the estimator. |
required |
settings
|
UKFSettings
|
The filter settings, including the sigma point parameters. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The 2n+1 sigma points, stacked along the second to last axis. |
Source code in drone_estimators/filterpy.py
ukf_correct(data, settings, mask=None)
¶
Correct the state with the measurement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
EstimatorData
|
The predicted state of the estimator, including the measurement. |
required |
settings
|
UKFSettings
|
The filter settings. |
required |
mask
|
Array | None
|
Optional, only batch elements where mask is True are updated. |
None
|
Returns:
| Type | Description |
|---|---|
EstimatorData
|
The corrected state. |
Source code in drone_estimators/filterpy.py
ukf_cross_variance(x, z, sigmas_f, sigmas_h, Wc)
¶
Compute cross variance of the state x and measurement z.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
The mean of the state sigma points. |
required |
z
|
Array
|
The mean of the measurement sigma points. |
required |
sigmas_f
|
Array
|
The state sigma points. |
required |
sigmas_h
|
Array
|
The measurement sigma points. |
required |
Wc
|
Array
|
The weights for the covariance. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The cross variance of shape (dim_x, dim_z). |
Source code in drone_estimators/filterpy.py
ukf_predict(data, settings, mask=None)
¶
Predict the state and covariance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
EstimatorData
|
The current state of the estimator, including the input and the time step. |
required |
settings
|
UKFSettings
|
The filter settings. |
required |
mask
|
Array | None
|
Optional, only batch elements where mask is True are updated. |
None
|
Returns:
| Type | Description |
|---|---|
EstimatorData
|
The predicted state. |
Source code in drone_estimators/filterpy.py
ukf_predict_correct(data, settings, mask=None)
¶
Predict and correct the state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
EstimatorData
|
The current state of the estimator, including the input and the measurement. |
required |
settings
|
UKFSettings
|
The filter settings. |
required |
mask
|
Array | None
|
Optional, only batch elements where mask is True are updated. |
None
|
Returns:
| Type | Description |
|---|---|
EstimatorData
|
The corrected state. |
Source code in drone_estimators/filterpy.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
ukf_unscented_transform(sigmas, Wm, Wc, noise_cov=None)
¶
Compute the mean and covariance of the sigma points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigmas
|
Array
|
The sigma points, stacked along the second to last axis. |
required |
Wm
|
Array
|
The weights for the mean. |
required |
Wc
|
Array
|
The weights for the covariance. |
required |
noise_cov
|
Array
|
Optional, noise covariance that is added to the result. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Array, Array]
|
The mean and covariance. |