class_docstr: Implements the Scaled Unscented Kalman filter (UKF) as defined by
  Simon Julier in [1], using the formulation provided by Wan and Merle
  in [2]. This filter scales the sigma points to avoid strong nonlinearities.
  
  
  You will have to set the following attributes after constructing this
  object for the filter to perform properly.
  
  Attributes
  ----------
  
  x : numpy.array(dim_x)
      state estimate vector
  
  P : numpy.array(dim_x, dim_x)
      covariance estimate matrix
  
  R : numpy.array(dim_z, dim_z)
      measurement noise matrix
  
  Q : numpy.array(dim_x, dim_x)
      process noise matrix
  
  
  You may read the following attributes.
  
  Readable Attributes
  -------------------
  
  
  K : numpy.array
      Kalman gain
  
  y : numpy.array
      innovation residual
  
  x : numpy.array(dim_x)
      predicted/updated state (result of predict()/update())
  
  P : numpy.array(dim_x, dim_x)
      predicted/updated covariance matrix (result of predict()/update())
  
  likelihood : scalar
      Likelihood of last measurement update.
  
  log_likelihood : scalar
      Log likelihood of last measurement update.
  
  
  References
  ----------
  
  .. [1] Julier, Simon J. "The scaled unscented transformation,"
      American Control Converence, 2002, pp 4555-4559, vol 6.
  
      Online copy:
      https://www.cs.unc.edu/~welch/kalman/media/pdf/ACC02-IEEE1357.PDF
  
  
  .. [2] E. A. Wan and R. Van der Merwe, “The unscented Kalman filter for
      nonlinear estimation,” in Proc. Symp. Adaptive Syst. Signal
      Process., Commun. Contr., Lake Louise, AB, Canada, Oct. 2000.
  
      Online Copy:
      https://www.seas.harvard.edu/courses/cs281/papers/unscented.pdf
