narykov / 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
1 stars 1 forks source link

Getting IPLS working #1

Open mrcfon opened 3 months ago

mrcfon commented 3 months ago

IPLS breaks for not definite positive covariance matrix error using AE measurement model in scenarios with measurement gaps. The error happens at the second iteration of IPLS (the one after UKF smoother) because the results of UKF smoother are not good.

mrcfon commented 3 months ago

I tested the IPLS based on the UKF filter rather IPLF, but I got the same error just a few time steps later.

mrcfon commented 3 months ago

According to Angel:

mrcfon commented 3 months ago

The same error was encountered using AER.

mrcfon commented 2 months ago

Update: the error (Matrix is not positive definite) occurs using any measurement model (CartesianToElevationBearingRangeRate, CartesianToMonostatic, CartesianToTelescope) with measurement gaps.

mrcfon commented 2 months ago

I'm trying to understand why the IPLF and IPLS return weird results if I set q_value = 5e-9 (it was previously set to q = 0.02). I'm using the CartesianToElevationBearingRangeRate measurement model from the Stone Soup library at the moment. The code I'm using is available here. I tested a few things:

  1. The code returns the same results using the last version of Stone Soup (v 1.2+) or the one released in December.
  2. I plotted the angles and they look fine. Note that bearing is \in [0,90] degrees in the simulation. I also tried to add a small offset to elevation to ensure it's always positive, but I got similar results. elevation_bearing_deg_in_GODOT_1man

While I originally tested the scenario with a measurement gap, I simplified it assuming we receive a measurement at each time step. See the scenario below. scenario_no_gap

This is the result I get setting the number of iterations for IPLF to 5: res_IPLF_5iter

If I set the number of iterations for IPLF to 1 I get: res_IPLF_1iter This is the Euclidian distance of the algorithms in this case perf_IPLF_1iter

Iterating IPLF 5 times instead of just once brings down the error of IPLS from 1e15 to 1e8. I'll try to see what happens if I replace IPLF with one iteration with UFK from the Stone Soup library. Any other suggestions @narykov?

narykov commented 2 months ago

I plotted the angles and they look fine.

Are these the measurements you've generated? How about the predicted angles we discussed yesterday? Do they look OK?

I think there is no point looking into smoothing results because filtering does not look OK in Figure 3. The smoothing results also tend to obscure the plots, e.g., little can be said about the IPLF performance in the last plot.

mrcfon commented 1 month ago

I’m trying to understand why the second iteration of IPLS doesn’t run on the TLE scenarios with measurement gaps. It seems that the UKF smoother used in the first iteration of IPLS returns “bad“ covariance matrices, so the proper IPLS breaks due to a incorrect input. Here are some facts:

  1. UKF and IPLF with one iterarions are equivalent.
  2. Using UKF, the UKF smoother returns non positive definite covariance matrices at the end of the measurement gaps. The eigenvalues may look like: [-6.47835139e+08, 1.55118343e+08, -1.87036495e+08, 9.46675460e-01, 8.19938443e-01, 8.71217637e-01].
  3. The number of non positive definite covariance matrices at the end of the measurement gaps depends on q_value.
  4. The issues occurs regardless of whether a manoeuvre is present in the simulation, even if a manoeuvre makes the problem more evident/likely.
  5. IPLF with max_n_iter > 1 increases the chanses to have the UKF smoother returning non positive definite covariance matrices. Points 2 and 4 are concerning. In point 2, the only non-Stone Soup component in the process chain is the transition model (based on GODOT), and the ground truth generated with GODOT. UKF has force_symmetric_covariance=True. In point 4, symmetry of the Omega returned by the SLR function is enforced.

The next step would be to test the UKF smoother in a linear scenario (without GODOT) with measurement gaps. Any other suggestions?

mrcfon commented 1 month ago

IPLS may return errors at the second iteration (the first after UKF smoothing) even in a scenario with no measurement gaps. Note that there was a manoeuvre in this scenario. Here is the error: IPLS iteration 1 out of 2 IPLS iteration 2 out of 2 Traceback (most recent call last): File "/home/mrcfon/workspace/space_manoeuvres/stonesoup/space_manoeuvres/STT_noDA_GODOT_TLEs.py", line 201, in <module> main() File "/home/mrcfon/workspace/space_manoeuvres/stonesoup/space_manoeuvres/STT_noDA_GODOT_TLEs.py", line 163, in main track_ipls = IPLSKalmanSmoother(transition_model=transition_model, n_iterations=n_iterations_ipls).smooth( File "/home/mrcfon/workspace/space_manoeuvres/stonesoup/robusstod/stonesoup/smoother.py", line 137, in smooth smoothed_track = KalmanSmoother(transition_model=None).smooth(track_forward) # <- this triggers UKF?? File "/home/mrcfon/workspace/space_manoeuvres/stonesoup/smoother/kalman.py", line 183, in smooth ksmooth_gain = self._smooth_gain( File "/home/mrcfon/workspace/space_manoeuvres/stonesoup/smoother/kalman.py", line 150, in _smooth_gain @ np.linalg.inv(prediction.covar) File "/home/mrcfon/workspace/space_manoeuvres/myenv/lib/python3.10/site-packages/numpy/linalg/linalg.py", line 561, in inv ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj) File "/home/mrcfon/workspace/space_manoeuvres/myenv/lib/python3.10/site-packages/numpy/linalg/linalg.py", line 112, in _raise_linalgerror_singular raise LinAlgError("Singular matrix") numpy.linalg.LinAlgError: Singular matrix

narykov commented 1 month ago

Thanks for the update. Do you encounter this error despite changing how the measurement prediction works in the update step?