Modify SquaredMahalanobis __call__ to accept a 2D state_vector in state2#1272
Modify SquaredMahalanobis __call__ to accept a 2D state_vector in state2#1272
Conversation
Modify SquaredMahalanobis __call__ to accept a 2D state_vector in state2
|
Looking at this again this morning, I see that |
sdhiscocks
left a comment
There was a problem hiding this comment.
Thanks @ajland.
Maybe we wont worry about (n, m) + (n, m) case for now, as you say it's more complex.
Some test failures here, but that's because test too strictly checking floats are equal. Using pytest.approx should fix that (patch below).
It would be good to get a new test that also checks the new case of state2.state_vector being (n, m)
diff --git i/stonesoup/measures/tests/test_state.py w/stonesoup/measures/tests/test_state.py
index 8a6887e5..4af68565 100644
--- i/stonesoup/measures/tests/test_state.py
+++ w/stonesoup/measures/tests/test_state.py
@@ -48,9 +48,9 @@ def test_euclideanweighted():
def test_mahalanobis():
measure = measures.Mahalanobis()
- assert measure(state_u, state_v) == distance.mahalanobis(u[:, 0],
- v[:, 0],
- np.linalg.inv(ui))
+ assert measure(state_u, state_v) == pytest.approx(distance.mahalanobis(u[:, 0],
+ v[:, 0],
+ np.linalg.inv(ui)))
def test_hellinger():
@@ -141,13 +141,13 @@ def test_hellinger_partial_mapping(mapping_type):
def test_mahalanobis_full_mapping(mapping_type):
mapping = mapping_type(np.arange(len(u)))
measure = measures.Mahalanobis(mapping=mapping)
- assert measure(state_u, state_v) == distance.mahalanobis(u[:, 0],
- v[:, 0],
- np.linalg.inv(ui))
+ assert measure(state_u, state_v) == pytest.approx(distance.mahalanobis(u[:, 0],
+ v[:, 0],
+ np.linalg.inv(ui)))
measure = measures.Mahalanobis(mapping=mapping, mapping2=mapping)
- assert measure(state_u, state_v) == distance.mahalanobis(u[:, 0],
- v[:, 0],
- np.linalg.inv(ui))
+ assert measure(state_u, state_v) == pytest.approx(distance.mahalanobis(u[:, 0],
+ v[:, 0],
+ np.linalg.inv(ui)))
def test_mahalanobis_partial_mapping(mapping_type):|
Added the following to address the requests and errors:
|
This PR is based on this exchange: #1226 (comment)
The idea is to expand SquaredMahalanobis to compute one-to-many distances instead of the original one-to-one distance.
Original interface:
state1.state_vectorhas shape (n, 1)state2.state_vectorhas shape (n, 1)New interface:
state1.state_vectorhas shape (n, 1)state2.state_vectorhas shape (n, m)In the original exchange, @sdhiscocks said we should also consider an (n, m) + (n, m) case. This is a possibility, but I was not sure how to implement this given that a
GaussianStatecannot have its seconds axis >1 due to the limitations ofStateVector. Please advise on this latter point.