Skip to content

Commit

Permalink
Refactor resampling code in SMCPHDUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
sglvladi committed Feb 15, 2024
1 parent d50d76d commit e0c73d4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions stonesoup/updater/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,16 +577,16 @@ def update(self, multihypothesis, **kwargs):
# Update weights Eq. (8) of [1]
# w_k^i = \sum_{z \in Z_k}{w^{n,i}}, where i is the index of z in Z_k
log_post_weights = logsumexp(log_weights_per_hyp, axis=1)
prediction.log_weight = log_post_weights

# Resample
log_num_targets = logsumexp(log_post_weights) # N_{k|k}
# Normalize weights
prediction.log_weight = log_post_weights - log_num_targets
if self.resampler is not None:
prediction = self.resampler.resample(prediction, self.num_samples) # Resample
# De-normalize
prediction.log_weight = prediction.log_weight + log_num_targets
# Normalize weights
log_num_targets = logsumexp(log_post_weights) # N_{k|k}
prediction.log_weight = log_post_weights - log_num_targets
# Resample
prediction = self.resampler.resample(prediction, self.num_samples)
# De-normalize
prediction.log_weight += log_num_targets

return Update.from_state(
state=multihypothesis[0].prediction,
Expand Down

0 comments on commit e0c73d4

Please sign in to comment.