Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# -*- coding: utf-8 -*-
from ..base import Property
from .array import CovarianceMatrix
from .base import Type
from .state import State, GaussianState, ParticleState
class Prediction(Type):
""" Prediction type
This is the base prediction class. """
class MeasurementPrediction(Type):
""" Prediction type
This is the base measurement prediction class. """
class StatePrediction(State, Prediction):
""" StatePrediction type
Most simple state prediction type, which only has time and a state vector.
"""
class StateMeasurementPrediction(State, MeasurementPrediction):
""" MeasurementPrediction type
Most simple measurement prediction type, which only has time and a state
# -*- coding: utf-8 -*-
from ..base import Property
from .array import CovarianceMatrix
from .base import Type
from .state import State, GaussianState, ParticleState
class Prediction(Type):
""" Prediction type
This is the base prediction class. """
class MeasurementPrediction(Type):
""" Prediction type
This is the base measurement prediction class. """
class StatePrediction(State, Prediction):
""" StatePrediction type
Most simple state prediction type, which only has time and a state vector.
"""
state_vector = Property(StateVector, doc='State vector.')
def __init__(self, state_vector, *args, **kwargs):
# Don't cast away subtype of state_vector if not necessary
if state_vector is not None \
and not isinstance(state_vector, StateVector):
state_vector = StateVector(state_vector)
super().__init__(state_vector, *args, **kwargs)
@property
def ndim(self):
"""The number of dimensions represented by the state."""
return self.state_vector.shape[0]
class StateMutableSequence(Type, MutableSequence):
"""A mutable sequence for :class:`~.State` instances
This sequence acts like a regular list object for States, as well as
proxying state attributes to the last state in the sequence. This sequence
can also be indexed/sliced by :class:`datetime.datetime` instances.
Example
-------
>>> t0 = datetime.datetime(2018, 1, 1, 14, 00)
>>> t1 = t0 + datetime.timedelta(minutes=1)
>>> state0 = State([[0]], t0)
>>> sequence = StateMutableSequence([state0])
>>> print(sequence.state_vector, sequence.timestamp)
[[0]] 2018-01-01 14:00:00
>>> sequence.append(State([[1]], t1))
>>> for state in sequence[t1:]:
# -*- coding: utf-8 -*-
from .base import Type
class SensorData(Type):
"""Sensor Data type"""
@property
def mean(self):
"""The state mean, equivalent to state vector"""
return self.state_vector
class WeightedGaussianState(GaussianState):
"""Weighted Gaussian State Type
Gaussian State object with an associated weight. Used as components
for a GaussianMixtureState.
"""
weight = Property(float, default=0, doc="Weight of the Gaussian State.")
class ParticleState(Type):
"""Particle State type
This is a particle state object which describes the state as a
distribution of particles"""
timestamp = Property(datetime.datetime, default=None,
doc="Timestamp of the state. Default None.")
particles = Property([Particle],
doc='List of particles representing state')
@property
def mean(self):
"""The state mean, equivalent to state vector"""
result = np.average([p.state_vector for p in self.particles], axis=0,
weights=[p.weight for p in self.particles])
# Convert type as may have type of weights
# -*- coding: utf-8 -*-
from ..base import Property
from .base import Type
from .hypothesis import Hypothesis
from .state import State, GaussianState, ParticleState
class Update(Type):
""" Update type
The base update class. Updates are returned by :class:'~.Updater' objects
and contain the information that was used to perform the updating"""
hypothesis = Property(Hypothesis,
doc="Hypothesis used for updating")
class StateUpdate(Update, State):
""" StateUpdate type
Most simple state update type, where everything only has time
and a state vector. Requires a prior state that was updated,
and the hypothesis used to update the prior.
"""
return self.probability < other.probability
def __le__(self, other):
return self.probability <= other.probability
def __eq__(self, other):
return self.probability == other.probability
def __gt__(self, other):
return self.probability > other.probability
def __ge__(self, other):
return self.probability >= other.probability
class SingleMeasurementJointHypothesis(Type, UserDict):
"""Joint Hypothesis base type
"""
hypotheses = Property(
Hypothesis,
doc='Association hypotheses')
def __new__(cls, hypotheses):
if all(isinstance(hypothesis, SingleMeasurementDistanceHypothesis)
for hypothesis in hypotheses.values()):
return super().__new__(SingleMeasurementDistanceJointHypothesis)
else:
raise NotImplementedError
def __init__(self, hypotheses):
doc="Timestamp of the association. Default is None.")
class TimeRangeAssociation(Association):
"""TimeRangeAssociation type
An :class:`~.AssociationPair` representing the linking of objects over a
range of times
"""
time_range = Property(TimeRange, default=None,
doc="Range of times that association exists over. "
"Default is None")
class AssociationSet(Type):
"""AssociationSet type
A set of :class:`~.Association` type objects representing multiple
independent associations. Contains functions for indexing into the
associations
"""
associations = Property(set, default=None,
doc="Set of independant associations")
def __init__(self, associations=None, *args, **kwargs):
if associations is None:
associations = set()
super().__init__(associations, *args, **kwargs)
def associations_at_timestamp(self, timestamp):
# -*- coding: utf-8 -*-
from ..base import Property
from .array import StateVector
from .base import Type
class Particle(Type):
"""
Particle type
A particle type which contains a state and weight
"""
state_vector = Property(StateVector, doc="State vector")
weight = Property(float, doc='Weight of particle')
parent = Property(None, default=None, doc='Parent particle')
def __init__(self, state_vector, weight, parent=None, *args, **kwargs):
if parent:
parent.parent = None
super().__init__(state_vector, weight, parent, *args, **kwargs)
Particle.parent.cls = Particle # noqa:E305
# -*- coding: utf-8 -*-
from .base import Type
class Metric(Type):
"""Metric type"""