Skip to content

Commit

Permalink
Added check for complex eignevalues or eigenvectors in uncertainity, …
Browse files Browse the repository at this point in the history
…plus added tests for it
  • Loading branch information
gawebb-dstl committed Oct 12, 2022
1 parent 8e2bb62 commit 0fa18c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stonesoup/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ def plot_tracks(self, tracks, mapping, uncertainty=False, particle=False, track_
HH = np.eye(track.ndim)[mapping, :] # Get position mapping matrix
for state in track:
w, v = np.linalg.eig(HH @ state.covar @ HH.T)
if np.iscomplexobj(w) or np.iscomplexobj(v):
warnings.warn("Can not plot uncertainty for all states due to complex "
"eignevalues or eigenvectors", UserWarning)
continue
max_ind = np.argmax(w)
min_ind = np.argmin(w)
orient = np.arctan2(v[1, max_ind], v[0, max_ind])
Expand Down
13 changes: 13 additions & 0 deletions stonesoup/tests/test_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,16 @@ def test_plot_density_equal_x_y():
timestamp=start_time + timedelta(seconds=k + 1)))
with pytest.raises(ValueError):
plotter.plot_density({truth}, index=None)


def test_plot_complex_uncertainty():
plotter = Plotter()
track = Track([
GaussianState(
state_vector=[0, 0],
covar=[[10, -1], [1, 10]])
])
with pytest.warns(UserWarning, match="Can not plot uncertainty for all states due to complex "
"eignevalues or eigenvectors"):

plotter.plot_tracks(track, mapping=[0, 1], uncertainty=True)

0 comments on commit 0fa18c9

Please sign in to comment.