Smoothers

RTSSmoother = RauchTungStriebelSmoother module-attribute

SO3CMSmoother = SO3ChordalMeanSmoother module-attribute

URTSSmoother = UnscentedRauchTungStriebelSmoother module-attribute

__all__ = ['AbstractSmoother', 'RauchTungStriebelSmoother', 'RTSSmoother', 'SlidingWindowManifoldMeanSmoother', 'SO3ChordalMeanSmoother', 'SO3CMSmoother', 'UnscentedRauchTungStriebelSmoother', 'URTSSmoother'] module-attribute

AbstractSmoother

Bases: ABC

Abstract base class for all smoothers.

smooth(*args, **kwargs) abstractmethod

Smooth a sequence of states produced by a forward pass.

RauchTungStriebelSmoother

Bases: AbstractSmoother

Rauch--Tung--Striebel smoother for linear Gaussian models.

This class intentionally does not depend on pyrecest.filters.KalmanFilter. The current filter classes do not retain the full forward-pass history that an RTS smoother requires, so this implementation provides its own forward pass for sequences of linear Gaussian models.

The accepted model inputs can each either be a single matrix/vector reused for the whole sequence or a sequence with one entry per time step.

Parameters

initial_state Initial prior state as GaussianDistribution or (mean, covariance). measurements Sequence of measurements. A one-dimensional array is interpreted as a sequence of scalar measurements. For vector measurements, pass a list/tuple of one-dimensional arrays or a two-dimensional array of shape (T, dim_z). measurement_matrices Measurement matrix H or sequence H_t. Defaults to identity. meas_noise_covariances Measurement noise covariance R or sequence R_t. system_matrices Transition matrix F or sequence F_t used between consecutive time steps. Defaults to identity. sys_noise_covariances Process noise covariance Q or sequence Q_t. Defaults to zero. sys_inputs Optional control/input vector u or sequence u_t added in the prediction step. Defaults to zero.

filter(initial_state, measurements, measurement_matrices=None, meas_noise_covariances=None, system_matrices=None, sys_noise_covariances=None, sys_inputs=None)

Run the forward Kalman filtering pass for a sequence.

Returns

filtered_states List of posterior states x_{t|t}. predicted_states List of one-step predictions x_{t+1|t}. Its length is one less than the number of measurements.

smooth(filtered_states, predicted_states, system_matrices=None)

Run the RTS backward pass.

Parameters

filtered_states Sequence of posterior states x_{t|t}. predicted_states Sequence of one-step predictions x_{t+1|t}. system_matrices Transition matrix F or sequence F_t used in the forward pass.

Returns

smoothed_states List of smoothed posterior states x_{t|T}. smoother_gains List of RTS smoother gains, one per backward recursion step.

filter_and_smooth(initial_state, measurements, measurement_matrices=None, meas_noise_covariances=None, system_matrices=None, sys_noise_covariances=None, sys_inputs=None)

Run a full forward-backward pass for a linear Gaussian sequence.

SlidingWindowManifoldMeanSmoother

Bases: AbstractSmoother

Smooth state estimates by replacing each entry with a local manifold mean.

The smoother extracts a representative point from each input state. For PyRecEst distributions this is state.mean(); raw arrays are used directly. Each sliding window is then represented as a Dirac distribution on the same manifold, and the Dirac distribution's mean() defines the smoothed value.

Parameters

window_size Number of sequence entries considered for each smoothed state. Edge windows are truncated to the available samples. dirac_distribution_factory Optional callable factory(points, weights) used to construct the window Dirac distribution. This is useful for raw samples on non-linear manifolds. If omitted, the smoother infers a factory from distribution inputs and falls back to a Euclidean Dirac distribution for raw arrays. window_weights Optional non-negative weights with length window_size. Truncated edge windows use the corresponding weight slice and are renormalized by the Dirac distribution. alignment "center" uses past and future estimates around each state, "trailing" uses the current and previous estimates, and "leading" uses the current and following estimates.

