Skip to content

Commit

Permalink
Merge pull request #1020 from dstl/cgtm
Browse files Browse the repository at this point in the history
Add type checking for model_list in CombinedGaussianTransitionModel

Resolves #1013
  • Loading branch information
sdhiscocks authored May 22, 2024
2 parents 3a7c10d + 295c39d commit 7be99ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions stonesoup/models/transition/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class CombinedGaussianTransitionModel(TransitionModel, GaussianModel):
"""
model_list: Sequence[GaussianModel] = Property(doc="List of Transition Models.")

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not isinstance(self.model_list, Sequence):
raise TypeError("model_list must be Sequence.")

def function(self, state, noise=False, **kwargs) -> StateVector:
"""Applies each transition model in :py:attr:`~model_list` in turn to the state's
corresponding state vector components.
Expand Down
15 changes: 14 additions & 1 deletion stonesoup/models/transition/tests/test_combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,22 @@ def test_nonlinear_combined(model_4):
time_interval=t_delta).shape
assert (DIM, 1) == combined_model.rvs(time_interval=t_delta).shape

# TODO: Figure out handling of pdf for non-linear models and singular convariance matrix
# TODO: Figure out handling of pdf for non-linear models and singular covariance matrix
# e.g. See Non-Linear Constant Turn model
# if isinstance(model_4,LinearModel):
assert isinstance(
combined_model.pdf(State(x_post), State(x_prior),
time_interval=t_delta), Real)


@pytest.mark.parametrize(
"model_list",
[
ConstantVelocity(noise_diff_coeff=1),
CombinedGaussianTransitionModel([ConstantVelocity(1)]),
None,
],
ids=["CV", "CGTM", "None"])
def test_model_list(model_list):
with pytest.raises(TypeError):
CombinedGaussianTransitionModel(model_list)

0 comments on commit 7be99ac

Please sign in to comment.