class_docstr_tok: ["Implements","the","Scaled","Unscented","Kalman","filter","(","UKF",")","as","defined","by","Simon","Julier","in","[","1","]",",","using","the","formulation","provided","by","Wan","and","Merle","in","[","2","]",".","This","filter","scales","the","sigma","points","to","avoid","strong","nonlinearities",".","You","will","have","to","set","the","following","attributes","after","constructing","this","object","for","the","filter","to","perform","properly",".","Attributes","--","--","--","--","--","x",":","numpy.array","(","dim_x",")","state","estimate","vector","P",":","numpy.array","(","dim_x",",","dim_x",")","covariance","estimate","matrix","R",":","numpy.array","(","dim_z",",","dim_z",")","measurement","noise","matrix","Q",":","numpy.array","(","dim_x",",","dim_x",")","process","noise","matrix","You","may","read","the","following","attributes",".","Readable","Attributes","--","--","--","--","--","--","--","--","--","-","K",":","numpy.array","Kalman","gain","y",":","numpy.array","innovation","residual","x",":","numpy.array","(","dim_x",")","predicted\/updated","state","(","result","of","predict","(",")","\/update","(",")",")","P",":","numpy.array","(","dim_x",",","dim_x",")","predicted\/updated","covariance","matrix","(","result","of","predict","(",")","\/update","(",")",")","likelihood",":","scalar","Likelihood","of","last","measurement","update",".","log_likelihood",":","scalar","Log","likelihood","of","last","measurement","update",".","References","--","--","--","--","--","..","[","1","]","Julier",",","Simon","J",".","``","The","scaled","unscented","transformation",",","''","American","Control","Converence",",","2002",",","pp","4555-4559",",","vol","6",".","Online","copy",":","https",":","\/\/www.cs.unc.edu\/~welch\/kalman\/media\/pdf\/ACC02-IEEE1357.PDF","..","[","2","]","E.","A.","Wan","and","R.","Van","der","Merwe",",","\u201c","The","unscented","Kalman","filter","for","nonlinear","estimation",",","\u201d","in","Proc",".","Symp",".","Adaptive","Syst",".","Signal","Process.",",","Commun",".","Contr.",",","Lake","Louise",",","AB",",","Canada",",","Oct.","2000",".","Online","Copy",":","https",":","\/\/www.seas.harvard.edu\/courses\/cs281\/papers\/unscented.pdf"]
docstr: Create a Kalman filter. 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 filter. For example, if
      you are tracking the position and velocity of an object in two
      dimensions, dim_x would be 4.
  
  
  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.
  
  dt : float
      Time between steps in seconds.
  
  hx : function(x)
      Measurement function. Converts state vector x into a measurement
      vector of shape (dim_z).
  
  fx : function(x,dt)
      function that returns the state x transformed by the
      state transition function. dt is the time step in seconds.
  
  points : class
      Class which computes the sigma points and weights for a UKF
      algorithm. You can vary the UKF implementation by changing this
      class. For example, MerweScaledSigmaPoints implements the alpha,
      beta, kappa parameterization of Van der Merwe, and
      JulierSigmaPoints implements Julier's original kappa
      parameterization. See either of those for the required
      signature of this class if you want to implement your own.
  
  sqrt_fn : callable(ndarray), default = scipy.linalg.cholesky
      Defines how we compute the square root of a matrix, which has
      no unique answer. Cholesky is the default choice due to its
      speed. Typically your alternative choice will be
      scipy.linalg.sqrtm. Different choices affect how the sigma points
      are arranged relative to the eigenvectors of the covariance matrix.
      Usually this will not matter to you; if so the default cholesky()
      yields maximal performance. As of van der Merwe's dissertation of
      2004 [6] this was not a well reseached area so I have no advice
      to give you.
  
      If your method returns a triangular matrix it must be upper
      triangular. Do not use numpy.linalg.cholesky - for historical
      reasons it returns a lower triangular matrix. The SciPy version
      does the right thing.
  
  x_mean_fn : callable  (sigma_points, weights), optional
      Function that computes the mean of the provided sigma points
      and weights. Use this if your state variable contains nonlinear
      values such as angles which cannot be summed.
  
      .. code-block:: Python
  
          def state_mean(sigmas, Wm):
              x = np.zeros(3)
              sum_sin, sum_cos = 0., 0.
  
              for i in range(len(sigmas)):
                  s = sigmas[i]
                  x[0] += s[0] * Wm[i]
                  x[1] += s[1] * Wm[i]
                  sum_sin += sin(s[2])*Wm[i]
                  sum_cos += cos(s[2])*Wm[i]
              x[2] = atan2(sum_sin, sum_cos)
              return x
  
  z_mean_fn : callable  (sigma_points, weights), optional
      Same as x_mean_fn, except it is called for sigma points which
      form the measurements after being passed through hx().
  
  residual_x : callable (x, y), optional
  residual_z : callable (x, y), optional
      Function that computes the residual (difference) between x and y.
      You will have to supply this if your state variable cannot support
      subtraction, such as angles (359-1 degreees is 2, not 358). x and y
      are state vectors, not scalars. One is for the state variable,
      the other is for the measurement state.
  
      .. code-block:: Python
  
          def residual(a, b):
              y = a[0] - b[0]
              if y > np.pi:
                  y -= 2*np.pi
              if y < -np.pi:
                  y = 2*np.pi
              return y
  
  
  References
  ----------
  
  .. [3] S. Julier, J. Uhlmann, and H. Durrant-Whyte. "A new method for
         the nonlinear transformation of means and covariances in filters
         and estimators," IEEE Transactions on Automatic Control, 45(3),
         pp. 477-482 (March 2000).
  
  .. [4] E. A. Wan and R. Van der Merwe, “The Unscented Kalman filter for
         Nonlinear Estimation,” in Proc. Symp. Adaptive Syst. Signal
         Process., Commun. Contr., Lake Louise, AB, Canada, Oct. 2000.
  
         https://www.seas.harvard.edu/courses/cs281/papers/unscented.pdf
  
  .. [5] Wan, Merle "The Unscented Kalman Filter," chapter in *Kalman
         Filtering and Neural Networks*, John Wiley & Sons, Inc., 2001.
  
  .. [6] R. Van der Merwe "Sigma-Point Kalman Filters for Probabilitic
         Inference in Dynamic State-Space Models" (Doctoral dissertation)
