### Install filterpy from source Source: https://github.com/rlabbe/filterpy/blob/master/README.rst Installs the filterpy package by cloning the source code from GitHub and then running the setup script. This method is useful for installing directly from the repository. ```shell cd git clone http://github.com/rlabbe/filterpy python setup.py install ``` -------------------------------- ### Install FilterPy from GitHub Source: https://github.com/rlabbe/filterpy/blob/master/docs/index.rst Installs the latest FilterPy code directly from its GitHub repository. This involves cloning the repository and running the setup script. Useful for developers wanting the most recent code. ```bash $ git clone --depth=1 https://github.com/rlabbe/filterpy.git $ cd filterpy $ python setup.py install ``` -------------------------------- ### Install filterpy from git repository Source: https://github.com/rlabbe/filterpy/blob/master/README.rst Installs the latest development version of filterpy directly from its git repository. Use with caution as it may be unstable. ```shell pip install git+https://github.com/rlabbe/filterpy.git ``` -------------------------------- ### Install FilterPy using pip Source: https://github.com/rlabbe/filterpy/blob/master/docs/index.rst Installs the FilterPy library using the pip package manager. This is the recommended method for most users. ```bash $ pip install filterpy ``` -------------------------------- ### Install filterpy using pip Source: https://github.com/rlabbe/filterpy/blob/master/README.rst Installs the filterpy package using pip, the standard Python package installer. This is the most common method for installing Python libraries. ```shell pip install filterpy ``` -------------------------------- ### Install and Configure conda-build Source: https://github.com/rlabbe/filterpy/blob/master/conda/conda_install.txt Installs the conda-build package and configures Anaconda to not upload packages automatically. These are initial setup steps. ```shell conda install conda-build conda config --set anaconda_upload no ``` -------------------------------- ### Procedural Kalman Filter Example Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Demonstrates the procedural form of Kalman filtering using standalone functions for predict and update steps. Suitable for users who prefer not to use objects. ```python while True: z, R = read_sensor() x, P = predict(x, P, F, Q) x, P = update(x, P, z, R, H) ``` -------------------------------- ### Install filterpy using conda Source: https://github.com/rlabbe/filterpy/blob/master/README.rst Installs the filterpy package using the conda package manager from the conda-forge channel. This method is suitable for users who manage their environments with Anaconda. ```shell conda config --add channels conda-forge conda install filterpy ``` -------------------------------- ### MMAE Filter Bank Initialization and Usage Example Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/MMAEFilterBank.rst This Python code demonstrates how to initialize and use the MMAEFilterBank. It sets up multiple Kalman filters, defines measurement matrices, and processes a series of measurements to estimate the state and probabilities. ```Python from filterpy.kalman import MMAEFilterBank pos, zs = generate_data(120, noise_factor=0.2) z_xs = zs[:, 0] t = np.arange(0, len(z_xs) * dt, dt) dt = 0.1 filters = [make_cv_filter(dt), make_ca_filter(dt)] H_cv = np.array([[1., 0, 0], [0., 1, 0]]) H_ca = np.array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) bank = MMAEFilterBank(filters, (0.5, 0.5), dim_x=3, H=(H_cv, H_ca)) xs, probs = [], [] for z in z_xs: bank.predict() bank.update(z) xs.append(bank.x[0]) probs.append(bank.p[0]) plt.subplot(121) plt.plot(xs) plt.subplot(122) plt.plot(probs) ``` -------------------------------- ### Import NumPy and filterpy modules Source: https://github.com/rlabbe/filterpy/blob/master/README.rst Basic Python code snippet to import the NumPy library for numerical operations and potentially filterpy modules for use in calculations. Assumes filterpy is installed. ```python import numpy as np ``` -------------------------------- ### kinematic_kf for Kinematic Kalman Filter Source: https://github.com/rlabbe/filterpy/blob/master/docs/common/common.rst Provides a Kalman filter implementation specifically tailored for kinematic models, such as constant velocity or constant acceleration. It simplifies the setup for common motion models. ```python from filterpy.common import kinematic_kf # Example usage (conceptual): # Initialize the filter with appropriate dimensions and noise values # kf = kinematic_kf(dim=2, order_by_dim=True) # kf.predict() # kf.update(measurement) ``` -------------------------------- ### Build HTML Documentation with Make Source: https://github.com/rlabbe/filterpy/blob/master/creating_a_release.rst Builds the HTML documentation for the filterpy project using the 'make html' command within the /docs directory. The generated documentation is then inspected for correctness. ```bash make html ``` -------------------------------- ### Initialize Kalman Filter and Matrices Source: https://github.com/rlabbe/filterpy/blob/master/README.rst Demonstrates the creation of a KalmanFilter object and the initialization of its core matrices (x, F, H, P, R, Q) using NumPy arrays and filterpy's Q_discrete_white_noise function. This is a foundational step for any Kalman filter implementation. ```python from filterpy.kalman import KalmanFilter from filterpy.common import Q_discrete_white_noise import numpy as np # Create the filter my_filter = KalmanFilter(dim_x=2, dim_z=1) # Initialize the filter's matrices my_filter.x = np.array([[2.], [0.]]) # initial state (location and velocity) my_filter.F = np.array([[1.,1.], [0.,1.]]) # state transition matrix my_filter.H = np.array([[1.,0.]]) # Measurement function my_filter.P *= 1000. # covariance matrix my_filter.R = 5 # state uncertainty my_filter.Q = Q_discrete_white_noise(dim=2, dt=0.1, var=0.1) # process uncertainty ``` -------------------------------- ### Update PyPI Documentation with Zip Archive Source: https://github.com/rlabbe/filterpy/blob/master/creating_a_release.rst Manually updates the documentation on PyPI's documentation server (pythonhosted.org) by uploading a zip archive of the built HTML documentation. This involves navigating to the build directory, creating a zip file, and uploading it via the PyPI website. ```bash cd /docs/_build/html zip -r filterpy.zip *.* ``` -------------------------------- ### Initialize a Kalman Filter in Python Source: https://github.com/rlabbe/filterpy/blob/master/docs/index.rst Demonstrates how to import and initialize a KalmanFilter object from the filterpy.kalman submodule. It shows setting the dimensions for the state and measurement spaces. ```python from filterpy.kalman import KalmanFilter kf = KalmanFilter(dim_x=3, dim_z=1) ``` -------------------------------- ### Run Pytest for filterpy Source: https://github.com/rlabbe/filterpy/blob/master/creating_a_release.rst Executes the pytest framework to run tests for the filterpy project. This step is crucial for ensuring code quality and stability before a release. ```bash pytest ``` -------------------------------- ### Run Pylint with specific disables for filterpy Source: https://github.com/rlabbe/filterpy/blob/master/creating_a_release.rst Runs the Pylint code analysis tool on the filterpy project. The --disable=similarities and --disable=R0205 flags are used to ignore warnings related to code similarities and deriving from 'object', respectively, to maintain compatibility with Python 2.7. ```bash pylint --disable=similarities --disable=R0205 filterpy ``` -------------------------------- ### Tag Release with Git Source: https://github.com/rlabbe/filterpy/blob/master/creating_a_release.rst Creates a Git tag for a specific release version. This is typically done after all other release preparation steps are completed and committed. ```bash git tag -a 0.1.23 -m "version 0.1.23" ``` -------------------------------- ### KalmanFilter Initialization Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Initializes a KalmanFilter object with the system's dimensions and initial state estimates. ```APIDOC ## KalmanFilter.__init__ ### Description Initializes the KalmanFilter with system dimensions and initial state estimates. ### Method __init__ ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **dim_x** (int) - Required - Dimensionality of the state vector. - **dim_z** (int) - Required - Dimensionality of the measurement vector. - **dim_u** (int) - Optional - Dimensionality of the control input vector (default 0). ### Request Example ```python from filterpy.kalman import KalmanFilter kf = KalmanFilter(dim_x=4, dim_z=2) ``` ### Response #### Success Response (200) N/A (Initialization) #### Response Example None ``` -------------------------------- ### Push Git Tags to Origin Source: https://github.com/rlabbe/filterpy/blob/master/creating_a_release.rst Pushes all local Git tags to the remote origin repository. This action is essential for ensuring that release tags are available on the central repository and can trigger automated builds (e.g., on ReadTheDocs). ```bash git push origin --tags ``` -------------------------------- ### Initialize Kalman Filter Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Constructs a KalmanFilter object with specified dimensions for the state vector (dim_x) and measurement vector (dim_z). Requires the filterpy library. ```python from filterpy.kalman import KalmanFilter f = KalmanFilter (dim_x=2, dim_z=1) ``` -------------------------------- ### KalmanFilter Class Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst The KalmanFilter class provides a comprehensive implementation of the Kalman filter algorithm. It includes methods for initialization, prediction, and updating the state estimate. ```APIDOC ## KalmanFilter Class ### Description Represents a Kalman filter, a powerful algorithm for estimating the state of a linear system corrupted by Gaussian noise. ### Method N/A (Class) ### Endpoint N/A (Class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) N/A (Class) #### Response Example None ``` -------------------------------- ### Convert and Upload filterpy Package to Anaconda Source: https://github.com/rlabbe/filterpy/blob/master/conda/conda_install.txt Converts the built filterpy package for all platforms and uploads it to Anaconda. This command is used for distributing the package. ```shell conda convert --platform all ~/anaconda3/conda-bld/linux-64/filterpy-0.1.2-0.tar.bz2 anaconda upload --force linux-64/filterpy-0.1.2-0.tar.bz2 anaconda upload --force linux-32/filterpy-0.1.2-0.tar.bz2 anaconda upload --force osx-64/filterpy-0.1.2-0.tar.bz2 anaconda upload --force win-32/filterpy-0.1.2-0.tar.bz2 anaconda upload --force win-64/filterpy-0.1.2-0.tar.bz2 ``` -------------------------------- ### Run Kalman Filter Prediction and Update Loop Source: https://github.com/rlabbe/filterpy/blob/master/README.rst Illustrates the continuous operation of a Kalman filter by implementing a loop that repeatedly calls the predict() and update() methods. This snippet assumes the existence of external functions `get_some_measurement()` and `do_something_amazing(x)` to provide measurements and process the filter's output. ```python from filterpy.kalman import KalmanFilter from filterpy.common import Q_discrete_white_noise import numpy as np # Assume KalmanFilter and its matrices are already initialized as above # Placeholder functions for demonstration def get_some_measurement(): # In a real scenario, this would return a measurement return np.array([1.5]) def do_something_amazing(x): # In a real scenario, this would process the estimated state print(f"Estimated state: {x}") # Example of how to initialize (if not done prior) my_filter = KalmanFilter(dim_x=2, dim_z=1) my_filter.x = np.array([[2.], [0.]]) my_filter.F = np.array([[1.,1.],[0.,1.]]) my_filter.H = np.array([[1.,0.]]) my_filter.P *= 1000. my_filter.R = 5 my_filter.Q = Q_discrete_white_noise(dim=2, dt=0.1, var=0.1) # Finally, run the filter # In a real application, this loop would run based on incoming data or time intervals for _ in range(5): # Run for 5 iterations for demonstration my_filter.predict() measurement = get_some_measurement() my_filter.update(measurement) # do something with the output x = my_filter.x do_something_amazing(x) ``` -------------------------------- ### Python: Calculate Kalman gain using mathematical symbols Source: https://github.com/rlabbe/filterpy/blob/master/docs/index.rst Shows a Python implementation for calculating the Kalman gain, directly using mathematical symbols (like P, H, R) for clarity and conciseness, mirroring the mathematical formula. ```Python K = dot(P, H.T).dot(inv(dot(H, P).dot(H.T) + R)) ``` -------------------------------- ### Build filterpy Package with conda Source: https://github.com/rlabbe/filterpy/blob/master/conda/conda_install.txt Builds the filterpy package using conda skeleton for PyPI. It requires updating the meta.yaml file with the correct version before building. ```shell cd ~/Dropbox/filterpy/conda edit meta.yaml, update version # conda skeleton pypi --version 0.1.2 filterpy conda build . ``` -------------------------------- ### Python: Calculate Kalman gain with descriptive variable names Source: https://github.com/rlabbe/filterpy/blob/master/docs/index.rst Presents an alternative Python implementation for Kalman gain calculation using more descriptive variable names, which can be more readable in a general programming context but may obscure the underlying mathematical operations. ```Python kalman_gain = ( dot(apriori_state_covariance, measurement_function_transpose).dot( inv(dot(measurement_function, apriori_state_covariance).dot( measurement_function_transpose) + measurement_noise_covariance))) ``` -------------------------------- ### KalmanFilter Class Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Represents a Kalman filter. It requires initialization with system dimensions. The class provides methods for predicting and updating the filter's state. ```python class KalmanFilter: def __init__(self, dim_x, dim_z): ... def predict(self, u=0): ... def update(self, z): ... ``` -------------------------------- ### filterpy.kalman.batch_filter Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Runs the Kalman filter over a batch of measurements. ```APIDOC ## filterpy.kalman.batch_filter ### Description Runs the Kalman filter over a sequence of measurements, returning the filtered states and covariances. ### Method batch_filter ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **kf** (KalmanFilter) - Required - An initialized KalmanFilter object. - **zs** (list or numpy.ndarray) - Required - A list or array of measurements. - **us** (list or numpy.ndarray) - Optional - A list or array of control inputs (default None). - **preserve_state** (bool) - Optional - If True, the internal state of kf is preserved after the call (default False). ### Request Example ```python from filterpy.kalman import KalmanFilter, batch_filter kf = KalmanFilter(dim_x=2, dim_z=1) # ... initialize kf ... measurements = [[1.0], [2.0], [3.0]] means, covariances = batch_filter(kf, measurements) ``` ### Response #### Success Response (200) - **means** (list of numpy.ndarray) - Filtered state estimates for each measurement. - **covariances** (list of numpy.ndarray) - Filtered covariance estimates for each measurement. #### Response Example ```json { "means": [ [...], [...] ], "covariances": [ [[...], [...]], [[...], [...]] ] } ``` ``` -------------------------------- ### Define State Transition Matrix (F) Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Defines the state transition matrix F, which describes how the state evolves from one time step to the next. Requires numpy. ```python f.F = np.array([[1.,1.], \ [0.,1.]]) ``` -------------------------------- ### van_loan_discretization for Discretizing Van Loan's Method Source: https://github.com/rlabbe/filterpy/blob/master/docs/common/common.rst Implements Van Loan's method for discretizing continuous-time linear systems. This function is useful for converting continuous-time state-space models to discrete-time equivalents. ```python from filterpy.common import van_loan_discretization import numpy as np # Example usage: A = np.array([[1, 1], [0, 1]]) dt = 0.1 (F, Q) = van_loan_discretization(A, dt) print('F:\n', F) print('Q:\n', Q) ``` -------------------------------- ### Set Covariance Matrix (P) Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Sets the initial covariance matrix P, representing the uncertainty in the state estimate. Can be initialized by scaling an identity matrix or by direct assignment. Requires numpy. ```python f.P *= 1000. ``` ```python f.P = np.array([[1000., 0.], \ [ 0., 1000.] ]) ``` -------------------------------- ### Save Kalman Filter State and Convert to Array Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/Saver.rst Demonstrates how to initialize a Saver with a Kalman filter (kf), save its state within a loop after predict and update steps, and then convert the saved states to a NumPy array for plotting. Assumes 'zs' is a list of measurements and 'N' is the number of epochs. ```python saver = Saver(kf) for i in range(N): kf.predict() kf.update(zs[i]) saver.save() saver.to_array() # convert all to np.array # plot the 0th element of kf.x over all epoches plot(saver.xs[:, 0]) ``` -------------------------------- ### Kalman Filter Predict-Update Loop Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Standard loop for Kalman filtering, involving prediction and update steps with sensor measurements. Requires sensor reading and estimation processing functions. ```python while some_condition_is_true: z = get_sensor_reading() f.predict() f.update(z) do_something_with_estimate (f.x) ``` -------------------------------- ### filterpy.kalman.update Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Performs a single Kalman filter update step. ```APIDOC ## filterpy.kalman.update ### Description Performs the update step of the Kalman filter algorithm. This is a functional approach. ### Method update ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **kf** (KalmanFilter) - Required - An initialized KalmanFilter object. - **z** (numpy.ndarray) - Required - The measurement vector. ### Request Example ```python from filterpy.kalman import KalmanFilter, update kf = KalmanFilter(dim_x=2, dim_z=1) kf.x = [[0.], [0.]] # initial state kf.P *= 1000. # initial covariance measurement = [5.0] update(kf, measurement) ``` ### Response #### Success Response (200) N/A (Function Call) #### Response Example None ``` -------------------------------- ### KalmanFilter.predict Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Predicts the next state of the system based on the system model and control input. ```APIDOC ## KalmanFilter.predict ### Description Predicts the next state and covariance of the Kalman filter. ### Method predict ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **u** (numpy.ndarray) - Optional - Control input vector (default None). ### Request Example ```python kf.predict(u=[1, 0]) # Example with control input kf.predict() # Example without control input ``` ### Response #### Success Response (200) N/A (Method Call) #### Response Example None ``` -------------------------------- ### Python: Calculate Newtonian distance equation Source: https://github.com/rlabbe/filterpy/blob/master/docs/index.rst Demonstrates how to implement the Newtonian distance equation in Python for maximum readability, aligning code closely with mathematical notation. ```Python distance = (.5 * constant_acceleration) * time_delta**2 + initial_velocity * time_delta + initial_distance ``` -------------------------------- ### Assign Process Noise (Q) Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Assigns the process noise covariance Q using the Q_discrete_white_noise function from filterpy.common. Requires filterpy.common. ```python from filterpy.common import Q_discrete_white_noise f.Q = Q_discrete_white_noise(dim=2, dt=0.1, var=0.13) ``` -------------------------------- ### Initialize ExtendedKalmanFilter Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/ExtendedKalmanFilter.rst Constructs an ExtendedKalmanFilter object, specifying the dimensions of the state and measurement vectors. This helps in performing size checks for matrix assignments. ```python from filterpy.kalman import ExtendedKalmanFilter # Example: state vector of size 4, measurement vector of size 2 fx = lambda x, dt: x + np.array([0., 0.]) # Example state transition function hx = lambda x: x # Example measurement function my_filter = ExtendedKalmanFilter(dim_x=4, dim_z=2) # Assign state transition and measurement functions my_filter.fx = fx my_filter.hx = hx # Default matrices are created, but their values must be specified. # Example: Overwriting the default measurement noise matrix R my_filter.R = np.array([[5., 0.], [0., 5.]]) # If you need to alter matrix sizes midstream, use the underscore version: # my_filter._R = a_3x3_matrix ``` -------------------------------- ### kinematic_state_transition for Kinematic Models Source: https://github.com/rlabbe/filterpy/blob/master/docs/common/common.rst Generates the state transition matrix (F) for kinematic models. This function is crucial for defining how the system state evolves over time in a Kalman filter. ```python from filterpy.common import kinematic_state_transition # Example usage: dt = 0.1 state_transition = kinematic_state_transition(2, 2, dt) # 2 dimensions, 2nd order print(state_transition) ``` -------------------------------- ### Kalman Filter Functions Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Provides core Kalman filter operations. 'update' adjusts the state based on a measurement, and 'predict' advances the state prediction. 'batch_filter' processes multiple measurements. ```python def update(state, P, x, b, u, z, R, H, H_transpose): ... def predict(x, P, u, F, B, Q): ... def batch_filter(x0, P0, zs, R, H, F, B, Q): ... ``` -------------------------------- ### MMAEFilterBank Class Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/MMAEFilterBank.rst The MMAEFilterBank class implements a bank of Kalman filters using the Mean-Maximal-A-Posteriori-Error (MMAE) criterion. ```APIDOC ## Class: MMAEFilterBank ### Description Implements a bank of Kalman filters using the Mean-Maximal-A-Posteriori-Error (MMAE) criterion. This class allows for managing multiple filters simultaneously and computing their weighted outputs. ### Initialization ```python from filterpy.kalman import MMAEFilterBank # Example initialization # filters: A list of initialized Kalman filter objects (e.g., KalmanFilter, ExtendedKalmanFilter) # prior: A tuple of prior probabilities for each filter in the bank. # dim_x: The dimension of the state vector for the filters. # H: A tuple of measurement matrices (H) for each filter, corresponding to the filters list. bank = MMAEFilterBank(filters, prior, dim_x, H) ``` ### Methods - **predict()**: Predicts the next state for all filters in the bank. - **update(z)**: Updates the filters with the new measurement `z` and calculates the posterior probabilities. ### Request Example ```python # Assuming 'filters', 'prior', 'dim_x', 'H' are defined and populated bank = MMAEFilterBank(filters, prior, dim_x, H) # Example usage in a loop # for z in measurements: # bank.predict() # bank.update(z) # posterior_state = bank.x # Access the MMAE estimated state # posterior_probs = bank.p # Access the probabilities of each filter ``` ### Response - **x** (numpy.ndarray): The MMAE estimated state vector. - **p** (numpy.ndarray): An array of posterior probabilities for each filter in the bank. ### Response Example ```json { "x": [0.1, 0.2, 0.3], "p": [0.6, 0.4] } ``` ### Error Handling - **ValueError**: If the number of filters, priors, or measurement matrices do not match. - **TypeError**: If the input types are incorrect. ``` -------------------------------- ### Q_discrete_white_noise for Discrete Systems Source: https://github.com/rlabbe/filterpy/blob/master/docs/common/common.rst Calculates the discrete white noise process noise covariance matrix Q for discrete-time systems. It takes the system's time step (dt) and the process noise variance (var) as input. ```python from filterpy.common import Q_discrete_white_noise # Example usage: dt = 0.1 var = 0.01 Q = Q_discrete_white_noise(dt, var) print(Q) ``` -------------------------------- ### KalmanFilter.update Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Updates the state estimate using a new measurement. ```APIDOC ## KalmanFilter.update ### Description Updates the Kalman filter state estimate with a new measurement. ### Method update ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **z** (numpy.ndarray) - Required - The measurement vector. ### Request Example ```python measurement = [5.0, 2.0] kf.update(measurement) ``` ### Response #### Success Response (200) N/A (Method Call) #### Response Example None ``` -------------------------------- ### Assign Initial State Estimate Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Assigns the initial value for the filter's state estimate (e.g., position and velocity). Can be a 2D or 1D numpy array. Requires numpy. ```python f.x = np.array([[2.], \ [0.]]) ``` ```python f.x = np.array([2., 0.]) ``` -------------------------------- ### Q_continuous_white_noise for Continuous Systems Source: https://github.com/rlabbe/filterpy/blob/master/docs/common/common.rst Calculates the continuous white noise process noise covariance matrix Q for continuous-time systems discretized to a discrete-time system. It requires the time step (dt) and the process noise variance (var). ```python from filterpy.common import Q_continuous_white_noise # Example usage: dt = 0.1 var = 0.01 Q = Q_continuous_white_noise(dt, var) print(Q) ``` -------------------------------- ### filterpy.kalman.predict Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Performs a single Kalman filter prediction step. ```APIDOC ## filterpy.kalman.predict ### Description Performs the prediction step of the Kalman filter algorithm. This is a functional approach. ### Method predict ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **kf** (KalmanFilter) - Required - An initialized KalmanFilter object. - **u** (numpy.ndarray) - Optional - Control input vector (default None). ### Request Example ```python from filterpy.kalman import KalmanFilter, predict kf = KalmanFilter(dim_x=2, dim_z=1) predict(kf, u=[1.]) # Example with control input predict(kf) # Example without control input ``` ### Response #### Success Response (200) N/A (Function Call) #### Response Example None ``` -------------------------------- ### Define Measurement Function (H) Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Defines the measurement function H, which maps the state space to the measurement space. Requires numpy. ```python f.H = np.array([[1.,0.]]) ``` -------------------------------- ### linear_ode_discretation for Linear ODE Discretization Source: https://github.com/rlabbe/filterpy/blob/master/docs/common/common.rst Discretizes a linear ordinary differential equation (ODE) system. This function is essential for converting continuous-time linear systems into a format suitable for discrete-time filtering algorithms. ```python from filterpy.common import linear_ode_discretation import numpy as np # Example usage: A = np.array([[1, 1], [0, 1]]) dt = 0.1 (F, Q) = linear_ode_discretation(A, dt) print('F:\n', F) print('Q:\n', Q) ``` -------------------------------- ### Saver Function in FilterPy Source: https://github.com/rlabbe/filterpy/blob/master/docs/common/common.rst The Saver function is used for saving and loading filter states or data. It typically handles serialization and deserialization of objects, allowing for checkpointing or data persistence. ```python from filterpy.common import Saver # Example usage (conceptual): saver = Saver('my_filter_data') saver.save(filter_state) loaded_state = saver.load() ``` -------------------------------- ### runge_kutta4 for 4th Order Runge-Kutta Integration Source: https://github.com/rlabbe/filterpy/blob/master/docs/common/common.rst Implements the 4th order Runge-Kutta method for solving ordinary differential equations (ODEs). This is a versatile numerical integration technique used for simulating dynamic systems. ```python from filterpy.common import runge_kutta4 import numpy as np # Example usage: def func(x, t): return -x * t x0 = 1.0 t = np.linspace(0, 1, 10) x = runge_kutta4(func, x0, t) print(x) ``` -------------------------------- ### inv_diagonal for Inverting Diagonal Matrices Source: https://github.com/rlabbe/filterpy/blob/master/docs/common/common.rst Efficiently computes the inverse of a diagonal matrix. This is a common operation in Kalman filtering when dealing with covariance matrices that are often diagonal. ```python from filterpy.common import inv_diagonal import numpy as np # Example usage: diag_matrix = np.diag([1, 2, 3]) inverse_diag = inv_diagonal(diag_matrix) print(inverse_diag) ``` -------------------------------- ### Assign Measurement Noise (R) Source: https://github.com/rlabbe/filterpy/blob/master/docs/kalman/KalmanFilter.rst Assigns the measurement noise covariance R. Can be a scalar if the dimension is 1x1, or a 2D numpy array. Requires numpy. ```python f.R = 5 ``` ```python f.R = np.array([[5.]]) ``` -------------------------------- ### outer_product_sum for Sum of Outer Products Source: https://github.com/rlabbe/filterpy/blob/master/docs/common/common.rst Calculates the sum of outer products of vectors. This function is useful in various linear algebra operations, including updating covariance matrices in Kalman filters. ```python from filterpy.common import outer_product_sum import numpy as np # Example usage: vec1 = np.array([1, 2]) vec2 = np.array([3, 4]) vec3 = np.array([5, 6]) sum_outer = outer_product_sum([vec1, vec2, vec3]) print(sum_outer) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.