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

Particle filter proposal implementation #1080

Merged
merged 4 commits into from
Oct 1, 2024

Conversation

A-acuto
Copy link
Contributor

@A-acuto A-acuto commented Sep 12, 2024

This PR updates the particle filter implementation with proposals, in particular prior as proposal and (local) kalman filter.
This is developed by @sglvladi and myself.

Now the particle filter uses prior as proposal as default, otherwise a Kalman filter proposal can be used.
Since in the prediction step we need to perform an update, we have modified as well the distance hypothesiser to include the measurements (or detections) to perform correctly the predict-update step.

We have implemented the local Lalman Filter proposal which propagates each particle using the kalman filter predict and update and then samples once for each particle the new state (before doing the particle update).
There is another way, commonly known as global Kalman Filter, where the particle distribution is approximated by a gaussian, which is propagated using the Kalman Filter and then a new set of particles is drawn from the new state. However, we encountered a number of issues in the making it working accordingly, in particular with problems with weights normalisation during the data-association step. I will open an issue to try to get to the bottom of this.

Summary paper that highlights the two implementations

We have not modified the probability hypothesier (yet) because there is the need of a fix proposed in #802 (PDA and JPDA to work with particle state) and we don't want to duplicate the work.

A couple of stone soup examples are :
single target no data association case
data association case

@A-acuto A-acuto requested a review from a team as a code owner September 12, 2024 10:35
@A-acuto A-acuto requested review from nperree-dstl and spike-dstl and removed request for a team September 12, 2024 10:35
Copy link
Member

@sdhiscocks sdhiscocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but would be nice to remove global seed setting from tests.

Comment on lines 124 to 127
post_log_weights = np.array([mvn.logpdf(sample,
np.array(update.mean).reshape(-1),
update.covar)
for sample, update in zip(samples, updates)])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better to handle custom types, as mvn converts to float arrays before taking difference.

Suggested change
post_log_weights = np.array([mvn.logpdf(sample,
np.array(update.mean).reshape(-1),
update.covar)
for sample, update in zip(samples, updates)])
post_log_weights = np.array([mvn.logpdf(sample - update.mean.reshape(-1), cov=update.covar)
for sample, update in zip(samples, updates)])

Also, here you use update.mean but above update.state_vector. Should these not be both the same? (In theory they should be anyway I guess? but...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, mean and state_vector are equal in this case. I changed it

def test_prior_proposal():
# test that the proposal as prior and basic PF implementation
# yield same results, since they are driven by the transition model
np.random.seed(16549)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1064 which aims to remove any setting of global random seeds in tests.

May need to add random state option to Proposal to support this, like models have.

…the state_vectr instead of mean and handling of arrays
@sdhiscocks sdhiscocks merged commit a004fd9 into dstl:main Oct 1, 2024
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants