ByteTrack icon indicating copy to clipboard operation
ByteTrack copied to clipboard

About covariance matrix computation in Kalman Filter

Open jawonseojw opened this issue 1 year ago • 2 comments

def update(self, mean, covariance, measurement):
    """Run Kalman filter correction step.

    Parameters
    ----------
    mean : ndarray
        The predicted state's mean vector (8 dimensional).
    covariance : ndarray
        The state's covariance matrix (8x8 dimensional).
    measurement : ndarray
        The 4 dimensional measurement vector (x, y, a, h), where (x, y)
        is the center position, a the aspect ratio, and h the height of the
        bounding box.

    Returns
    -------
    (ndarray, ndarray)
        Returns the measurement-corrected state distribution.

    """
    projected_mean, projected_cov = self.project(mean, covariance)

    chol_factor, lower = scipy.linalg.cho_factor(
        projected_cov, lower=True, check_finite=False)
    kalman_gain = scipy.linalg.cho_solve(
        (chol_factor, lower), np.dot(covariance, self._update_mat.T).T,
        check_finite=False).T
    innovation = measurement - projected_mean

    new_mean = mean + np.dot(innovation, kalman_gain.T)
    new_covariance = covariance - np.linalg.multi_dot((
        kalman_gain, projected_cov, kalman_gain.T))
    return new_mean, new_covariance

I'm wondering whether the computation of the new covariance matrix is right or not. i.e., new_covariance = covariance - np.linalg.multi_dot(( kalman_gain, projected_cov, kalman_gain.T))

Actually, it should be P' = P - KHP, where P is covariance matrix, K is Kalman gain, and H is projection matrix to measurement space.

jawonseojw avatar Jul 26 '23 09:07 jawonseojw

Hi, have you figured this out yet?

fxyQAQ avatar Aug 08 '23 06:08 fxyQAQ

Hi, have anyone tried this? It should improve tracking results As I understands from the question, it should be: new_covariance = covariance - np.linalg.multi_dot(( kalman_gain, projected_cov, covariance ))

egSat avatar Mar 04 '24 12:03 egSat