Skip to content

Commit

Permalink
Added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pesslovany committed Jul 2, 2024
1 parent 7af6e21 commit 9900128
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 57 deletions.
31 changes: 31 additions & 0 deletions stonesoup/functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,37 @@


def gridCreation(xp_aux, Pp_aux, sFactor, nx, Npa):
"""Grid for point mass filter
Create a PMF grid based on center, covariance matrix, and sigma probability
Parameters
==========
xp_aux : numpy.ndarray
`nx` by `1` center of the grid
Pp_aux : numpy.ndarray
'nx' by 'nx' covariance matrix
sFactor : int
Parameter for the size of the grid
nx : int
Dimension of the grid
Npa : numpy.ndarray
'nx' by '' number of points per axis of the grid
Returns
=======
predGrid : numpy.ndarray
'nx' by prod(Npa) predictive grid
predGridDelta : list
grid step per dimension
gridDim : list of numpy.ndarrays
grid coordinates per dimension before rotation and translation
xp_aux : numpy.ndarray
grid center
eigVect : numpy.ndarray
eigenvectors describing the rotation of the grid
"""
gridDim = np.zeros((nx, Npa[0]))
gridStep = np.zeros(nx)
eigVal, eigVect = LA.eig(
Expand Down
8 changes: 4 additions & 4 deletions stonesoup/predictor/pointMass.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class PointMassPredictor(Predictor):
sFactor: float = Property(default=4, doc="How many sigma to cover by the grid")

# @profile
def predict(self, prior, timestamp=None, **kwargs):
"""Particle Filter prediction step
def predict(self, prior, timestamp=1, **kwargs):
"""Point Mass Filter prediction step
Parameters
----------
prior : :class:`~.ParticleState`
prior : :class:`~.Point mass state`
A prior state object
timestamp: :class:`datetime.datetime`, optional
A timestamp signifying when the prediction is performed
(the default is `None`)
(the default is `1`)
Returns
-------
Expand Down
4 changes: 4 additions & 0 deletions stonesoup/types/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ def from_state(


class PointMassState(State):
"""PointMassState State type
For the Lagrangina Point Mass filter.
"""

state_vector: StateVectors = Property(doc="State vectors.")
weight: MutableSequence[Probability] = Property(
Expand Down
59 changes: 6 additions & 53 deletions stonesoup/updater/pointMass.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,19 @@
from functools import lru_cache
from typing import Callable

import numpy as np
from scipy.stats import multivariate_normal
from stonesoup.types.state import PointMassState
from ..base import Property
from ..regulariser import Regulariser
from ..resampler import Resampler
from ..types.prediction import (
MeasurementPrediction,
)
from ..types.update import Update
from .base import Updater


class PointMassUpdater(Updater):
"""Particle Updater
"""Point mass Updater
Perform an update by multiplying particle weights by PDF of measurement
model (either :attr:`~.Detection.measurement_model` or
:attr:`measurement_model`), and normalising the weights. If provided, a
:attr:`resampler` will be used to take a new sample of particles (this is
called every time, and it's up to the resampler to decide if resampling is
required).
Perform an update by multiplying grid points weights by PDF of measurement
model
"""

sFactor: float = Property(default=3, doc="How many sigma to cover by the grid")
resampler: Resampler = Property(
default=None, doc="Resampler to prevent particle degeneracy"
)
regulariser: Regulariser = Property(
default=None,
doc="Regulariser to prevent particle impoverishment. The regulariser "
"is normally used after resampling. If a :class:`~.Resampler` is defined, "
"then regularisation will only take place if the particles have been "
"resampled. If the :class:`~.Resampler` is not defined but a "
":class:`~.Regulariser` is, then regularisation will be conducted under the "
"assumption that the user intends for this to occur.",
)

constraint_func: Callable = Property(
default=None,
doc="Callable, user defined function for applying "
"constraints to the states. This is done by setting the weights "
"of particles to 0 for particles that are not correctly constrained. "
"This function provides indices of the unconstrained particles and "
"should accept a :class:`~.ParticleState` object and return an array-like "
"object of logical indices. ",
)
sFactor: float = Property(default=4, doc="How many sigma to cover by the grid")

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -63,7 +30,7 @@ def update(self, hypothesis, **kwargs):
Returns
-------
: :class:`~.ParticleState`
: :class:`~.PointMassState`
The state posterior
"""

Expand Down Expand Up @@ -101,17 +68,3 @@ def update(self, hypothesis, **kwargs):
)

return predicted_state

@lru_cache()
def predict_measurement(self, state_prediction, measurement_model=None, **kwargs):

if measurement_model is None:
measurement_model = self.measurement_model

new_state_vector = measurement_model.function(state_prediction, **kwargs)

return MeasurementPrediction.from_state(
state_prediction,
state_vector=new_state_vector,
timestamp=state_prediction.timestamp,
)

0 comments on commit 9900128

Please sign in to comment.