Kalman Filter
Kalman filter and smoother implementation in JAX.
Provides the KalmanFilter class — the primary interface used by the SIMPL
E-step — as well as lower-level JIT-compiled helper functions for prediction,
update, filtering, smoothing, and parameter fitting.
The Kalman dynamics are:
where \(q_t \sim \mathcal{N}(0, Q)\) and \(r_t \sim \mathcal{N}(0, R)\).
- Filtering estimates the causal posterior \(P(z_t \mid y_{1:t})\).
- Smoothing refines this to the full posterior \(P(z_t \mid y_{1:T})\) using all observations.
For 1-D angular state spaces (is_1D_angular=True), the filter and smoother
wrap \(\mu\) to \([-\pi, \pi)\) after every predict, update, and
smooth step.
The lower-level functions (prefixed with _) mirror KalmanFilter
methods and are not intended for direct use.
KalmanFilter
A Kalman filter class. This class is used to filter the data and fit the model.
Written in jax, the lower level functions are jit compiled for speed. The filtering and smoothing loops are processed in batches using jax.lax.scan(): higher batch sizes will run faster but at the cost of a one-off compilation time.
The Kalman dynamics equations are as follows:
where \(z_t\) is the hidden state, \(y_t\) is the observation, \(u_t\) is the control input, \(F\) is the state transition matrix, \(B\) is the control matrix, \(H\) is the observation matrix, \(q_t \sim \mathcal{N}(0, Q)\) is the state transition noise, and \(r_t \sim \mathcal{N}(0, R)\) is the observation noise.
Kalman filtering takes observations and estimates the causal posterior distribution of the hidden state given the observations. Kalman smoothing takes the filtered estimates and estimates the posterior distribution of the hidden state given all the observations.
\(\mu_{\textrm{filter},t} = \mathbb{E}[z_t \mid y_{1:t}, u_{1:t}]\), \(\Sigma_{\textrm{filter},t} = \textrm{Cov}[z_t \mid y_{1:t}, u_{1:t}]\)
\(\mu_{\textrm{smooth},t} = \mathbb{E}[z_t \mid y_{1:T}, u_{1:T}]\), \(\Sigma_{\textrm{smooth},t} = \textrm{Cov}[z_t \mid y_{1:T}, u_{1:T}]\)
Multi-trial support
Both filter() and smooth() support processing multiple
concatenated trials in a single pass. Trial boundaries are specified via
boolean arrays (is_boundary / is_trial_end) that mark where one
trial ends and the next begins. At these points the filter state is reset
to per-trial initial conditions (mu0_all, sigma0_all), and the
smoother treats each trial independently by resetting its backward carry
to the filtered terminal state. This avoids a Python-level loop over
trials and keeps the full computation inside a single jax.lax.scan.
Source code in src/simpl/kalman.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
_to_cpu(x)
staticmethod
Move a JAX array to CPU.
Source code in src/simpl/kalman.py
210 211 212 213 214 215 | |
_to_device(x, device)
staticmethod
Move a JAX array to the given device.
Source code in src/simpl/kalman.py
217 218 219 220 221 222 | |
filter(Y, U=None, mu0=None, sigma0=None, F=None, B=None, Q=None, H=None, R=None, is_boundary=None, mu0_all=None, sigma0_all=None)
Run the Kalman filter, optionally over multiple concatenated trials.
If parameters are not passed in, the class defaults are used.
If they are passed in, they must have shape
(T, *param_shape) where T is the number of time steps — this
allows for time-varying parameters.
For multi-trial data, pass is_boundary, mu0_all, and
sigma0_all. At every timestep where is_boundary[t] is True
the filter carry is reset to (mu0_all[t], sigma0_all[t]) before
the predict/update step, so each trial is filtered independently
within a single jax.lax.scan pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Y
|
(Array, shape(T, dim_Y))
|
The observation means. |
required |
U
|
(Array, shape(T, dim_U))
|
The control inputs (defaults to zeros if not provided). |
None
|
mu0
|
(Array, shape(dim_Z))
|
The initial state mean (default is provided at initialisation). |
None
|
sigma0
|
(Array, shape(dim_Z, dim_Z))
|
The initial state covariance (default is provided at initialisation). |
None
|
F
|
(Array, shape(T, dim_Z, dim_Z))
|
The state transition matrix (default is provided at initialisation). |
None
|
B
|
(Array, shape(T, dim_Z, dim_U))
|
The control matrix (default is provided at initialisation). |
None
|
Q
|
(Array, shape(T, dim_Z, dim_Z))
|
The state transition noise covariance (default is provided at initialisation). |
None
|
H
|
(Array, shape(T, dim_Y, dim_Z))
|
The observation matrix (default is provided at initialisation). |
None
|
R
|
(Array, shape(T, dim_Y, dim_Y))
|
The observation noise covariances (default is provided at initialisation). |
None
|
is_boundary
|
(Array, shape(T))
|
Boolean array. True at the first timestep of each trial. The filter
state is reset to |
None
|
mu0_all
|
(Array, shape(T, dim_Z))
|
Per-timestep initial means (only read where |
None
|
sigma0_all
|
(Array, shape(T, dim_Z, dim_Z))
|
Per-timestep initial covariances (only read where |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
mus_f |
(Array, shape(T, dim_Z))
|
The filtered means. |
sigmas_f |
(Array, shape(T, dim_Z, dim_Z))
|
The filtered covariances. |
Source code in src/simpl/kalman.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
smooth(mus_f, sigmas_f, U=None, F=None, B=None, Q=None, is_trial_end=None)
Run the Rauch-Tung-Striebel smoother, optionally over multiple concatenated trials.
For multi-trial data, pass is_trial_end. At every timestep where
is_trial_end[t] is True the smoothed output is set to the filtered
value (terminal condition) and the backward carry is reset, so each
trial is smoothed independently within a single backward
jax.lax.scan pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mus_f
|
(Array, shape(T, dim_Z))
|
The filtered means. |
required |
sigmas_f
|
(Array, shape(T, dim_Z, dim_Z))
|
The filtered covariances. |
required |
U
|
(Array, shape(T, dim_U))
|
The control inputs (defaults to zeros if not provided). |
None
|
F
|
(Array, shape(T, dim_Z, dim_Z))
|
The state transition matrix. |
None
|
B
|
(Array, shape(T, dim_Z, dim_U))
|
The control matrix. |
None
|
Q
|
(Array, shape(T, dim_Z, dim_Z))
|
The state transition noise covariance. |
None
|
is_trial_end
|
(Array, shape(T))
|
Boolean array. True at the last timestep of each trial. At these points the smoothed state is set to the filtered state (terminal condition) and the carry is reset for the next trial's backward pass. If None, only the final timestep is treated as a trial end (single-trial behaviour). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
mus_s |
(Array, shape(T, dim_Z))
|
The smoothed means. |
sigmas_s |
(Array, shape(T, dim_Z, dim_Z))
|
The smoothed covariances. |
Source code in src/simpl/kalman.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
loglikelihood(Y, mu, sigma, H=None, R=None)
Calculates the log-likelihood of the observations, Y.
Marginalises over the hidden state [mu, sigma] (filtered or smoothed). This can be done analytically (see page 361 of the Advanced Murphy book).
\(P(Y) = \mathcal{N}(Y \mid \hat{Y}, S)\) where \(S = H \Sigma H^\top + R\) (the posterior observation covariance combined with the observation noise covariance) and \(\hat{Y} = H \mu\) (the predicted observation).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Y
|
(Array, shape(T, dim_Y))
|
The observation means |
required |
mu
|
(Array, shape(T, dim_Z))
|
The posterior state means |
required |
sigma
|
(Array, shape(T, dim_Z, dim_Z))
|
The posterior state covariances |
required |
H
|
Array | None
|
The observation matrix, optional |
None
|
R
|
(Array, shape(T, dim_Y, dim_Y))
|
The observation noise covariances, optional |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
logP |
(Array, shape(T))
|
The log-likelihood of the data given the model |
Source code in src/simpl/kalman.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
_kalman_filter(Y, U, mu0, sigma0, F, B, Q, H, R, is_1D_angular=None, is_boundary=None, mu0_all=None, sigma0_all=None)
Kalman filters a batch of observation data, Y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Y
|
(Array, shape(T, dim_Y))
|
The observation means |
required |
U
|
(Array, shape(T, dim_U))
|
The control inputs |
required |
mu0
|
(Array, shape(dim_Z))
|
The initial state mean |
required |
sigma0
|
(Array, shape(dim_Z, dim_Z))
|
The initial state covariance |
required |
F
|
(Array, shape(T, dim_Z, dim_Z))
|
The state transition matrix |
required |
B
|
(Array, shape(T, dim_Z, dim_U))
|
The control matrix |
required |
Q
|
(Array, shape(T, dim_Z, dim_Z))
|
The state transition noise covariance |
required |
H
|
(Array, shape(T, dim_Y, dim_Z))
|
The observation matrix |
required |
R
|
(Array, shape(T, dim_Y, dim_Y))
|
The observation noise covariances |
required |
is_1D_angular
|
Array
|
Scalar bool. If True, wrap mu to [-pi, pi) after predict and update steps and wrap the innovation for angular data. By default False. |
None
|
is_boundary
|
(Array, shape(T))
|
Boolean array. True at the first timestep of each trial. When True, the
filter state is reset to |
None
|
mu0_all
|
(Array, shape(T, dim_Z))
|
Per-timestep initial means (only used where |
None
|
sigma0_all
|
(Array, shape(T, dim_Z, dim_Z))
|
Per-timestep initial covariances (only used where |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
mu |
(Array, shape(T, dim_Z))
|
The filtered posterior state means |
sigma |
(Array, shape(T, dim_Z, dim_Z))
|
The filtered posterior state covariances |
Source code in src/simpl/kalman.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | |
_kalman_smoother(mu, sigma, U, muT, sigmaT, F, B, Q, is_1D_angular=None, is_trial_end=None)
Runs the Kalman smoother on the data.
mu and sigma are in forward order, ie. mu = [mu[0], mu[1], ... mu[T]] and they are looped over in reverse order, so you can still batch the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
(Array, shape(T, dim_Z))
|
The filtered posterior state means |
required |
sigma
|
(Array, shape(T, dim_Z, dim_Z))
|
The filtered posterior state covariances |
required |
U
|
(Array, shape(T, dim_U))
|
The control inputs |
required |
muT
|
(Array, shape(dim_Z))
|
The final state mean - by definition this should have already been smoothed |
required |
sigmaT
|
(Array, shape(dim_Z, dim_Z))
|
The final state covariance - by definition this should have already been smoothed |
required |
F
|
(Array, shape(T, dim_Z, dim_Z))
|
The state transition matrix |
required |
B
|
(Array, shape(T, dim_Z, dim_U))
|
The control matrix |
required |
Q
|
(Array, shape(T, dim_Z, dim_Z))
|
The state transition noise covariance |
required |
is_1D_angular
|
Array
|
Scalar bool. If True, wrap mu and angular differences to [-pi, pi) during smoothing. By default False. |
None
|
is_trial_end
|
(Array, shape(T))
|
Boolean array. True at the last timestep of each trial. At these points the smoothed state is set to the filtered state (terminal condition) and the carry is reset for the next trial's backward pass. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
mu_smooth |
(Array, shape(T, dim_Z))
|
The smoothed state means |
sigma_smooth |
(Array, shape(T, dim_Z, dim_Z))
|
The smoothed state covariances |
Source code in src/simpl/kalman.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | |
_kalman_likelihoods(Z, Y, mu, sigma, F, Q, H, R, B=None, U=None)
Calculates the prior P(Z), likelihood P(Y | Z), and posterior P(Z | Y).
Evaluates any state trajectory (Z) and observations (Y, R) under the fitted kalman model. Note although Z and Y can, in principle, be any trajectory and observations, typically Z == mu and Y == the observations which were used to fit the model in the first place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
(Array, shape(T, dim_Z))
|
The trajectory of the agent (typical this might just be the same as mu) |
required |
Y
|
(Array, shape(T, dim_Y))
|
The observations to be evalauted |
required |
mu
|
(Array, shape(T, dim_Z))
|
The posterior state means |
required |
sigma
|
(Array, shape(T, dim_Z, dim_Z))
|
The posterior state covariances |
required |
F
|
(Array, shape(T, dim_Z, dim_Z))
|
The state transition matrix |
required |
Q
|
(Array, shape(T, dim_Z, dim_Z))
|
The state transition noise covariance |
required |
H
|
(Array, shape(T, dim_Y, dim_Z))
|
The observation matrix |
required |
R
|
(Array, shape(T, dim_Y, dim_Y))
|
The observation noise covariances |
required |
B
|
(Array, shape(T, dim_Z, dim_U))
|
The control matrix |
None
|
U
|
(Array, shape(T, dim_U))
|
The control inputs |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
PZ |
(Array, shape(T))
|
The likelihood of the state given the previous state |
PZXF |
(Array, shape(T))
|
The likelihood of the state given the observation |
PXZF |
(Array, shape(T))
|
The likelihood of the observation given the state |
Source code in src/simpl/kalman.py
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 | |
_kalman_predict(mu, sigma, F, Q, B, u)
Predicts the next state of the system given the current state and the state transition matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
(Array, shape(dim_Z))
|
The current state mean |
required |
sigma
|
(Array, shape(dim_Z, dim_Z))
|
The current state covariance |
required |
F
|
(Array, shape(dim_Z, dim_Z))
|
The state transition matrix |
required |
Q
|
(Array, shape(dim_Z, dim_Z))
|
The state transition noise covariance |
required |
B
|
(Array, shape(dim_Z, dim_U))
|
The control matrix |
required |
u
|
(Array, shape(dim_U))
|
The control input |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mu_next |
(Array, shape(dim_Z))
|
The predicted next state mean |
sigma_next |
(Array, shape(dim_Z, dim_Z))
|
The predicted next state covariance |
Source code in src/simpl/kalman.py
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |
_kalman_update(mu, sigma, H, R, y, is_1D_angular=None)
Updates the state estimate given an observation.
Innovation: \(v = y - H\mu\), Kalman gain: \(K = \Sigma H^\top S^{-1}\), Posterior: \(\mu_{\textrm{post}} = \mu + Kv\), \(\Sigma_{\textrm{post}} = (I - KH)\Sigma\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
(Array, shape(dim_Z))
|
The current state mean |
required |
sigma
|
(Array, shape(dim_Z, dim_Z))
|
The current state covariance |
required |
H
|
(Array, shape(dim_Y, dim_Z))
|
The observation matrix |
required |
R
|
(Array, shape(dim_Y, dim_Y))
|
The observation noise covariance |
required |
y
|
(Array, shape(dim_Y))
|
The state observation |
required |
is_1D_angular
|
Array
|
Scalar bool. If True, wrap the innovation (y - y_hat) to [-pi, pi) for angular data. By default False. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
mu_post |
(Array, shape(dim_Z))
|
The posterior state mean |
sigma_post |
(Array, shape(dim_Z, dim_Z))
|
The posterior state covariance |
Source code in src/simpl/kalman.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
_calculate_S_matrix(sigma, H, R)
Calculates the S matrix, \(S = H \Sigma H^\top + R\), for the Kalman filter.
This doesn't really need to be it's own function but it's useful for readability and I vmap it later.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
(Array, shape(dim_Z, dim_Z))
|
The state covariance |
required |
H
|
(Array, shape(dim_Y, dim_Z))
|
The observation matrix |
required |
R
|
(Array, shape(dim_Y, dim_Y))
|
The observation noise covariance |
required |
Returns:
| Name | Type | Description |
|---|---|---|
S |
(Array, shape(dim_Y, dim_Y))
|
The S matrix |
Source code in src/simpl/kalman.py
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |
_calculate_K_matrix(sigma, H, S)
Calculates the Kalman gain matrix, \(K = \Sigma H^\top S^{-1}\), for the Kalman filter.
This doesn't really need to be it's own function but it's useful for readability and I vmap it later.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
(Array, shape(dim_Z, dim_Z))
|
The state covariance |
required |
H
|
(Array, shape(dim_Y, dim_Z))
|
The observation matrix |
required |
S
|
(Array, shape(dim_Y, dim_Y))
|
The S matrix |
required |
Returns:
| Name | Type | Description |
|---|---|---|
K |
(Array, shape(dim_Z, dim_Y))
|
The K matrix |
Source code in src/simpl/kalman.py
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
_fit_parameters(Z, Y)
Fits the optimal stationary parameters of the Kalman filter.
Assuming a training set exists where hidden states Z and observations Y are known, this function returns those parameters that maximise the likelihood of the data and the state: \(\mathcal{L}(\Theta) = \log p(\{z\}, \{y\} \mid \Theta)\). These solutions are (relatively) easy to derive, I took them from Byron Yu's lecture notes (they look a lot like linear regression solutions):
NOTE: This function assumes NO control input (B=0). Fitting B would require U as an input and a different regression setup (e.g., regressing \(z_{t+1}\) on \([z_t, u_t]\)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
(Array, shape(T, dim_Z))
|
The hidden states (training data) |
required |
Y
|
(Array, shape(T, dim_Y))
|
The observations (training data) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mu0 |
(Array, shape(dim_Z))
|
The initial state mean |
sigma0 |
(Array, shape(dim_Z, dim_Z))
|
The initial state covariance |
F |
(Array, shape(dim_Z, dim_Z))
|
The state transition matrix |
Q |
(Array, shape(dim_Z, dim_Z))
|
The state transition noise covariance |
H |
(Array, shape(dim_Y, dim_Z))
|
The observation matrix |
R |
(Array, shape(dim_Y, dim_Y))
|
The observation noise covariance |
Source code in src/simpl/kalman.py
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 | |
_fit_mu0(Z)
Fits the initial state mean of the Kalman filter.
Assumes stationary dynamics, see _fit_parameters for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
(Array, shape(T, dim_Z))
|
The hidden states (training data) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mu0 |
(Array, shape(dim_Z))
|
The initial state mean |
Source code in src/simpl/kalman.py
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 | |
_fit_sigma0(Z)
Fits the initial state covariance of the Kalman filter.
Assumes stationary dynamics, see _fit_parameters for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
(Array, shape(T, dim_Z))
|
The hidden states (training data) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
sigma0 |
(Array, shape(dim_Z, dim_Z))
|
The initial state covariance |
Source code in src/simpl/kalman.py
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 | |
_fit_F(Z)
Fits the state transition matrix of the Kalman filter.
Assumes stationary dynamics and no control input, see
_fit_parameters for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
(Array, shape(T, dim_Z))
|
The hidden states (training data) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
F |
(Array, shape(dim_Z, dim_Z))
|
The state transition matrix |
Source code in src/simpl/kalman.py
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | |
_fit_Q(Z)
Fits the state transition noise covariance of the Kalman filter.
Assumes stationary dynamics and no control input, see
_fit_parameters for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
(Array, shape(T, dim_Z))
|
The hidden states (training data) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Q |
(Array, shape(dim_Z, dim_Z))
|
The state transition noise covariance |
Source code in src/simpl/kalman.py
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 | |
_fit_H(Z, Y)
Fits the observation matrix of the Kalman filter.
Assumes stationary dynamics, see _fit_parameters for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
(Array, shape(T, dim_Z))
|
The hidden states (training data) |
required |
Y
|
(Array, shape(T, dim_Y))
|
The observations (training data) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
H |
(Array, shape(dim_Y, dim_Z))
|
The observation matrix |
Source code in src/simpl/kalman.py
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 | |
_fit_R(Z, Y)
Fits the observation noise covariance of the Kalman filter.
Assumes stationary dynamics, see _fit_parameters for more details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
(Array, shape(T, dim_Z))
|
The hidden states (training data) |
required |
Y
|
(Array, shape(T, dim_Y))
|
The observations (training data) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
R |
(Array, shape(dim_Y, dim_Y))
|
The observation noise covariance |
Source code in src/simpl/kalman.py
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 | |