docstr_tok: ["Create","a","Kalman","filter",".","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","filter",".","For","example",",","if","you","are","tracking","the","position","and","velocity","of","an","object","in","two","dimensions",",","dim_x","would","be","4.","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.","dt",":","float","Time","between","steps","in","seconds",".","hx",":","function","(","x",")","Measurement","function",".","Converts","state","vector","x","into","a","measurement","vector","of","shape","(","dim_z",")",".","fx",":","function","(","x",",","dt",")","function","that","returns","the","state","x","transformed","by","the","state","transition","function",".","dt","is","the","time","step","in","seconds",".","points",":","class","Class","which","computes","the","sigma","points","and","weights","for","a","UKF","algorithm",".","You","can","vary","the","UKF","implementation","by","changing","this","class",".","For","example",",","MerweScaledSigmaPoints","implements","the","alpha",",","beta",",","kappa","parameterization","of","Van","der","Merwe",",","and","JulierSigmaPoints","implements","Julier","'s","original","kappa","parameterization",".","See","either","of","those","for","the","required","signature","of","this","class","if","you","want","to","implement","your","own",".","sqrt_fn",":","callable","(","ndarray",")",",","default","=","scipy.linalg.cholesky","Defines","how","we","compute","the","square","root","of","a","matrix",",","which","has","no","unique","answer",".","Cholesky","is","the","default","choice","due","to","its","speed",".","Typically","your","alternative","choice","will","be","scipy.linalg.sqrtm",".","Different","choices","affect","how","the","sigma","points","are","arranged","relative","to","the","eigenvectors","of","the","covariance","matrix",".","Usually","this","will","not","matter","to","you",";","if","so","the","default","cholesky","(",")","yields","maximal","performance",".","As","of","van","der","Merwe","'s","dissertation","of","2004","[","6","]","this","was","not","a","well","reseached","area","so","I","have","no","advice","to","give","you",".","If","your","method","returns","a","triangular","matrix","it","must","be","upper","triangular",".","Do","not","use","numpy.linalg.cholesky","-","for","historical","reasons","it","returns","a","lower","triangular","matrix",".","The","SciPy","version","does","the","right","thing",".","x_mean_fn",":","callable","(","sigma_points",",","weights",")",",","optional","Function","that","computes","the","mean","of","the","provided","sigma","points","and","weights",".","Use","this","if","your","state","variable","contains","nonlinear","values","such","as","angles","which","can","not","be","summed",".","..","code-block",":",":","Python","def","state_mean","(","sigmas",",","Wm",")",":","x","=","np.zeros","(","3",")","sum_sin",",","sum_cos","=","0.",",","0.","for","i","in","range","(","len","(","sigmas",")",")",":","s","=","sigmas","[","i","]","x","[","0","]","+=","s","[","0","]","*","Wm","[","i","]","x","[","1","]","+=","s","[","1","]","*","Wm","[","i","]","sum_sin","+=","sin","(","s","[","2","]",")","*","Wm","[","i","]","sum_cos","+=","cos","(","s","[","2","]",")","*","Wm","[","i","]","x","[","2","]","=","atan2","(","sum_sin",",","sum_cos",")","return","x","z_mean_fn",":","callable","(","sigma_points",",","weights",")",",","optional","Same","as","x_mean_fn",",","except","it","is","called","for","sigma","points","which","form","the","measurements","after","being","passed","through","hx","(",")",".","residual_x",":","callable","(","x",",","y",")",",","optional","residual_z",":","callable","(","x",",","y",")",",","optional","Function","that","computes","the","residual","(","difference",")","between","x","and","y",".","You","will","have","to","supply","this","if","your","state","variable","can","not","support","subtraction",",","such","as","angles","(","359-1","degreees","is","2",",","not","358",")",".","x","and","y","are","state","vectors",",","not","scalars",".","One","is","for","the","state","variable",",","the","other","is","for","the","measurement","state",".","..","code-block",":",":","Python","def","residual","(","a",",","b",")",":","y","=","a","[","0","]","-","b","[","0","]","if","y",">","np.pi",":","y","-=","2","*","np.pi","if","y","<","-np.pi",":","y","=","2","*","np.pi","return","y","References","--","--","--","--","--","..","[","3","]","S.","Julier",",","J.","Uhlmann",",","and","H.","Durrant-Whyte",".","``","A","new","method","for","the","nonlinear","transformation","of","means","and","covariances","in","filters","and","estimators",",","''","IEEE","Transactions","on","Automatic","Control",",","45","(","3",")",",","pp",".","477-482","(","March","2000",")",".","..","[","4","]","E.","A.","Wan","and","R.","Van","der","Merwe",",","\u201c","The","Unscented","Kalman","filter","for","Nonlinear","Estimation",",","\u201d","in","Proc",".","Symp",".","Adaptive","Syst",".","Signal","Process.",",","Commun",".","Contr.",",","Lake","Louise",",","AB",",","Canada",",","Oct.","2000.","https",":","\/\/www.seas.harvard.edu\/courses\/cs281\/papers\/unscented.pdf","..","[","5","]","Wan",",","Merle","``","The","Unscented","Kalman","Filter",",","''","chapter","in","*","Kalman","Filtering","and","Neural","Networks","*",",","John","Wiley","&","Sons",",","Inc.",",","2001",".","..","[","6","]","R.","Van","der","Merwe","``","Sigma-Point","Kalman","Filters","for","Probabilitic","Inference","in","Dynamic","State-Space","Models","''","(","Doctoral","dissertation",")"]
code: def __init__(
      self,
      dim_x,
      dim_z,
      dt,
      hx,
      fx,
      points,
      sqrt_fn=None,
      x_mean_fn=None,
      z_mean_fn=None,
      residual_x=None,
      residual_z=None,
  ):
      r"""Create a Kalman filter. 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 filter. For example, if
          you are tracking the position and velocity of an object in two
          dimensions, dim_x would be 4.
  
  
      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.
  
      dt : float
          Time between steps in seconds.
  
      hx : function(x)
          Measurement function. Converts state vector x into a measurement
          vector of shape (dim_z).
  
      fx : function(x,dt)
          function that returns the state x transformed by the
          state transition function. dt is the time step in seconds.
  
      points : class
          Class which computes the sigma points and weights for a UKF
          algorithm. You can vary the UKF implementation by changing this
          class. For example, MerweScaledSigmaPoints implements the alpha,
          beta, kappa parameterization of Van der Merwe, and
          JulierSigmaPoints implements Julier's original kappa
          parameterization. See either of those for the required
          signature of this class if you want to implement your own.
  
      sqrt_fn : callable(ndarray), default = scipy.linalg.cholesky
          Defines how we compute the square root of a matrix, which has
          no unique answer. Cholesky is the default choice due to its
          speed. Typically your alternative choice will be
          scipy.linalg.sqrtm. Different choices affect how the sigma points
          are arranged relative to the eigenvectors of the covariance matrix.
          Usually this will not matter to you; if so the default cholesky()
          yields maximal performance. As of van der Merwe's dissertation of
          2004 [6] this was not a well reseached area so I have no advice
          to give you.
  
          If your method returns a triangular matrix it must be upper
          triangular. Do not use numpy.linalg.cholesky - for historical
          reasons it returns a lower triangular matrix. The SciPy version
          does the right thing.
  
      x_mean_fn : callable  (sigma_points, weights), optional
          Function that computes the mean of the provided sigma points
          and weights. Use this if your state variable contains nonlinear
          values such as angles which cannot be summed.
  
          .. code-block:: Python
  
              def state_mean(sigmas, Wm):
                  x = np.zeros(3)
                  sum_sin, sum_cos = 0., 0.
  
                  for i in range(len(sigmas)):
                      s = sigmas[i]
                      x[0] += s[0] * Wm[i]
                      x[1] += s[1] * Wm[i]
                      sum_sin += sin(s[2])*Wm[i]
                      sum_cos += cos(s[2])*Wm[i]
                  x[2] = atan2(sum_sin, sum_cos)
                  return x
  
      z_mean_fn : callable  (sigma_points, weights), optional
          Same as x_mean_fn, except it is called for sigma points which
          form the measurements after being passed through hx().
  
      residual_x : callable (x, y), optional
      residual_z : callable (x, y), optional
          Function that computes the residual (difference) between x and y.
          You will have to supply this if your state variable cannot support
          subtraction, such as angles (359-1 degreees is 2, not 358). x and y
          are state vectors, not scalars. One is for the state variable,
          the other is for the measurement state.
  
          .. code-block:: Python
  
              def residual(a, b):
                  y = a[0] - b[0]
                  if y > np.pi:
                      y -= 2*np.pi
                  if y < -np.pi:
                      y = 2*np.pi
                  return y
  
  
      References
      ----------
  
      .. [3] S. Julier, J. Uhlmann, and H. Durrant-Whyte. "A new method for
             the nonlinear transformation of means and covariances in filters
             and estimators," IEEE Transactions on Automatic Control, 45(3),
             pp. 477-482 (March 2000).
  
      .. [4] E. A. Wan and R. Van der Merwe, “The Unscented Kalman filter for
             Nonlinear Estimation,” in Proc. Symp. Adaptive Syst. Signal
             Process., Commun. Contr., Lake Louise, AB, Canada, Oct. 2000.
  
             https://www.seas.harvard.edu/courses/cs281/papers/unscented.pdf
  
      .. [5] Wan, Merle "The Unscented Kalman Filter," chapter in *Kalman
             Filtering and Neural Networks*, John Wiley & Sons, Inc., 2001.
  
      .. [6] R. Van der Merwe "Sigma-Point Kalman Filters for Probabilitic
             Inference in Dynamic State-Space Models" (Doctoral dissertation)
      """
  
      self.Q = eye(dim_x)
      self.R = eye(dim_z)
      self.x = zeros(dim_x)
      self.P = eye(dim_x)
      self._dim_x = dim_x
      self._dim_z = dim_z
      self.points_fn = points
      self._dt = dt
      self._num_sigmas = points.num_sigmas()
      self.hx = hx
      self.fx = fx
      self.x_mean = x_mean_fn
      self.z_mean = z_mean_fn
      self.log_likelihood = 0.0
  
      if sqrt_fn is None:
          self.msqrt = cholesky
      else:
          self.msqrt = sqrt_fn
  
      # weights for the means and covariances.
      self.Wm, self.Wc = self.points_fn.weights()
      self.Wm = self.Wm.reshape((-1, 1))
      self.Wc = self.Wc.reshape((-1, 1))
  
      if residual_x is None:
          self.residual_x = np.subtract
      else:
          self.residual_x = residual_x
  
      if residual_z is None:
          self.residual_z = np.subtract
      else:
          self.residual_z = residual_z
  
      # sigma points transformed through f(x) and h(x)
      # variables for efficiency so we don't recreate every update
  
      self.sigmas_f = zeros((self._dim_x, self._num_sigmas))
      self.sigmas_h = zeros((self._dim_z, self._num_sigmas))
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import matplotlib.pyplot
  import numpy.random
  from numpy.random import randn
  from numpy import asarray
  import numpy
  from filterpy.kalman import UnscentedKalmanFilter
  from filterpy.kalman import unscented_transform, MerweScaledSigmaPoints, JulierSigmaPoints, SimplexSigmaPoints
  from filterpy.common import Q_discrete_white_noise
  import filterpy.stats
  from math import cos, sin
  from filterpy.kalman import UnscentedKalmanFilter2
label_desc: Use image node_id 1 to create a new UnscentedKalmanFilter2 object from inherited base classes: object with example: obj = UnscentedKalmanFilter2(dim_x, dim_z, dt, hx, fx, points, sqrt_fn, x_mean_fn, z_mean_fn, residual_x, residual_z)