dstl / Stone-Soup

A software project to provide the target tracking community with a framework for the development and testing of tracking algorithms.
https://stonesoup.rtfd.io
MIT License
406 stars 134 forks source link

Using a 1D measurement model noise covariance matrix doesn't produce an error message #754

Open gawebb-dstl opened 1 year ago

gawebb-dstl commented 1 year ago

I recently made a small mistake when creating the covariance matrix for a measurement model. I used: noise_covar=np.array([...]) which creates a 1D array instead of: noise_covar=np.diag([...]) which creates a 2D square array with values along the diagonal

Using the wrong covariance matrix doesn't produce any error messages. The detections are produced successfully with scipy.stats.multivariate_normal.rvs produces the same result with either input. However the measurement covariance matrix is used when tracking. It's used when calculating the innovation covariance. This doesn't produce an error message either but does give the wrong result. Which leads to really bad tracking.

To can observe this by changing line 130 in tutorial number 2.

Fortunately I spotted my error pretty quickly but I worry others might not spot it so quickly.

I have thought of some options:

  1. Do nothing. This was user error not a bug
  2. Cast the noise_covar value to a CovarianceMatrix when initialising a MeasurementModel. Using a 1D array would result in a ValueError being throw
  3. Add a warning if a 1D array is used in a measurement model
sdhiscocks commented 1 year ago

I think 2. is a good option.