class_docstr: A simple Kalman filter for tracking bounding boxes in image space.
  
  The 8-dimensional state space
  
      x, y, a, h, vx, vy, va, vh
  
  contains the bounding box center position (x, y), aspect ratio a, height h,
  and their respective velocities.
  
  Object motion follows a constant velocity model. The bounding box location
  (x, y, a, h) is taken as direct observation of the state space (linear
  observation model).
class_docstr_tok: ["A","simple","Kalman","filter","for","tracking","bounding","boxes","in","image","space",".","The","8-dimensional","state","space","x",",","y",",","a",",","h",",","vx",",","vy",",","va",",","vh","contains","the","bounding","box","center","position","(","x",",","y",")",",","aspect","ratio","a",",","height","h",",","and","their","respective","velocities",".","Object","motion","follows","a","constant","velocity","model",".","The","bounding","box","location","(","x",",","y",",","a",",","h",")","is","taken","as","direct","observation","of","the","state","space","(","linear","observation","model",")","."]
docstr: Compute gating distance between state distribution and measurements.
  A suitable distance threshold can be obtained from `chi2inv95`. If
  `only_position` is False, the chi-square distribution has 4 degrees of
  freedom, otherwise 2.
  
  Args:
      mean (ndarray): Mean vector over the state distribution (8
          dimensional).
      covariance (ndarray): Covariance of the state distribution (8x8
          dimensional).
      measurements (ndarray): An Nx4 dimensional matrix of N measurements,
          each in format (x, y, a, h) where (x, y) is the bounding box center
          position, a the aspect ratio, and h the height.
      only_position (Optional[bool]): If True, distance computation is 
          done with respect to the bounding box center position only.
      metric (str): Metric type, 'gaussian' or 'maha'.
  
  Returns
      An array of length N, where the i-th element contains the squared
      Mahalanobis distance between (mean, covariance) and `measurements[i]`.
docstr_tok: ["Compute","gating","distance","between","state","distribution","and","measurements",".","A","suitable","distance","threshold","can","be","obtained","from","`","chi2inv95","`",".","If","`","only_position","`","is","False",",","the","chi-square","distribution","has","4","degrees","of","freedom",",","otherwise","2",".","Args",":","mean","(","ndarray",")",":","Mean","vector","over","the","state","distribution","(","8","dimensional",")",".","covariance","(","ndarray",")",":","Covariance","of","the","state","distribution","(","8x8","dimensional",")",".","measurements","(","ndarray",")",":","An","Nx4","dimensional","matrix","of","N","measurements",",","each","in","format","(","x",",","y",",","a",",","h",")","where","(","x",",","y",")","is","the","bounding","box","center","position",",","a","the","aspect","ratio",",","and","h","the","height",".","only_position","(","Optional","[","bool","]",")",":","If","True",",","distance","computation","is","done","with","respect","to","the","bounding","box","center","position","only",".","metric","(","str",")",":","Metric","type",",","'gaussian","'","or","'maha","'",".","Returns","An","array","of","length","N",",","where","the","i-th","element","contains","the","squared","Mahalanobis","distance","between","(","mean",",","covariance",")","and","`","measurements","[","i","]","`","."]
code: def gating_distance(
      self,
      mean,
      covariance,
      measurements,
      only_position=False,
      metric="maha",
  ):
      """
      Compute gating distance between state distribution and measurements.
      A suitable distance threshold can be obtained from `chi2inv95`. If
      `only_position` is False, the chi-square distribution has 4 degrees of
      freedom, otherwise 2.
  
      Args:
          mean (ndarray): Mean vector over the state distribution (8
              dimensional).
          covariance (ndarray): Covariance of the state distribution (8x8
              dimensional).
          measurements (ndarray): An Nx4 dimensional matrix of N measurements,
              each in format (x, y, a, h) where (x, y) is the bounding box center
              position, a the aspect ratio, and h the height.
          only_position (Optional[bool]): If True, distance computation is
              done with respect to the bounding box center position only.
          metric (str): Metric type, 'gaussian' or 'maha'.
  
      Returns
          An array of length N, where the i-th element contains the squared
          Mahalanobis distance between (mean, covariance) and `measurements[i]`.
      """
      mean, covariance = self.project(mean, covariance)
      if only_position:
          mean, covariance = mean[:2], covariance[:2, :2]
          measurements = measurements[:, :2]
  
      d = measurements - mean
      if metric == "gaussian":
          return np.sum(d * d, axis=1)
      elif metric == "maha":
          cholesky_factor = np.linalg.cholesky(covariance)
          z = scipy.linalg.solve_triangular(
              cholesky_factor,
              d.T,
              lower=True,
              check_finite=False,
              overwrite_b=True,
          )
          squared_maha = np.sum(z * z, axis=0)
          return squared_maha
      else:
          raise ValueError("invalid distance metric")
  
file_path: PaddleDetection/ppdet/modeling/mot/motion/kalman_filter.py
imports: import numpy
  import scipy.linalg
label_desc: Use image node_id 7 for calling the KalmanFilter obj's underlying member method code with example usage: obj.gating_distance(mean, covariance, measurements, only_position, metric) and returns: np, squared_maha