Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
log_other = self._log(other)
if self.log_value > log_other:
log_l, log_s = self.log_value, log_other
elif self.log_value < log_other: # Result will be negative
return float(self) - other
else: # Must be equal, so return 0
return Probability(float("-inf"), log_value=True)
if log_s == float("-inf"): # Just return largest value
return Probability(log_l, log_value=True)
exp_diff = exp(log_s - log_l)
if exp_diff == 1: # Diff too small, so result is effectively zero
return Probability(float("-inf"), log_value=True)
return Probability(log_l + log1p(-exp_diff),
log_value=True)
def sum(cls, values):
"""Carry out LogSumExp"""
log_values = [cls._log(value) for value in values]
if not log_values:
return Probability(0)
max_log_value = max(log_values)
# Check if all values are zero
if max_log_value == float('-inf'):
return Probability(0)
value_sum = sum(exp(log_value - max_log_value)
for log_value in log_values)
return Probability(cls._log(value_sum) + max_log_value, log_value=True)
return self.distance == other.distance
def __gt__(self, other):
return self.distance < other.distance
def __ge__(self, other):
return self.distance <= other.distance
class SingleMeasurementProbabilityHypothesis(Hypothesis):
"""Single Measurement Probability scored hypothesis subclass.
"""
probability = Property(
Probability,
doc="Probability that detection is true location of prediction")
def __lt__(self, other):
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 SimpleDetectionSimulator(DetectionSimulator):
"""A simple detection simulator.
Parameters
----------
groundtruth : GroundTruthReader
Source of ground truth tracks used to generate detections for.
measurement_model : MeasurementModel
Measurement model used in generating detections.
"""
groundtruth = Property(GroundTruthReader)
measurement_model = Property(MeasurementModel)
meas_range = Property(np.ndarray)
detection_probability = Property(Probability, default=0.9)
clutter_rate = Property(float, default=2.0)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.real_detections = set()
self.clutter_detections = set()
self.index = 0
@property
def clutter_spatial_density(self):
"""returns the clutter spatial density of the measurement space - num
clutter detections per unit volume per timestep"""
return self.clutter_rate/np.prod(np.diff(self.meas_range))
@BufferedGenerator.generator_method
def detections_gen(self):
def __add__(self, other):
if other < 0:
return self - -other
log_other = self._log(other)
if self.log_value > log_other:
log_l, log_s = self.log_value, log_other
elif self.log_value < log_other:
log_l, log_s = log_other, self.log_value
else: # Must be equal, so just double value
return self * 2
if log_s == float("-inf"): # Just return largest value
return Probability(log_l, log_value=True)
return Probability(log_l + log1p(exp(log_s - log_l)),
log_value=True)
detections.
"""
predictor = Property(
Predictor,
doc="Predict tracks to detection times")
updater = Property(
Updater,
doc="Updater used to get measurement prediction")
clutter_spatial_density = Property(
float,
doc="Spatial density of clutter - tied to probability of false "
"detection")
prob_detect = Property(
Probability,
default=Probability(0.85),
doc="Target Detection Probability")
prob_gate = Property(
Probability,
default=Probability(0.95),
doc="Gate Probability - prob. gate contains true measurement "
"if detected")
def hypothesise(self, track, detections, timestamp):
r"""Evaluate and return all track association hypotheses.
For a given track and a set of N detections, return a
MultipleHypothesis with N+1 detections (first detection is
a 'MissedDetection'), each with an associated probability.
Probabilities are assumed to be exhaustive (sum to 1) and mutually
exclusive (two detections cannot be the correct association at the
same time).
def __sub__(self, other):
if other < 0:
return self + -other
log_other = self._log(other)
if self.log_value > log_other:
log_l, log_s = self.log_value, log_other
elif self.log_value < log_other: # Result will be negative
return float(self) - other
else: # Must be equal, so return 0
return Probability(float("-inf"), log_value=True)
if log_s == float("-inf"): # Just return largest value
return Probability(log_l, log_value=True)
exp_diff = exp(log_s - log_l)
if exp_diff == 1: # Diff too small, so result is effectively zero
return Probability(float("-inf"), log_value=True)
return Probability(log_l + log1p(-exp_diff),
log_value=True)
def __abs__(self):
return Probability(self)