Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
: :class:`float`
The likelihood of ``state_vec_post``, given ``state_vec_prior``
"""
likelihood = multivariate_normal.pdf(
state_vector_post.T,
mean=self.function(state_vector_prior, noise=0, **kwargs).ravel(),
cov=self.covar(**kwargs)
)
return likelihood
class CombinedLinearGaussianTransitionModel(LinearGaussianTransitionModel):
r"""Combine multiple models into a single model by stacking them.
The assumption is that all models are Linear and Gaussian.
Time Variant, and Time Invariant models can be combined together.
If any of the models are time variant the keyword argument "time_interval"
must be supplied to all methods
"""
model_list = Property(
[LinearGaussianTransitionModel], doc="List of Transition Models.")
@property
def ndim_state(self):
"""ndim_state getter method
Returns
cov=self.covar(**kwargs)
)
return likelihood
class CombinedLinearGaussianTransitionModel(LinearGaussianTransitionModel):
r"""Combine multiple models into a single model by stacking them.
The assumption is that all models are Linear and Gaussian.
Time Variant, and Time Invariant models can be combined together.
If any of the models are time variant the keyword argument "time_interval"
must be supplied to all methods
"""
model_list = Property(
[LinearGaussianTransitionModel], doc="List of Transition Models.")
@property
def ndim_state(self):
"""ndim_state getter method
Returns
-------
: :class:`int`
The number of combined model state dimensions.
"""
return sum(model.ndim_state for model in self.model_list)
def matrix(self, **kwargs):
"""Model matrix :math:`F`
Returns
def covar(self, **kwargs):
"""Returns the transition model noise covariance matrix.
Returns
-------
: :class:`stonesoup.types.state.CovarianceMatrix` of shape\
(:py:attr:`~ndim_state`, :py:attr:`~ndim_state`)
The process noise covariance.
"""
covar_list = [model.covar(**kwargs) for model in self.model_list]
return block_diag(*covar_list)
class LinearGaussianTimeInvariantTransitionModel(LinearGaussianTransitionModel,
TimeInvariantModel):
r"""Generic Linear Gaussian Time Invariant Transition Model."""
transition_matrix = Property(
sp.ndarray, doc="Transition matrix :math:`\\mathbf{F}`.")
control_matrix = Property(
sp.ndarray, default=None, doc="Control matrix :math:`\\mathbf{B}`.")
covariance_matrix = Property(
sp.ndarray,
doc="Transition noise covariance matrix :math:`\\mathbf{Q}`.")
def matrix(self, **kwargs):
"""Model matrix :math:`F`
Returns
-------
def covar(self, **kwargs):
"""Returns the transition model noise covariance matrix.
Returns
-------
: :class:`stonesoup.types.state.CovarianceMatrix` of shape\
(:py:attr:`~ndim_state`, :py:attr:`~ndim_state`)
The process noise covariance.
"""
covar_list = [model.covar(**kwargs) for model in self.model_list]
return block_diag(*covar_list)
class LinearGaussianTimeInvariantTransitionModel(LinearGaussianTransitionModel,
TimeInvariantModel):
r"""Generic Linear Gaussian Time Invariant Transition Model."""
transition_matrix = Property(
sp.ndarray, doc="Transition matrix :math:`\\mathbf{F}`.")
control_matrix = Property(
sp.ndarray, default=None, doc="Control matrix :math:`\\mathbf{B}`.")
covariance_matrix = Property(
sp.ndarray,
doc="Transition noise covariance matrix :math:`\\mathbf{Q}`.")
def matrix(self, **kwargs):
"""Model matrix :math:`F`
Returns
-------
cov=self.covar(**kwargs)
)
return likelihood
class CombinedLinearGaussianTransitionModel(LinearGaussianTransitionModel):
r"""Combine multiple models into a single model by stacking them.
The assumption is that all models are Linear and Gaussian.
Time Variant, and Time Invariant models can be combined together.
If any of the models are time variant the keyword argument "time_interval"
must be supplied to all methods
"""
model_list = Property(
[LinearGaussianTransitionModel], doc="List of Transition Models.")
@property
def ndim_state(self):
"""ndim_state getter method
Returns
-------
: :class:`int`
The number of combined model state dimensions.
"""
return sum(model.ndim_state for model in self.model_list)
def matrix(self, **kwargs):
"""Model matrix :math:`F`
Returns
Notes
-----
In the Kalman filter, transition and control models must be linear.
Raises
------
ValueError
If no :class:`~.TransitionModel` is specified.
"""
transition_model = Property(
LinearGaussianTransitionModel,
doc="The transition model to be used.")
control_model = Property(
LinearControlModel,
default=None,
doc="The control model to be used. Default `None` where the predictor "
"will create a zero-effect linear :class:`~.ControlModel`.")
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# If no control model insert a linear zero-effect one
# TODO: Think about whether it's more efficient to leave this out
if self.control_model is None:
ndims = self.transition_model.ndim_state
self.control_model = LinearControlModel(ndims, [],
np.zeros([ndims, 1]),