window_size = window_size instance-attribute

dirac_distribution_factory = dirac_distribution_factory instance-attribute

alignment = alignment instance-attribute

window_weights = None instance-attribute

__init__(window_size=3, dirac_distribution_factory=None, window_weights=None, alignment='center')

smooth(states)

Return smoothed manifold mean values for a sequence of states.

SO3ChordalMeanSmoother

Bases: AbstractSmoother

Smooth SO(3) rotation sequences with local weighted chordal means.

Rotations are represented as 3-by-3 rotation matrices. The chordal mean is computed by averaging rotation matrices in the ambient Euclidean space and projecting the result back onto SO(3) with the orthogonal Procrustes solution.

Parameters

window_size Number of neighboring rotations used per local mean. The window is centered as far as possible around each time index and clipped at the sequence boundaries. kernel_weights Optional nonnegative weights for positions inside the local window. If provided, its length must match window_size.

window_size = self._validate_window_size(window_size) instance-attribute

kernel_weights = self._normalize_weight_vector(kernel_weights, self.window_size, 'kernel_weights', normalize=False) instance-attribute

__init__(window_size=3, kernel_weights=None)

project_to_so3(matrix) staticmethod

Project a 3-by-3 matrix to the closest SO(3) rotation matrix.

chordal_distance(rotation_a, rotation_b) staticmethod

Return the Frobenius chordal distance between two SO(3) rotations.

chordal_mean(rotations, weights=None) classmethod

Compute the weighted chordal mean of one or more SO(3) rotations.

smooth(rotations, weights=None, window_size=None)

Smooth a rotation sequence with local chordal means.

Parameters

rotations Rotation matrix sequence as a Python sequence, (n, 3, 3) array, or (3, 3, n) array. weights Optional nonnegative reliability weights, one per input rotation. window_size Optional per-call override for the number of rotations in each local mean. Kernel weights from construction are only used when this is not overridden.

Returns

list Smoothed SO(3) rotations, one per input rotation.

UnscentedRauchTungStriebelSmoother

Bases: AbstractSmoother

Unscented fixed-interval smoother for nonlinear Gaussian state-space models.

This implements the unscented Rauch--Tung--Striebel (URTS) smoother for Euclidean state spaces. It mirrors the current :class:UnscentedKalmanFilter scope in PyRecEst and therefore only supports the NumPy backend.

The smoother provides a complete forward pass (filter) and the backward pass (smooth). For the nonlinear case the smoother gain depends on the predicted cross-covariance between x_t and x_{t+1}, so the forward pass stores those cross-covariances explicitly.

Parameters

points Optional sigma-point object compatible with MerweScaledSigmaPoints. If omitted, standard Merwe scaled sigma points are used. alpha, beta, kappa Default sigma-point parameters used when points is omitted.

points = points instance-attribute

alpha = alpha instance-attribute

beta = beta instance-attribute

kappa = kappa instance-attribute

__init__(points=None, alpha=0.001, beta=2.0, kappa=0.0)

filter(initial_state, measurements, measurement_functions=None, meas_noise_covariances=None, transition_functions=None, sys_noise_covariances=None, time_steps=None)

Run the forward unscented filtering pass for a full sequence.

Returns

filtered_states Posterior states x_{t|t}. predicted_states One-step predictions x_{t+1|t} with length T - 1. predicted_cross_covariances Cross-covariances Cov[x_t, x_{t+1}] needed by the URTS backward pass.

smooth(filtered_states, predicted_states, predicted_cross_covariances)

Run the unscented RTS backward pass.

smooth_from_filtered(filtered_states, transition_functions=None, sys_noise_covariances=None, time_steps=None)

Smooth from filtered states by recomputing nonlinear predictions.

filter_and_smooth(initial_state, measurements, measurement_functions=None, meas_noise_covariances=None, transition_functions=None, sys_noise_covariances=None, time_steps=None)

Convenience wrapper that runs both the forward and backward passes.