{"id":8490,"library":"pykalman","title":"PyKalman","description":"PyKalman is an active Python library providing robust implementations of the Kalman Filter, Kalman Smoother, and the Expectation-Maximization (EM) algorithm. It is designed for state estimation in linear dynamical systems and parameter learning, with recent updates ensuring compatibility with modern Python and NumPy versions. The library maintains a steady release cadence with regular bug fixes and maintenance updates.","status":"active","version":"0.11.2","language":"en","source_language":"en","source_url":"https://github.com/pykalman/pykalman","tags":["kalman filter","time series","state estimation","signal processing","machine learning","filtering","smoothing"],"install":[{"cmd":"pip install pykalman","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for numerical operations, array manipulation, and mathematical functions.","package":"numpy","optional":false}],"imports":[{"symbol":"KalmanFilter","correct":"from pykalman import KalmanFilter"},{"note":"Used for non-linear state estimation problems.","symbol":"UnscentedKalmanFilter","correct":"from pykalman import UnscentedKalmanFilter"}],"quickstart":{"code":"import numpy as np\nfrom pykalman import KalmanFilter\n\n# Define the parameters of a simple linear system\ntransition_matrices = [[1, 1], [0, 1]] # State transition matrix\nobservation_matrices = [[1, 0]]       # Observation matrix (we observe position only)\ntransition_covariance = np.eye(2) * 0.1 # Small process noise\nobservation_covariance = np.eye(1) * 1.0 # Larger observation noise\ninitial_state_mean = [0, 1]           # Initial state (position=0, velocity=1)\ninitial_state_covariance = np.eye(2) * 1.0 # Initial uncertainty\n\n# Create a Kalman Filter instance\nkf = KalmanFilter(\n    transition_matrices=transition_matrices,\n    observation_matrices=observation_matrices,\n    transition_covariance=transition_covariance,\n    observation_covariance=observation_covariance,\n    initial_state_mean=initial_state_mean,\n    initial_state_covariance=initial_state_covariance\n)\n\n# Generate some noisy 'measurements' for a simple linear motion\nn_timesteps = 50\ntrue_states = np.zeros((n_timesteps, 2))\nmeasurements = np.zeros((n_timesteps, 1))\ntrue_states[0] = initial_state_mean\nfor t in range(1, n_timesteps):\n    true_states[t] = np.dot(transition_matrices, true_states[t-1]) + np.random.multivariate_normal([0, 0], transition_covariance)\n    measurements[t] = np.dot(observation_matrices, true_states[t]) + np.random.normal(0, np.sqrt(observation_covariance[0,0]))\n\n# Use the Kalman Filter to estimate the states from measurements\n(filtered_state_means, filtered_state_covariances) = kf.filter(measurements)\n(smoothed_state_means, smoothed_state_covariances) = kf.smooth(measurements)\n\nprint(\"First 5 filtered state means (position, velocity):\")\nprint(filtered_state_means[:5])\nprint(\"\\nFirst 5 smoothed state means (position, velocity):\")\nprint(smoothed_state_means[:5])","lang":"python","description":"This quickstart demonstrates the basic usage of `KalmanFilter` to estimate states from noisy measurements. It defines a simple linear system, generates synthetic data, and then applies the `filter` and `smooth` methods to estimate the underlying states."},"warnings":[{"fix":"Upgrade your Python interpreter to version 3.10 or higher. Use a virtual environment to manage dependencies: `python3.10 -m venv .venv && source .venv/bin/activate`","message":"Python 3.8 (and earlier) is no longer supported as of v0.10.0, and Python 3.9 is no longer supported as of v0.11.0. Ensure your Python environment meets the `pykalman` requirements (>=3.10, <3.15).","severity":"breaking","affected_versions":">=0.10.0, >=0.11.0"},{"fix":"Upgrade `pykalman` to the latest version (0.11.1 or higher) to ensure full compatibility with `numpy` 2.x. If upgrading `pykalman` is not an option, you may need to pin `numpy` to a `1.x` version (e.g., `numpy<2`).","message":"Older versions of `pykalman` (prior to v0.10.0 and v0.11.1) may experience compatibility issues with `numpy` 2.x due to significant API changes in NumPy. This can lead to unexpected errors or incorrect behavior.","severity":"gotcha","affected_versions":"<0.10.0, <0.11.1"},{"fix":"Upgrade `pykalman` to version 0.11.2 or higher. If unable to upgrade, ensure `n_timesteps` is greater than 1 when using `em()`.","message":"When using `KalmanFilter.em()` with `n_timesteps=1`, versions prior to v0.11.2 may encounter a crash. This specific edge case was resolved in a recent bugfix.","severity":"gotcha","affected_versions":"<0.11.2"},{"fix":"Upgrade `pykalman` to version 0.10.2 or higher to resolve this issue. If using an older version, manually ensure that time-varying transition covariance is correctly handled or explicitly set if it's not meant to vary.","message":"A bug existed in versions prior to v0.10.2 where time-varying transition covariance could be incorrectly overwritten by the initial matrix in the standard Kalman filter.","severity":"gotcha","affected_versions":"<0.10.2"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Update `pykalman` to the latest version (`pip install --upgrade pykalman`). If you cannot upgrade `pykalman`, downgrade `numpy` to a 1.x version (e.g., `pip install 'numpy<2'`).","cause":"This error often occurs when an older version of `pykalman` (e.g., <0.10.0 or <0.11.1) is used with `numpy` 2.x, due to breaking API changes in NumPy.","error":"TypeError: 'numpy.ndarray' object is not callable"},{"fix":"Ensure you are using `from pykalman import KalmanFilter` and that your `KalmanFilter` instance (`kf`) is properly created before calling its methods. Check the official documentation for correct method names and parameters.","cause":"This usually means you're trying to call a method like `filter()` or `smooth()` on an incorrectly initialized `KalmanFilter` object, or perhaps from an outdated fork, or you made a typo.","error":"AttributeError: 'KalmanFilter' object has no attribute 'filter'"},{"fix":"Carefully check the shapes of your input matrices. Ensure `transition_matrices` is (n_dim_state, n_dim_state), `observation_matrices` is (n_dim_obs, n_dim_state), and covariance matrices are symmetric with appropriate dimensions (e.g., `transition_covariance` is (n_dim_state, n_dim_state), `observation_covariance` is (n_dim_obs, n_dim_obs)).","cause":"This error indicates a mismatch in the dimensions of the matrices provided to the KalmanFilter constructor (e.g., `transition_matrices`, `observation_matrices`, `covariance` matrices).","error":"ValueError: operands could not be broadcast together with shapes (X) (Y)"}]}