Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPDA and SystematicResampler Fixes (updated) #193

Merged
merged 3 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 deletions stonesoup/dataassociator/probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,24 @@ def associate(self, tracks, detections, time):
SingleProbabilityHypothesis(
hypotheses[track][0].prediction,
MissedDetection(timestamp=time),
measurement_prediction=hypotheses[track][0]
.measurement_prediction,
measurement_prediction=hypotheses[track][0].measurement_prediction,
probability=prob_misdetect))

# record hypothesis for any given Detection being associated with
# this track
for detection in detections:
for hypothesis in hypotheses[track]:
if not hypothesis:
continue
pro_detect_assoc = Probability.sum(
joint_hypothesis.probability
for joint_hypothesis in joint_hypotheses
if joint_hypothesis.
hypotheses[track].measurement is detection)
if joint_hypothesis.hypotheses[track].measurement is hypothesis.measurement)

single_measurement_hypotheses.append(
SingleProbabilityHypothesis(
hypotheses[track][0].prediction,
detection,
measurement_prediction=hypotheses[track][0].
measurement_prediction,
hypothesis.prediction,
hypothesis.measurement,
measurement_prediction=hypothesis.measurement_prediction,
probability=pro_detect_assoc))

result = MultipleHypothesis(single_measurement_hypotheses, True, 1)
Expand Down
8 changes: 5 additions & 3 deletions stonesoup/resampler/particle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import numpy as np
from operator import attrgetter

from .base import Resampler
from ..types.numeric import Probability
Expand All @@ -24,8 +25,9 @@ def resample(self, particles):

n_particles = len(particles)
weight = Probability(1/n_particles)
cdf = np.cumsum([p.weight for p in particles])
particles_listed = list(particles)
particles_sorted = sorted(particles, key=attrgetter('weight'), reverse=False)
cdf = np.cumsum([p.weight for p in particles_sorted])

# Pick random starting point
u_i = np.random.uniform(0, 1 / n_particles)
new_particles = []
Expand All @@ -36,7 +38,7 @@ def resample(self, particles):

u_j = u_i + (1 / n_particles) * j

particle = particles_listed[np.argmax(u_j < cdf)]
particle = particles_sorted[np.argmax(u_j < cdf)]
new_particles.append(
Particle(particle.state_vector,
weight=weight,
Expand Down