class_docstr: 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.
  
  
  Examples
  --------
  
  .. code-block:: Python
  
      from filterpy.kalman import FixedLagSmoother
      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)
  
  
  See my book Kalman and Bayesian Filters in Python
  https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python
  
  
  References
  ----------
  
  Wikipedia http://en.wikipedia.org/wiki/Kalman_filter#Fixed-lag_smoother
  
  Simon, Dan. "Optimal State Estimation," John Wiley & Sons pp 274-8 (2006).
  
  |
  |
class_docstr_tok: ["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",".","Examples","--","--","--","--","..","code-block",":",":","Python","from","filterpy.kalman","import","FixedLagSmoother","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",")","See","my","book","Kalman","and","Bayesian","Filters","in","Python","https",":","\/\/github.com\/rlabbe\/Kalman-and-Bayesian-Filters-in-Python","References","--","--","--","--","--","Wikipedia","http",":","\/\/en.wikipedia.org\/wiki\/Kalman_filter","#","Fixed-lag_smoother","Simon",",","Dan",".","``","Optimal","State","Estimation",",","''","John","Wiley","&","Sons","pp","274-8","(","2006",")",".","|","|"]
docstr: batch smooths the set of measurements using a fixed lag smoother.
  I consider this function a somewhat pedalogical exercise; why would
  you not use a RTS smoother if you are able to batch process your data?
  Hint: RTS is a much better smoother, and faster besides. Use it.
  
  This is a batch processor, so it does not alter any of the object's
  data. In particular, self.x is NOT modified. All date is returned
  by the function.
  
  Parameters
  ----------
  
  
  zs : ndarray of measurements
  
      iterable list (usually ndarray, but whatever works for you) of
      measurements that you want to smooth, one per time step.
  
  N : int
     size of fixed lag in time steps
  
  us : ndarray, optional
  
      If provided, control input to the filter for each time step
  
  
  Returns
  -------
  
  (xhat_smooth, xhat) : ndarray, ndarray
  
      xhat_smooth is the output of the N step fix lag smoother
      xhat is the filter output of the standard Kalman filter
docstr_tok: ["batch","smooths","the","set","of","measurements","using","a","fixed","lag","smoother",".","I","consider","this","function","a","somewhat","pedalogical","exercise",";","why","would","you","not","use","a","RTS","smoother","if","you","are","able","to","batch","process","your","data","?","Hint",":","RTS","is","a","much","better","smoother",",","and","faster","besides",".","Use","it",".","This","is","a","batch","processor",",","so","it","does","not","alter","any","of","the","object's","data",".","In","particular",",","self.x","is","NOT","modified",".","All","date","is","returned","by","the","function",".","Parameters","--","--","--","--","--","zs",":","ndarray","of","measurements","iterable","list","(","usually","ndarray",",","but","whatever","works","for","you",")","of","measurements","that","you","want","to","smooth",",","one","per","time","step",".","N",":","int","size","of","fixed","lag","in","time","steps","us",":","ndarray",",","optional","If","provided",",","control","input","to","the","filter","for","each","time","step","Returns","--","--","--","-","(","xhat_smooth",",","xhat",")",":","ndarray",",","ndarray","xhat_smooth","is","the","output","of","the","N","step","fix","lag","smoother","xhat","is","the","filter","output","of","the","standard","Kalman","filter"]
code: def smooth_batch(self, zs, N, us=None):
      """batch smooths the set of measurements using a fixed lag smoother.
      I consider this function a somewhat pedalogical exercise; why would
      you not use a RTS smoother if you are able to batch process your data?
      Hint: RTS is a much better smoother, and faster besides. Use it.
  
      This is a batch processor, so it does not alter any of the object's
      data. In particular, self.x is NOT modified. All date is returned
      by the function.
  
      Parameters
      ----------
  
  
      zs : ndarray of measurements
  
          iterable list (usually ndarray, but whatever works for you) of
          measurements that you want to smooth, one per time step.
  
      N : int
         size of fixed lag in time steps
  
      us : ndarray, optional
  
          If provided, control input to the filter for each time step
  
  
      Returns
      -------
  
      (xhat_smooth, xhat) : ndarray, ndarray
  
          xhat_smooth is the output of the N step fix lag smoother
          xhat is the filter output of the standard Kalman filter
      """
  
      # take advantage of the fact that np.array are assigned by reference.
      H = self.H
      R = self.R
      F = self.F
      P = self.P
      x = self.x
      Q = self.Q
      B = self.B
  
      if x.ndim == 1:
          xSmooth = zeros((len(zs), self.dim_x))
          xhat = zeros((len(zs), self.dim_x))
      else:
          xSmooth = zeros((len(zs), self.dim_x, 1))
          xhat = zeros((len(zs), self.dim_x, 1))
      for k, z in enumerate(zs):
          # predict step of normal Kalman filter
          x_pre = dot(F, x)
          if us is not None:
              x_pre += dot(B, us[k])
  
          P = dot(F, P).dot(F.T) + Q
  
          # update step of normal Kalman filter
          y = z - dot(H, x_pre)
  
          S = dot(H, P).dot(H.T) + R
          SI = inv(S)
  
          K = dot(P, H.T).dot(SI)
  
          x = x_pre + dot(K, y)
  
          I_KH = self._I - dot(K, H)
          P = dot(I_KH, P).dot(I_KH.T) + dot(K, R).dot(K.T)
  
          xhat[k] = x.copy()
          xSmooth[k] = x_pre.copy()
  
          # compute invariants
          HTSI = dot(H.T, SI)
          F_LH = (F - dot(K, H)).T
  
          if k >= N:
              PS = P.copy()  # smoothed P for step i
              for i in range(N):
                  K = dot(PS, HTSI)  # smoothed gain
                  PS = dot(PS, F_LH)  # smoothed covariance
  
                  si = k - i
                  xSmooth[si] = xSmooth[si] + dot(K, y)
          else:
              # Some sources specify starting the fix lag smoother only
              # after N steps have passed, some don't. I am getting far
              # better results by starting only at step N.
              xSmooth[k] = xhat[k]
  
      return xSmooth, xhat
  
file_path: filterpy/filterpy/kalman/fixed_lag_smoother.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import numpy
  from numpy import dot, zeros, eye
  from scipy.linalg import inv
  from filterpy.common import pretty_str
label_desc: Use image node_id 3 for calling the FixedLagSmoother obj's underlying member method code with example usage: obj.smooth_batch(zs, N, us) and returns: xSmooth,  xhat