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.
  
  
  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.
  
      This is for convience, so everything is sized correctly on
      creation. If you are using multiple sensors the size of `z` can
      change based on the sensor. Just provide the appropriate hx function
  
  
  dt : float
      Time between steps in seconds.
  
  
  
  hx : function(x,**hx_args)
      Measurement function. Converts state vector x into a measurement
      vector of shape (dim_z).
  
  fx : function(x,dt,**fx_args)
      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=None (implies 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 as far as this class is concerned.
  
  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
  
  state_add: callable (x, y), optional, default np.add
      Function that subtracts two state vectors, returning a new
      state vector. Used during update to compute `x + K@y`
      You will have to supply this if your state variable does not
      suport addition, such as it contains angles.
  
  Attributes
  ----------
  
  x : numpy.array(dim_x)
      state estimate vector
  
  P : numpy.array(dim_x, dim_x)
      covariance estimate matrix
  
  x_prior : numpy.array(dim_x)
      Prior (predicted) state estimate. The *_prior and *_post attributes
      are for convienence; they store the  prior and posterior of the
      current epoch. Read Only.
  
  P_prior : numpy.array(dim_x, dim_x)
      Prior (predicted) state covariance matrix. Read Only.
  
  x_post : numpy.array(dim_x)
      Posterior (updated) state estimate. Read Only.
  
  P_post : numpy.array(dim_x, dim_x)
      Posterior (updated) state covariance matrix. Read Only.
  
  z : ndarray
      Last measurement used in update(). Read only.
  
  R : numpy.array(dim_z, dim_z)
      measurement noise matrix
  
  Q : numpy.array(dim_x, dim_x)
      process noise matrix
  
  K : numpy.array
      Kalman gain
  
  y : numpy.array
      innovation residual
  
  log_likelihood : scalar
      Log likelihood of last measurement update.
  
  likelihood : float
      likelihood of last measurment. Read only.
  
      Computed from the log-likelihood. The log-likelihood can be very
      small,  meaning a large negative value such as -28000. Taking the
      exp() of that results in 0.0, which can break typical algorithms
      which multiply by this value, so by default we always return a
      number >= sys.float_info.min.
  
  mahalanobis : float
      mahalanobis distance of the measurement. Read only.
  
  inv : function, default numpy.linalg.inv
      If you prefer another inverse function, such as the Moore-Penrose
      pseudo inverse, set it to that instead:
  
      .. code-block:: Python
  
          kf.inv = np.linalg.pinv
  
  
  Examples
  --------
  
  Simple example of a linear order 1 kinematic filter in 2D. There is no
  need to use a UKF for this example, but it is easy to read.
  
  >>> def fx(x, dt):
  >>>     # state transition function - predict next state based
  >>>     # on constant velocity model x = vt + x_0
  >>>     F = np.array([[1, dt, 0, 0],
  >>>                   [0, 1, 0, 0],
  >>>                   [0, 0, 1, dt],
  >>>                   [0, 0, 0, 1]], dtype=float)
  >>>     return np.dot(F, x)
  >>>
  >>> def hx(x):
  >>>    # measurement function - convert state into a measurement
  >>>    # where measurements are [x_pos, y_pos]
  >>>    return np.array([x[0], x[2]])
  >>>
  >>> dt = 0.1
  >>> # create sigma points to use in the filter. This is standard for Gaussian processes
  >>> points = MerweScaledSigmaPoints(4, alpha=.1, beta=2., kappa=-1)
  >>>
  >>> kf = UnscentedKalmanFilter(dim_x=4, dim_z=2, dt=dt, fx=fx, hx=hx, points=points)
  >>> kf.x = np.array([-1., 1., -1., 1]) # initial state
  >>> kf.P *= 0.2 # initial uncertainty
  >>> z_std = 0.1
  >>> kf.R = np.diag([z_std**2, z_std**2]) # 1 standard
  >>> kf.Q = Q_discrete_white_noise(dim=2, dt=dt, var=0.01**2, block_size=2)
  >>>
  >>> zs = [[i+randn()*z_std, i+randn()*z_std] for i in range(50)] # measurements
  >>> for z in zs:
  >>>     kf.predict()
  >>>     kf.update(z)
  >>>     print(kf.x, 'log-likelihood', kf.log_likelihood)
  
  For in depth explanations see my book Kalman and Bayesian Filters in Python
  https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python
  
  Also see the filterpy/kalman/tests subdirectory for test code that
  may be illuminating.
  
  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
  
  .. [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: Computed from the log-likelihood. The log-likelihood can be very
  small,  meaning a large negative value such as -28000. Taking the
  exp() of that results in 0.0, which can break typical algorithms
  which multiply by this value, so by default we always return a
  number >= sys.float_info.min.
docstr_tok: ["Computed","from","the","log-likelihood",".","The","log-likelihood","can","be","very","small",",","meaning","a","large","negative","value","such","as","-28000",".","Taking","the","exp","(",")","of","that","results","in","0.0",",","which","can","break","typical","algorithms","which","multiply","by","this","value",",","so","by","default","we","always","return","a","number",">","=","sys.float_info.min","."]
code: def likelihood(self):
      """
      Computed from the log-likelihood. The log-likelihood can be very
      small,  meaning a large negative value such as -28000. Taking the
      exp() of that results in 0.0, which can break typical algorithms
      which multiply by this value, so by default we always return a
      number >= sys.float_info.min.
      """
      if self._likelihood is None:
          self._likelihood = exp(self.log_likelihood)
          if self._likelihood == 0:
              self._likelihood = sys.float_info.min
      return self._likelihood
  
imports: from __future__ import absolute_import, division
  from copy import deepcopy
  from math import log, exp, sqrt
  import sys
  import numpy
  from numpy import eye, zeros, dot, isscalar, outer
  from scipy.linalg import cholesky
  from filterpy.kalman import unscented_transform
  from filterpy.stats import logpdf
  from filterpy.common import pretty_str
label_desc: Use image node_id 9 for calling the UnscentedKalmanFilter obj's underlying member method code with example usage: obj.likelihood() and returns: self