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: Smooths the measurement using a fixed lag smoother.
  
  On return, self.xSmooth is populated with the N previous smoothed
  estimates,  where self.xSmooth[k] is the kth time step. self.x
  merely contains the current Kalman filter output of the most recent
  measurement, and is not smoothed at all (beyond the normal Kalman
  filter processing).
  
  self.xSmooth grows in length on each call. If you run this 1 million
  times, it will contain 1 million elements. Sure, we could minimize
  this, but then this would make the caller's code much more cumbersome.
  
  This also means that you cannot use this filter to track more than
  one data set; as data will be hopelessly intermingled. If you want
  to filter something else, create a new FixedLagSmoother object.
  
  Parameters
  ----------
  
  z : ndarray or scalar
      measurement to be smoothed
  
  
  u : ndarray, optional
      If provided, control input to the filter
docstr_tok: ["Smooths","the","measurement","using","a","fixed","lag","smoother",".","On","return",",","self.xSmooth","is","populated","with","the","N","previous","smoothed","estimates",",","where","self.xSmooth","[","k","]","is","the","kth","time","step",".","self.x","merely","contains","the","current","Kalman","filter","output","of","the","most","recent","measurement",",","and","is","not","smoothed","at","all","(","beyond","the","normal","Kalman","filter","processing",")",".","self.xSmooth","grows","in","length","on","each","call",".","If","you","run","this","1","million","times",",","it","will","contain","1","million","elements",".","Sure",",","we","could","minimize","this",",","but","then","this","would","make","the","caller","'s","code","much","more","cumbersome",".","This","also","means","that","you","can","not","use","this","filter","to","track","more","than","one","data","set",";","as","data","will","be","hopelessly","intermingled",".","If","you","want","to","filter","something","else",",","create","a","new","FixedLagSmoother","object",".","Parameters","--","--","--","--","--","z",":","ndarray","or","scalar","measurement","to","be","smoothed","u",":","ndarray",",","optional","If","provided",",","control","input","to","the","filter"]
code: def smooth(self, z, u=None):
      """Smooths the measurement using a fixed lag smoother.
  
      On return, self.xSmooth is populated with the N previous smoothed
      estimates,  where self.xSmooth[k] is the kth time step. self.x
      merely contains the current Kalman filter output of the most recent
      measurement, and is not smoothed at all (beyond the normal Kalman
      filter processing).
  
      self.xSmooth grows in length on each call. If you run this 1 million
      times, it will contain 1 million elements. Sure, we could minimize
      this, but then this would make the caller's code much more cumbersome.
  
      This also means that you cannot use this filter to track more than
      one data set; as data will be hopelessly intermingled. If you want
      to filter something else, create a new FixedLagSmoother object.
  
      Parameters
      ----------
  
      z : ndarray or scalar
          measurement to be smoothed
  
  
      u : ndarray, optional
          If provided, control input to the 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
      N = self.N
  
      k = self.count
  
      # predict step of normal Kalman filter
      x_pre = dot(F, x)
      if u is not None:
          x_pre += dot(B, u)
  
      P = dot(F, P).dot(F.T) + Q
  
      # update step of normal Kalman filter
      self.y = z - dot(H, x_pre)
  
      self.S = dot(H, P).dot(H.T) + R
      SI = inv(self.S)
  
      K = dot(P, H.T).dot(SI)
  
      x = x_pre + dot(K, self.y)
  
      I_KH = self._I - dot(K, H)
      P = dot(I_KH, P).dot(I_KH.T) + dot(K, R).dot(K.T)
  
      self.xSmooth.append(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
              self.xSmooth[si] = self.xSmooth[si] + dot(K, self.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.
          self.xSmooth[k] = x.copy()
  
      self.count += 1
      self.x = x
      self.P = P
  
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 2 for calling the FixedLagSmoother obj's underlying member method code with example usage: obj.smooth(z, u) without return types