Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type checking for model_list in CombinedGaussianTransitionModel #1020

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)