Skip to content

Commit f4ddd71

Browse files
committed
gitHub #223 Improved docstring
Added to the docstring to addess confusions for people coming from alternative terminology/formulations.
1 parent 12f6598 commit f4ddd71

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

filterpy/kalman/kalman_filter.py

+20-25
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ class KalmanFilter(object):
161161
Here is a filter that tracks position and velocity using a sensor that only
162162
reads position.
163163
164-
First construct the object with the required dimensionality.
164+
First construct the object with the required dimensionality. Here the state
165+
(`dim_x`) has 2 coefficients (position and velocity), and the measurement
166+
(`dim_z`) has one. In FilterPy `x` is the state, `z` is the measurement.
165167
166168
.. code::
167169
@@ -191,28 +193,20 @@ class KalmanFilter(object):
191193
f.F = np.array([[1.,1.],
192194
[0.,1.]])
193195
194-
Define the measurement function:
196+
Define the measurement function. Here we need to convert a position-velocity
197+
vector into just a position vector, so we use:
195198
196199
.. code::
197200
198-
f.H = np.array([[1.,0.]])
201+
f.H = np.array([[1., 0.]])
199202
200-
Define the covariance matrix. Here I take advantage of the fact that
201-
P already contains np.eye(dim_x), and just multiply by the uncertainty:
202-
203-
.. code::
204-
205-
f.P *= 1000.
206-
207-
I could have written:
203+
Define the state's covariance matrix P.
208204
209205
.. code::
210206
211207
f.P = np.array([[1000., 0.],
212208
[ 0., 1000.] ])
213209
214-
You decide which is more readable and understandable.
215-
216210
Now assign the measurement noise. Here the dimension is 1x1, so I can
217211
use a scalar
218212
@@ -226,7 +220,7 @@ class KalmanFilter(object):
226220
227221
f.R = np.array([[5.]])
228222
229-
Note that this must be a 2 dimensional array, as must all the matrices.
223+
Note that this must be a 2 dimensional array.
230224
231225
Finally, I will assign the process noise. Here I will take advantage of
232226
another FilterPy library function:
@@ -239,15 +233,14 @@ class KalmanFilter(object):
239233
240234
Now just perform the standard predict/update loop:
241235
242-
while some_condition_is_true:
243-
244236
.. code::
245237
246-
z = get_sensor_reading()
247-
f.predict()
248-
f.update(z)
238+
while some_condition_is_true:
239+
z = get_sensor_reading()
240+
f.predict()
241+
f.update(z)
249242
250-
do_something_with_estimate (f.x)
243+
do_something_with_estimate (f.x)
251244
252245
253246
**Procedural Form**
@@ -309,7 +302,7 @@ class KalmanFilter(object):
309302
310303
x_prior : numpy.array(dim_x, 1)
311304
Prior (predicted) state estimate. The *_prior and *_post attributes
312-
are for convienence; they store the prior and posterior of the
305+
are for convenience; they store the prior and posterior of the
313306
current epoch. Read Only.
314307
315308
P_prior : numpy.array(dim_x, dim_x)
@@ -325,16 +318,18 @@ class KalmanFilter(object):
325318
Last measurement used in update(). Read only.
326319
327320
R : numpy.array(dim_z, dim_z)
328-
Measurement noise matrix
321+
Measurement noise covariance matrix. Also known as the
322+
observation covariance.
329323
330324
Q : numpy.array(dim_x, dim_x)
331-
Process noise matrix
325+
Process noise covariance matrix. Also known as the transition
326+
covariance.
332327
333328
F : numpy.array()
334-
State Transition matrix
329+
State Transition matrix. Also known as `A` in some formulation.
335330
336331
H : numpy.array(dim_z, dim_x)
337-
Measurement function
332+
Measurement function. Also known as the observation matrix, or as `C`.
338333
339334
y : numpy.array
340335
Residual of the update step. Read only.

0 commit comments

Comments
 (0)