� �g�Uc @` s� d Z d d l m Z m Z m Z m Z d d l Z d d l m Z d d l m Z m Z m Z d d l m Z m Z m Z d e f d � � YZ d S( u4 Copyright 2015 Roger R Labbe Jr. FilterPy library. http://github.com/rlabbe/filterpy Documentation at: https://filterpy.readthedocs.org Supporting book at: https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python This is licensed under an MIT license. See the readme.MD file for more information. i ( t absolute_importt divisiont print_functiont unicode_literalsN( t inv( t dott zerost eye( t dot3t dot4t dotnt FixedLagSmootherc B` s2 e Z d Z d d � Z d d � Z d d � Z RS( u� Fixed Lag Kalman smoother. Computes a smoothed sequence from a set of measurements based on the fixed lag Kalman smoother. At time k, for a lag N, the fixed-lag smoother computes the state estimate for time k-N based on all measurements made between times k-N and k. This yields a pretty good smoothed result with O(N) extra computations performed for each measurement. In other words, if N=4 this will consume about 5x the number of computations as a basic Kalman filter. However, the loops contain only 3 dot products, so it will be much faster than this sounds as the main Kalman filter loop involves transposes and inverses, as well as many more matrix multiplications. Implementation based on Wikipedia article as it existed on November 18, 2014. **Example**:: fls = FixedLagSmoother(dim_x=2, dim_z=1) fls.x = np.array([[0.], [.5]]) fls.F = np.array([[1.,1.], [0.,1.]]) fls.H = np.array([[1.,0.]]) fls.P *= 200 fls.R *= 5. fls.Q *= 0.001 zs = [...some measurements...] xhatsmooth, xhat = fls.smooth_batch(zs, N=4) **References** Wikipedia http://en.wikipedia.org/wiki/Kalman_filter#Fixed-lag_smoother Simon, Dan. "Optimal State Estimation," John Wiley & Sons pp 274-8 (2006). | | **Methods** c C` s� | | _ | | _ | | _ t | d f � | _ t | d f � | _ t | � | _ t | � | _ d | _ d | _ t | � | _ d | _ t | d f � | _ d | _ t j | � | _ d | _ | d k r� g | _ n d S( uL Create a fixed lag Kalman filter smoother. You are responsible for setting the various state variables to reasonable values; the defaults below will not give you a functional filter. **Parameters** dim_x : int Number of state variables for the Kalman filter. For example, if you are tracking the position and velocity of an object in two dimensions, dim_x would be 4. This is used to set the default size of P, Q, and u dim_z : int Number of of measurement inputs. For example, if the sensor provides you with position in (x,y), dim_z would be 2. N : int, optional If provided, the size of the lag. Not needed if you are only using smooth_batch() function. Required if calling smooth() i i N( t dim_xt dim_zt NR t xt x_sR t Pt Qt Ft Ht Rt Kt residualt Bt npt _It countt Nonet xSmooth( t selfR R R ( ( s'