Skip to content

Commit

Permalink
Merge pull request #1085 from dstl/dist_hyp_meas
Browse files Browse the repository at this point in the history
Make passing measurements in distance hypothesiser optional
  • Loading branch information
sdhiscocks authored Oct 7, 2024
2 parents a004fd9 + fc2adb2 commit 10b3ab7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
12 changes: 10 additions & 2 deletions stonesoup/hypothesiser/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class DistanceHypothesiser(Hypothesiser):
include_all: bool = Property(
default=False,
doc="If `True`, hypotheses beyond missed distance will be returned. Default `False`")
predict_with_measurements: bool = Property(
default=False,
doc="Whether to pass measurement/detection to the predictor. Default `False`"
)

def hypothesise(self, track, detections, timestamp, **kwargs):
""" Evaluate and return all track association hypotheses.
Expand Down Expand Up @@ -68,8 +72,12 @@ def hypothesise(self, track, detections, timestamp, **kwargs):
for detection in detections:

# Re-evaluate prediction
prediction = self.predictor.predict(
track, timestamp=detection.timestamp, measurement=detection, **kwargs)
if self.predict_with_measurements:
prediction = self.predictor.predict(
track, timestamp=detection.timestamp, measurement=detection, **kwargs)
else:
prediction = self.predictor.predict(
track, timestamp=detection.timestamp, **kwargs)

# Compute measurement prediction and distance measure
measurement_prediction = self.updater.predict_measurement(
Expand Down
7 changes: 5 additions & 2 deletions stonesoup/hypothesiser/tests/test_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime

import numpy as np
import pytest

from ..distance import DistanceHypothesiser
from ...types.detection import Detection
Expand All @@ -10,7 +11,8 @@
from ... import measures


def test_mahalanobis(predictor, updater):
@pytest.mark.parametrize('predict_with_measurements', [True, False])
def test_mahalanobis(predictor, updater, predict_with_measurements):

timestamp = datetime.datetime.now()
track = Track([GaussianState(np.array([[0]]), np.array([[1]]), timestamp)])
Expand All @@ -21,7 +23,8 @@ def test_mahalanobis(predictor, updater):

measure = measures.Mahalanobis()
hypothesiser = DistanceHypothesiser(
predictor, updater, measure=measure, missed_distance=3)
predictor, updater, measure=measure, missed_distance=3,
predict_with_measurements=predict_with_measurements)

hypotheses = hypothesiser.hypothesise(track, detections, timestamp)

Expand Down
2 changes: 2 additions & 0 deletions stonesoup/proposal/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class Proposal(Base):
@abstractmethod
def rvs(self, *args, **kwargs):
r"""Proposal noise/sample generation function
Generates samples from the proposal.
Parameters
----------
state: :class:`~.State`
Expand Down
20 changes: 15 additions & 5 deletions stonesoup/proposal/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ class PriorAsProposal(Proposal):
def rvs(self, prior: State, measurement=None, time_interval=None,
**kwargs) -> Union[StateVector, StateVectors]:
"""Generate samples from the proposal.
Parameters
----------
state: :class:`~.State`
The state to generate samples from.
measurement: :class:`~.Detection`
the measurement that will preferably used to get time interval
if provided(the default is `None`)
time_interval: :class:`datetime.time_delta`
time interval of the prediction is needed to propagate the states
Returns
-------
: :class:`~.ParticlePrediction` with samples drawn from the updated proposal
: :class:`~.ParticlePrediction`
State with samples drawn from the updated proposal
"""

if measurement is not None:
Expand All @@ -55,7 +62,7 @@ def rvs(self, prior: State, measurement=None, time_interval=None,


class KFasProposal(Proposal):
"""This proposal uses the kalman filter prediction and update steps to
"""This proposal uses the Kalman filter prediction and update steps to
generate new set of particles and weights
"""
predictor: Predictor = Property(
Expand All @@ -66,20 +73,23 @@ class KFasProposal(Proposal):
def rvs(self, prior: State, measurement: Detection = None, time_interval=None,
**kwargs):
"""Generate samples from the proposal.
Use the kalman filter predictor and updater to create a new distribution
Use the Kalman filter predictor and updater to create a new distribution
Parameters
----------
state: :class:`~.State`
The state to generate samples from.
measurement: :class:`~.Detection`
the measurement that is used in the update step of the kalman prediction,
the measurement that is used in the update step of the Kalman prediction,
(the default is `None`)
time_interval: :class:`datetime.time_delta`
time interval of the prediction is needed to propagate the states
Returns
-------
: :class:`~.ParticlePrediction`
State with samples drawn from the updated proposal
"""

if measurement is not None:
Expand Down

0 comments on commit 10b3ab7

Please sign in to comment.