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

Integrate sensor probabilities across resampling iterations #149

Merged
merged 1 commit into from
Apr 1, 2023

Conversation

glpuga
Copy link
Collaborator

@glpuga glpuga commented Mar 25, 2023

Related to #57.

Summary

  • Initializes weight to 1
  • Incorporates previous weight to the new weight calculation during the importance weight step.
  • Corrects importance_weight formula
  • Updates related tests
  • Minor documentation and testing updates.

Checklist

  • Read the contributing guidelines.
  • Configured pre-commit and ran colcon test locally.
  • Signed all commits for DCO.
  • Added tests (regression tests for bugs, coverage of new code for features).
  • Updated documentation (as needed).
  • Checked that CI is passing.

@glpuga glpuga self-assigned this Mar 25, 2023
@glpuga glpuga force-pushed the glpuga/integrate_importance_sampling branch 3 times, most recently from a5dcc7a to dd1eb21 Compare March 25, 2023 17:22
Copy link
Member

@nahueespinosa nahueespinosa left a comment

Choose a reason for hiding this comment

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

@glpuga This is great! Thanks for the documentation fixes and minor refactors.

beluga/include/beluga/algorithm/particle_filter.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/particle_filter.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/particle_filter.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/sampling.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/sampling.hpp Outdated Show resolved Hide resolved
beluga/include/beluga/algorithm/sampling.hpp Outdated Show resolved Hide resolved
@glpuga glpuga force-pushed the glpuga/integrate_importance_sampling branch 2 times, most recently from b67902f to 1311a4f Compare March 29, 2023 01:48
@glpuga
Copy link
Collaborator Author

glpuga commented Mar 29, 2023

Ready for another view. I did not update the tolerances since I could not get the system_test to run. I opened a ticket about that, since the error seems to be in main.

@nahueespinosa nahueespinosa added enhancement New feature or request cpp Related to C++ code labels Mar 29, 2023
});
// TODO(glpuga): Investigate why AMCL and QuickMCL use this formula for the weight.
// See https://github.com/ekumenlabs/beluga/issues/153
return pz * pz * pz;
Copy link
Member

Choose a reason for hiding this comment

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

This is not exactly what AMCL does. I think you need to cube the result of:

index < likelihood_field_.size() ? likelihood_field_[index] : unknown_space_occupancy_prob

And then accumulate the results by adding them, not multiplying them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, you're right. My mistake. I'll fix it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The longer you look at it, the weirder it becomes. The accumulation starts from 1.0, not from 0.0.

// Compute the sample weights
for (j = 0; j < set->sample_count; j++) {
    // ...
    p = 1.0;
    // ...
    for (i = 0; i < data->range_count; i += step) {
        // ...
        pz = 0.0;
        // ...
        pz += ...;
        pz += ...;

        assert(pz <= 1.0);
        assert(pz >= 0.0);

        p += pz * pz * pz;
    }

    sample->weight *= p;
    total_weight += sample->weight;
}

Also, the Beam Model does the same. #99

Copy link
Collaborator

Choose a reason for hiding this comment

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

The accumulation starts from 1.0, not from 0.0.

That looks like they started by multiplying and then and some point switched and forgot to change the starting value...

But starting with a weight of 1 also makes sure all particles are somehow weighted, so it's a big difference to have that in the addition or not (my assumption is that all other terms of the sum are less than 1., that's why I consider starting with 1 a big difference).

beluga/include/beluga/algorithm/particle_filter.hpp Outdated Show resolved Hide resolved
@glpuga glpuga force-pushed the glpuga/integrate_importance_sampling branch 2 times, most recently from 516a0ac to 82ccc15 Compare March 29, 2023 23:45
Copy link
Member

@nahueespinosa nahueespinosa left a comment

Choose a reason for hiding this comment

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

LGTM!

@glpuga
Copy link
Collaborator Author

glpuga commented Mar 30, 2023

@nahueespinosa I have not yet run system_test and checked if the tolerances need ajustments. Should I

  1. merge this and check/fix the tolerances in a follow up PR.
  2. wait until we define the lfs ticket and check/fix as part of this MR?
  3. not wait, sort the configuration issue locally and check/fix as part of this MR?

@nahueespinosa
Copy link
Member

@ivanpauno Could you run a benchmark on this branch? I have to rebuild the dockers to do it myself.

@glpuga I have run the system test locally and it consistently passes. So merging this as is is also a good option in my opinion.

@glpuga
Copy link
Collaborator Author

glpuga commented Mar 30, 2023

Ok! I'll wait for @ivanpauno JIC.

@ivanpauno
Copy link
Collaborator

@ivanpauno Could you run a benchmark on this branch? I have to rebuild the dockers to do it myself.

Sure, I think I can do it for tomorrow.

Copy link
Collaborator

@ivanpauno ivanpauno left a comment

Choose a reason for hiding this comment

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

LGTM!

@nahueespinosa
Copy link
Member

Benchmark results, red is before this patch and blue is after this patch. The error is a bit higher, but that's fine by me.

image

Signed-off-by: Gerardo Puga <glpuga@ekumenlabs.com>
@glpuga glpuga force-pushed the glpuga/integrate_importance_sampling branch from 82ccc15 to 953aaa6 Compare April 1, 2023 13:02
@glpuga glpuga merged commit 5db2870 into main Apr 1, 2023
@glpuga glpuga deleted the glpuga/integrate_importance_sampling branch April 1, 2023 13:13
@nahueespinosa nahueespinosa mentioned this pull request Apr 17, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpp Related to C++ code enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate multiple measurements by multiplicatively updating the importance factor or weight.
3 participants