Transition Models¶
- class stonesoup.models.transition.base.TransitionModel[source]¶
Bases:
stonesoup.models.base.Model
Transition Model base class
- property ndim: int¶
Number of dimensions of model
- abstract property ndim_state: int¶
Number of state dimensions
Linear¶
- class stonesoup.models.transition.linear.LinearGaussianTransitionModel(seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.base.TransitionModel
,stonesoup.models.base.LinearModel
,stonesoup.models.base.GaussianModel
- Parameters
seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- property ndim_state¶
ndim_state getter method
- Returns
The number of model state dimensions.
- Return type
- abstract covar(**kwargs) stonesoup.types.array.CovarianceMatrix ¶
Model covariance
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- abstract matrix(**kwargs) numpy.ndarray ¶
Model matrix
- property ndim: int¶
Number of dimensions of model
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.CombinedLinearGaussianTransitionModel(model_list: Sequence[GaussianModel], seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.base.LinearModel
,stonesoup.models.transition.base._CombinedGaussianTransitionModel
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
- Parameters
model_list (
Sequence[GaussianModel]
) – List of Transition Models.seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- matrix(**kwargs)[source]¶
Model matrix \(F\)
- Returns
- Return type
numpy.ndarray
of shape (ndim_state
,ndim_state
)
- covar(**kwargs)¶
Returns the transition model noise covariance matrix.
- Returns
The process noise covariance.
- Return type
stonesoup.types.state.CovarianceMatrix
of shape (ndim_state
,ndim_state
)
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- model_list: Sequence[stonesoup.models.base.GaussianModel]¶
List of Transition Models.
- property ndim: int¶
Number of dimensions of model
- property ndim_state¶
ndim_state getter method
- Returns
The number of combined model state dimensions.
- Return type
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.LinearGaussianTimeInvariantTransitionModel(transition_matrix: numpy.ndarray, covariance_matrix: CovarianceMatrix, seed: Optional[int] = None, control_matrix: numpy.ndarray = None)[source]¶
Bases:
stonesoup.models.transition.linear.LinearGaussianTransitionModel
,stonesoup.models.base.TimeInvariantModel
Generic Linear Gaussian Time Invariant Transition Model.
- Parameters
transition_matrix (
numpy.ndarray
) – Transition matrix \(\mathbf{F}\).covariance_matrix (
CovarianceMatrix
) – Transition noise covariance matrix \(\mathbf{Q}\).seed (
Union[int, NoneType]
, optional) – Seed for random number generationcontrol_matrix (
numpy.ndarray
, optional) – Control matrix \(\mathbf{B}\).
- transition_matrix: numpy.ndarray¶
Transition matrix \(\mathbf{F}\).
- control_matrix: numpy.ndarray¶
Control matrix \(\mathbf{B}\).
- covariance_matrix: stonesoup.types.array.CovarianceMatrix¶
Transition noise covariance matrix \(\mathbf{Q}\).
- matrix(**kwargs)[source]¶
Model matrix \(F\)
- Returns
The model matrix evaluated given the provided time interval.
- Return type
numpy.ndarray
of shape (ndim_state
,ndim_state
)
- covar(**kwargs)[source]¶
Returns the transition model noise covariance matrix.
- Returns
The process noise covariance.
- Return type
stonesoup.types.state.CovarianceMatrix
of shape (ndim_state
,ndim_state
)
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- property ndim: int¶
Number of dimensions of model
- property ndim_state¶
ndim_state getter method
- Returns
The number of model state dimensions.
- Return type
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.ConstantNthDerivative(constant_derivative: int, noise_diff_coeff: float, seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.linear.LinearGaussianTransitionModel
,stonesoup.models.base.TimeVariantModel
Discrete model based on the Nth derivative with respect to time being constant, to set derivative use keyword argument
constant_derivative
The model is described by the following SDEs:
\begin{eqnarray} dx^{(N-1)} & = & x^{(N)} dt & | {(N-1)th \ derivative \ on \ X-axis (m)} \\ dx^{(N)} & = & q\cdot dW_t,\ W_t \sim \mathcal{N}(0,q^2) & | \ Nth\ derivative\ on\ X-axis (m/s^{N}) \end{eqnarray}It is hard to represent the matrix form of these due to the fact that they vary with N, examples for N=1 and N=2 can be found in the
ConstantVelocity
andConstantAcceleration
models respectively. To aid visualisation of \(F_t\) the elements are calculated as the terms of the taylor expansion of each state variable.- Parameters
constant_derivative (
int
) – The order of the derivative with respect to time to be kept constant, eg if 2 identical to constant accelerationnoise_diff_coeff (
float
) – The Nth derivative noise diffusion coefficient (Variance) \(q\)seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- constant_derivative: int¶
The order of the derivative with respect to time to be kept constant, eg if 2 identical to constant acceleration
- property ndim_state¶
ndim_state getter method
- Returns
The number of model state dimensions.
- Return type
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- property ndim: int¶
Number of dimensions of model
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.RandomWalk(noise_diff_coeff: float, seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.linear.ConstantNthDerivative
This is a class implementation of a discrete, time-variant 1D Linear-Gaussian Random Walk Transition Model.
The target is assumed to be (almost) stationary, where target velocity is modelled as white noise.
- Parameters
noise_diff_coeff (
float
) – The position noise diffusion coefficient \(q\)seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- property constant_derivative¶
For random walk, this is 0.
- covar(time_interval, **kwargs)¶
Model covariance
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- matrix(time_interval, **kwargs)¶
Model matrix
- property ndim: int¶
Number of dimensions of model
- property ndim_state¶
ndim_state getter method
- Returns
The number of model state dimensions.
- Return type
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.ConstantVelocity(noise_diff_coeff: float, seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.linear.ConstantNthDerivative
This is a class implementation of a discrete, time-variant 1D Linear-Gaussian Constant Velocity Transition Model.
The target is assumed to move with (nearly) constant velocity, where target acceleration is modelled as white noise.
The model is described by the following SDEs:
\begin{eqnarray} dx_{pos} & = & x_{vel} d & | {Position \ on \ X-axis (m)} \\ dx_{vel} & = & q\cdot dW_t,\ W_t \sim \mathcal{N}(0,q^2) & | \ Speed on\ X-axis (m/s) \end{eqnarray}Or equivalently:
\[x_t = F_t x_{t-1} + w_t,\ w_t \sim \mathcal{N}(0,Q_t)\]where:
\[\begin{split}x & = & \begin{bmatrix} x_{pos} \\ x_{vel} \end{bmatrix}\end{split}\]\[\begin{split}F_t & = & \begin{bmatrix} 1 & dt\\ 0 & 1 \end{bmatrix}\end{split}\]\[\begin{split}Q_t & = & \begin{bmatrix} \frac{dt^3}{3} & \frac{dt^2}{2} \\ \frac{dt^2}{2} & dt \end{bmatrix} q\end{split}\]- Parameters
noise_diff_coeff (
float
) – The velocity noise diffusion coefficient \(q\)seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- property constant_derivative¶
For constant velocity, this is 1.
- covar(time_interval, **kwargs)¶
Model covariance
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- matrix(time_interval, **kwargs)¶
Model matrix
- property ndim: int¶
Number of dimensions of model
- property ndim_state¶
ndim_state getter method
- Returns
The number of model state dimensions.
- Return type
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.ConstantAcceleration(noise_diff_coeff: float, seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.linear.ConstantNthDerivative
This is a class implementation of a discrete, time-variant 1D Constant Acceleration Transition Model.
The target acceleration is modeled as a zero-mean white noise random process.
The model is described by the following SDEs:
\begin{eqnarray} dx_{pos} & = & x_{vel} d & | {Position \ on \ X-axis (m)} \\ dx_{vel} & = & x_{acc} d & | {Speed \ on\ X-axis (m/s)} \\ dx_{acc} & = & q W_t,\ W_t \sim \mathcal{N}(0,q^2) & | {Acceleration \ on \ X-axis (m^2/s)} \end{eqnarray}Or equivalently:
\[x_t = F_t x_{t-1} + w_t,\ w_t \sim \mathcal{N}(0,Q_t)\]where:
\[\begin{split}x & = & \begin{bmatrix} x_{pos} \\ x_{vel} \\ x_{acc} \end{bmatrix}\end{split}\]\[\begin{split}F_t & = & \begin{bmatrix} 1 & dt & \frac{dt^2}{2} \\ 0 & 1 & dt \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]\[\begin{split}Q_t & = & \begin{bmatrix} \frac{dt^5}{20} & \frac{dt^4}{8} & \frac{dt^3}{6} \\ \frac{dt^4}{8} & \frac{dt^3}{3} & \frac{dt^2}{2} \\ \frac{dt^3}{6} & \frac{dt^2}{2} & dt \end{bmatrix} q\end{split}\]- Parameters
noise_diff_coeff (
float
) – The acceleration noise diffusion coefficient \(q\)seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- property constant_derivative¶
For constant acceleration, this is 2.
- covar(time_interval, **kwargs)¶
Model covariance
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- matrix(time_interval, **kwargs)¶
Model matrix
- property ndim: int¶
Number of dimensions of model
- property ndim_state¶
ndim_state getter method
- Returns
The number of model state dimensions.
- Return type
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.NthDerivativeDecay(decay_derivative: int, noise_diff_coeff: float, damping_coeff: float, seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.linear.LinearGaussianTransitionModel
,stonesoup.models.base.TimeVariantModel
Discrete model based on the Nth derivative with respect to time decaying to 0 exponentially, to set derivative use keyword argument
decay_derivative
The model is described by the following SDEs:
\begin{eqnarray} dx^{(N-1)} & = & x^{(N)} dt & | {(N-1)th derivative \ on \ X-axis (m)} \\ dx^{(N)} & = & -K x^{N} dt + q\cdot dW_t,\ W_t \sim \mathcal{N}(0,q^2) & | \ Nth\ derivative\ on\ X-axis (m/s^{N}) \end{eqnarray}The transition and covariance matrices are very difficult to express simply, but examples for N=1 and N=2 are given in
OrnsteinUhlenbeck
andSinger
respectively.- Parameters
decay_derivative (
int
) – The derivative with respect to time to decay exponentially, eg if 2 identical to singernoise_diff_coeff (
float
) – The noise diffusion coefficient \(q\)damping_coeff (
float
) – The Nth derivative damping coefficient \(K\)seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- decay_derivative: int¶
The derivative with respect to time to decay exponentially, eg if 2 identical to singer
- property ndim_state¶
ndim_state getter method
- Returns
The number of model state dimensions.
- Return type
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- property ndim: int¶
Number of dimensions of model
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.OrnsteinUhlenbeck(noise_diff_coeff: float, damping_coeff: float, seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.linear.NthDerivativeDecay
This is a class implementation of a discrete, time-variant 1D Linear-Gaussian Ornstein Uhlenbeck Transition Model.
The target is assumed to move with (nearly) constant velocity, which exponentially decays to zero over time, and target acceleration is modeled as white noise.
The model is described by the following SDEs:
\begin{eqnarray} dx_{pos} & = & x_{vel} dt & | {Position \ on \ X-axis (m)} \\ dx_{vel} & = & -K x_{vel} dt + q dW_t, W_t \sim \mathcal{N}(0,q) & | {Speed\ on \ X-axis (m/s)} \end{eqnarray}Or equivalently:
\[x_t = F_t x_{t-1} + w_t,\ w_t \sim \mathcal{N}(0,Q_t)\]where:
\[\begin{split}x & = & \begin{bmatrix} x_{pos} \\ x_{vel} \end{bmatrix}\end{split}\]\[\begin{split}F_t & = & \begin{bmatrix} 1 & \frac{1}{K}(1 - e^{-Kdt})\\ 0 & e^{-Kdt} \end{bmatrix}\end{split}\]\[\begin{split}Q_t & = & \begin{bmatrix} \frac{dt - \frac{2}{K}(1 - e^{-Kdt}) + \frac{1}{2K}(1 - e^{-2Kdt})}{K^2} & \frac{\frac{1}{K}(1 - e^{-Kdt}) - \frac{1}{2K}(1 - e^{-2Kdt})}{K} \\ \frac{\frac{1}{K}(1 - e^{-Kdt}) - \frac{1}{2K}(1 - e^{-2Kdt})}{K} & \frac{1 - e^{-2Kdt}}{2K} \end{bmatrix} q\end{split}\]- Parameters
noise_diff_coeff (
float
) – The velocity noise diffusion coefficient \(q\)damping_coeff (
float
) – The velocity damping coefficient \(K\)seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- property decay_derivative¶
The derivative with respect to time to decay exponentially, eg if 2 identical to singer
- covar(time_interval, **kwargs)¶
Model covariance
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- matrix(time_interval, **kwargs)¶
Model matrix
- property ndim: int¶
Number of dimensions of model
- property ndim_state¶
ndim_state getter method
- Returns
The number of model state dimensions.
- Return type
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.Singer(noise_diff_coeff: float, damping_coeff: float, seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.linear.NthDerivativeDecay
This is a class implementation of a discrete, time-variant 1D Singer Transition Model.
The target acceleration is modeled as a zero-mean Gauss-Markov random process.
The model is described by the following SDEs:
\begin{eqnarray} dx_{pos} & = & x_{vel} dt & | {Position \ on \ X-axis (m)} \\ dx_{vel} & = & x_{acc} dt & | {Speed \ on\ X-axis (m/s)} \\ dx_{acc} & = & -K x_{acc} dt + q W_t,\ W_t \sim \mathcal{N}(0,q^2) & | {Acceleration \ on \ X-axis (m^2/s)} \end{eqnarray}Or equivalently:
\[x_t = F_t x_{t-1} + w_t,\ w_t \sim \mathcal{N}(0,Q_t)\]where:
\[\begin{split}x & = & \begin{bmatrix} x_{pos} \\ x_{vel} \\ x_{acc} \end{bmatrix}\end{split}\]\[\begin{split}F_t & = & \begin{bmatrix} 1 & dt & (K dt-1+e^{-K dt})/K^2 \\ 0 & 1 & (1-e^{-K dt})/K \\ 0 & 0 & e^{-K t} \end{bmatrix}\end{split}\]\[\begin{split}Q_t & = & q \begin{bmatrix} \frac{[1-e^{-2K dt}] + 2K dt + \frac{2K^3 dt^3}{3}- 2K^2 dt^2 - 4K dt e^{-K dt} }{2K^5} & \frac{(K dt - [1-e^{-K dt}])^2}{2K^4} & \frac{[1-e^{-2K dt}]-2K dt e^{-K dt}} {2K^3} \\ \frac{(K dt - [1 - e^{-K dt}])^2}{2K^4} & \frac{2K dt - 4[1-e^{-K dt}] + [1-e^{-2K dt}]}{2K^3} & \frac{[1-e^{-K dt}]^2}{2K^2} \\ \frac{[1- e^{-2K dt}]-2K dt e^{-K dt}} {2K^3} & \frac{[1-e^{-K dt}]^2}{2K^2} & \frac{1-e^{-2K dt}}{2K} \end{bmatrix}\end{split}\]- Parameters
noise_diff_coeff (
float
) – The acceleration noise diffusion coefficient \(q\)damping_coeff (
float
) – The reciprocal of the decorrelation time \(\alpha\)seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- property decay_derivative¶
The derivative with respect to time to decay exponentially, eg if 2 identical to singer
- covar(time_interval, **kwargs)¶
Model covariance
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- matrix(time_interval, **kwargs)¶
Model matrix
- property ndim: int¶
Number of dimensions of model
- property ndim_state¶
ndim_state getter method
- Returns
The number of model state dimensions.
- Return type
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.SingerApproximate(noise_diff_coeff: float, damping_coeff: float, seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.linear.Singer
- Parameters
noise_diff_coeff (
float
) – The acceleration noise diffusion coefficient \(q\)damping_coeff (
float
) – The reciprocal of the decorrelation time \(\alpha\)seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- property decay_derivative¶
The derivative with respect to time to decay exponentially, eg if 2 identical to singer
- covar(time_interval, **kwargs)[source]¶
Returns the transition model noise covariance matrix.
- Parameters
time_interval (
datetime.timedelta
) – A time interval \(dt\)- Returns
The process noise covariance.
- Return type
stonesoup.types.state.CovarianceMatrix
of shape (ndim_state
,ndim_state
)
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- matrix(time_interval, **kwargs)¶
Model matrix
- property ndim: int¶
Number of dimensions of model
- property ndim_state¶
ndim_state getter method
- Returns
The number of model state dimensions.
- Return type
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.ConstantTurnSandwich(turn_noise_diff_coeffs: numpy.ndarray, turn_rate: float, model_list: Sequence[LinearGaussianTransitionModel], seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.linear.LinearGaussianTransitionModel
,stonesoup.models.base.TimeVariantModel
This is a class implementation of a time-variant 2D Constant Turn Model. This model is used, as opposed to the normal
ConstantTurn
model, when the turn occurs in 2 dimensions that are not adjacent in the state vector, eg if the turn occurs in the x-z plane but the state vector is of the form \((x,y,z)\). The list of transition models are to be applied to any state variables that lie in between, eg if for the above example you wanted the y component to move with constant velocity, you would put aConstantVelocity
model in the list.The target is assumed to move with (nearly) constant velocity and also known (nearly) constant turn rate.
- Parameters
turn_noise_diff_coeffs (
numpy.ndarray
) – The acceleration noise diffusion coefficients \(q\)turn_rate (
float
) – The turn rate \(\omega\)model_list (
Sequence[LinearGaussianTransitionModel]
) – List of Transition Models.seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- turn_noise_diff_coeffs: numpy.ndarray¶
The acceleration noise diffusion coefficients \(q\)
- model_list: Sequence[stonesoup.models.transition.linear.LinearGaussianTransitionModel]¶
List of Transition Models.
- property ndim_state¶
ndim_state getter method
- Returns
The number of combined model state dimensions.
- Return type
- matrix(time_interval, **kwargs)[source]¶
Model matrix \(F\)
- Returns
- Return type
numpy.ndarray
of shape (ndim_state
,ndim_state
)
- covar(time_interval, **kwargs)[source]¶
Returns the transition model noise covariance matrix.
- Returns
The process noise covariance.
- Return type
stonesoup.types.state.CovarianceMatrix
of shape (ndim_state
,ndim_state
)
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- property ndim: int¶
Number of dimensions of model
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- class stonesoup.models.transition.linear.ConstantTurn(turn_noise_diff_coeffs: numpy.ndarray, turn_rate: float, seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.linear.ConstantTurnSandwich
This is a class implementation of a discrete, time-variant 2D Constant Turn Model.
The target is assumed to move with (nearly) constant velocity and also known (nearly) constant turn rate.
The model is described by the following SDEs:
\begin{eqnarray} dx_{pos} & = & x_{vel} d & | {Position \ on \ X-axis (m)} \\ dx_{vel} & = &-\omega y_{pos} d & | {Speed \ on\ X-axis (m/s)} \\ dy_{pos} & = & y_{vel} d & | {Position \ on \ Y-axis (m)} \\ dy_{vel} & = & \omega x_{pos} d & | {Speed \ on\ Y-axis (m/s)} \end{eqnarray}Or equivalently:
\[x_t = F_t x_{t-1} + w_t,\ w_t \sim \mathcal{N}(0,Q_t)\]where:
\[\begin{split}x & = & \begin{bmatrix} x_{pos} \\ x_{vel} \\ y_{pos} \\ y_{vel} \end{bmatrix}\end{split}\]\[\begin{split}F_t & = & \begin{bmatrix} 1 & \frac{\sin\omega dt}{\omega} & 0 &-\frac{1-\cos\omega dt}{\omega} \\ 0 & \cos\omega dt & 0 & -\sin\omega dt \\ 0 & \frac{1-\cos\omega dt}{\omega} & 1 & \frac{\sin\omega dt}{\omega}\\ 0 & \sin\omega dt & 0 & \cos\omega dt \end{bmatrix}\end{split}\]\[\begin{split}Q_t & = & \begin{bmatrix} q_x^2 \frac{dt^3}{3} & q_x^2 \frac{dt^2}{2} & 0 & 0 \\ q_x^2 \frac{dt^2}{2} & q_x^2 dt & 0 & 0 \\ 0 & 0 & q_y^2 \frac{dt^3}{3} & q_y^2 \frac{dt^2}{2}\\ 0 & 0 & q_y^2 \frac{dt^2}{2} & q_y^2 dt \end{bmatrix}\end{split}\]- Parameters
turn_noise_diff_coeffs (
numpy.ndarray
) – The acceleration noise diffusion coefficients \(q\)turn_rate (
float
) – The turn rate \(\omega\)seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- property model_list¶
For a turn in adjacent state vectors, no transition models go in between
- covar(time_interval, **kwargs)¶
Returns the transition model noise covariance matrix.
- Returns
The process noise covariance.
- Return type
stonesoup.types.state.CovarianceMatrix
of shape (ndim_state
,ndim_state
)
- function(state: State, noise: Union[bool, numpy.ndarray] = False, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model linear function \(f_k(x(k),w(k)) = F_k(x_k) + w_k\)
- Parameters
state (State) – An input state
noise (
numpy.ndarray
or bool) – An externally generated random process noise sample (the default is False, in which case no noise will be added if ‘True’, the output ofrvs()
is added)
- Returns
The StateVector(s) with the model function evaluated.
- Return type
StateVector
orStateVectors
- matrix(time_interval, **kwargs)¶
Model matrix \(F\)
- Returns
- Return type
numpy.ndarray
of shape (ndim_state
,ndim_state
)
- property ndim: int¶
Number of dimensions of model
- property ndim_state¶
ndim_state getter method
- Returns
The number of combined model state dimensions.
- Return type
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)
- turn_noise_diff_coeffs: numpy.ndarray¶
The acceleration noise diffusion coefficients \(q\)
NonLinear¶
- class stonesoup.models.transition.nonlinear.CombinedNonlinearGaussianTransitionModel(model_list: Sequence[GaussianModel], seed: Optional[int] = None)[source]¶
Bases:
stonesoup.models.transition.base._CombinedGaussianTransitionModel
,stonesoup.models.base.NonLinearModel
Combine multiple models into a single model by stacking them.
The assumption is that all models are 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
- Parameters
model_list (
Sequence[GaussianModel]
) – List of Transition Models.seed (
Union[int, NoneType]
, optional) – Seed for random number generation
- function(state, **kwargs) stonesoup.types.array.StateVector [source]¶
Applies each transition model in
model_list
in turn to the state’s corresponding state vector components. For example, in a 3D state space, withmodel_list
= [modelA(ndim_state=2), modelB(ndim_state=1)], this would apply modelA to the state vector’s 1st and 2nd elements, then modelB to the remaining 3rd element.- Parameters
state (
stonesoup.state.State
) – The state to be transitioned according to the models inmodel_list
.- Returns
state_vector – of shape (
ndim_state, 1
). The resultant state vector of the transition.- Return type
- covar(**kwargs)¶
Returns the transition model noise covariance matrix.
- Returns
The process noise covariance.
- Return type
stonesoup.types.state.CovarianceMatrix
of shape (ndim_state
,ndim_state
)
- jacobian(state: State, **kwargs) numpy.ndarray ¶
Model Jacobian matrix \(H_{jac}\)
- Parameters
state (
State
) – An input state- Returns
:class:`numpy.ndarray` of shape (attr – The model Jacobian matrix evaluated around the given state vector.
- Return type
~ndim_meas,
ndim_state
)
- model_list: Sequence[stonesoup.models.base.GaussianModel]¶
List of Transition Models.
- property ndim: int¶
Number of dimensions of model
- property ndim_state¶
ndim_state getter method
- Returns
The number of combined model state dimensions.
- Return type
- pdf(state1: State, state2: State, **kwargs) Union[stonesoup.types.numeric.Probability, numpy.ndarray] ¶
Model pdf/likelihood evaluation function
Evaluates the pdf/likelihood of
state1
, given the statestate2
which is passed tofunction()
.In mathematical terms, this can be written as:
\[p = p(y_t | x_t) = \mathcal{N}(y_t; x_t, Q)\]where \(y_t\) =
state_vector1
, \(x_t\) =state_vector2
and \(Q\) =covar
.- Parameters
- Returns
The likelihood of
state1
, givenstate2
- Return type
Probability
orndarray
ofProbability
- rvs(num_samples: int = 1, random_state=None, **kwargs) Union[stonesoup.types.array.StateVector, stonesoup.types.array.StateVectors] ¶
Model noise/sample generation function
Generates noise samples from the model.
In mathematical terms, this can be written as:
\[v_t \sim \mathcal{N}(0,Q)\]where \(v_t =\)
noise
and \(Q\) =covar
.- Parameters
num_samples (scalar, optional) – The number of samples to be generated (the default is 1)
- Returns
noise – A set of Np samples, generated from the model’s noise distribution.
- Return type
2-D array of shape (
ndim
,num_samples
)