From a7b42cf7da2cb8bebf67561230774b3b079b74ad Mon Sep 17 00:00:00 2001 From: Nahuel Espinosa Date: Mon, 3 Apr 2023 08:45:08 -0300 Subject: [PATCH] Rename `importance_sample` method to `reweight` (#158) Fixes #151. The term "importance sample" means the act of drawing samples with replacement with probabilities given by the importance factors, and that is not what this method does in code. Signed-off-by: Nahuel Espinosa --- .../beluga/algorithm/particle_filter.hpp | 22 +++++++++---------- .../beluga/algorithm/test_particle_filter.cpp | 4 ++-- beluga_amcl/src/amcl_node.cpp | 2 +- beluga_system_tests/test/test_system.cpp | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/beluga/include/beluga/algorithm/particle_filter.hpp b/beluga/include/beluga/algorithm/particle_filter.hpp index 581f9f4f8..a206b2664 100644 --- a/beluga/include/beluga/algorithm/particle_filter.hpp +++ b/beluga/include/beluga/algorithm/particle_filter.hpp @@ -36,7 +36,7 @@ * * The following is satisfied: * - `b.sample()` updates the particles based on the latest motion update. - * - `b.importance_sample()` updates the particles weight based on the latest sensor update. + * - `b.reweight()` updates the particles weight based on the latest sensor update. * - `b.resample()` generates new particles from the old ones based on their importance weights. * * \section BaseParticleFilterLinks See also @@ -75,19 +75,19 @@ struct BaseParticleFilterInterface { * to incorporate measurements. The importance is proportional to the * probability of seeing the measurement given the current particle state. */ - virtual void importance_sample() = 0; + virtual void reweight() = 0; /** * \overload * It allows specifying a sequenced execution policy. */ - virtual void importance_sample(std::execution::sequenced_policy) { return this->importance_sample(); }; + virtual void reweight(std::execution::sequenced_policy) { return this->reweight(); }; /** * \overload * It allows specifying a parallel execution policy. */ - virtual void importance_sample(std::execution::parallel_policy) { return this->importance_sample(); }; + virtual void reweight(std::execution::parallel_policy) { return this->reweight(); }; /// Resample particles based on their weights. /** @@ -151,18 +151,18 @@ class BootstrapParticleFilter : public Mixin { void sample(std::execution::parallel_policy policy) final { this->sample_impl(policy); } /** - * \copydoc BaseParticleFilterInterface::importance_sample() + * \copydoc BaseParticleFilterInterface::reweight() * * The update will be done based on the `Mixin` implementation of the * \ref SensorModelPage "SensorModel" named requirements. */ - void importance_sample() final { this->importance_sample_impl(std::execution::seq); } + void reweight() final { this->reweight_impl(std::execution::seq); } - /// \copydoc BaseParticleFilterInterface::importance_sample(std::execution::sequenced_policy policy) - void importance_sample(std::execution::sequenced_policy policy) final { this->importance_sample_impl(policy); } + /// \copydoc BaseParticleFilterInterface::reweight(std::execution::sequenced_policy policy) + void reweight(std::execution::sequenced_policy policy) final { this->reweight_impl(policy); } - /// \copydoc BaseParticleFilterInterface::importance_sample(std::execution::parallel_policy policy) - void importance_sample(std::execution::parallel_policy policy) final { this->importance_sample_impl(policy); } + /// \copydoc BaseParticleFilterInterface::reweight(std::execution::parallel_policy policy) + void reweight(std::execution::parallel_policy policy) final { this->reweight_impl(policy); } /** * \copydoc BaseParticleFilterInterface::resample() @@ -191,7 +191,7 @@ class BootstrapParticleFilter : public Mixin { } template - void importance_sample_impl(ExecutionPolicy&& policy) { + void reweight_impl(ExecutionPolicy&& policy) { auto states = this->self().states() | ranges::views::common; auto weights = this->self().weights() | ranges::views::common; std::transform( diff --git a/beluga/test/beluga/algorithm/test_particle_filter.cpp b/beluga/test/beluga/algorithm/test_particle_filter.cpp index 5cd62670b..2443ede3e 100644 --- a/beluga/test/beluga/algorithm/test_particle_filter.cpp +++ b/beluga/test/beluga/algorithm/test_particle_filter.cpp @@ -123,7 +123,7 @@ TEST(BootstrapParticleFilter, UpdateWithoutResampling) { ASSERT_THAT(filter.weights() | ranges::to, Each(expected_initial_weight)); // updating particle weights, particles will have updated weights, but unchanged state - filter.importance_sample(); + filter.reweight(); ASSERT_THAT(filter.states() | ranges::to, Each(expected_final_state)); ASSERT_THAT(filter.weights() | ranges::to, Each(expected_final_weight)); @@ -162,7 +162,7 @@ TEST(BootstrapParticleFilter, UpdateWithResampling) { ASSERT_THAT(filter.weights() | ranges::to, Each(expected_initial_weight)); // updating particle weights, particles will have updated weights, but unchanged state - filter.importance_sample(); + filter.reweight(); ASSERT_THAT(filter.states() | ranges::to, Each(expected_final_state)); ASSERT_THAT(filter.weights() | ranges::to, Each(expected_final_weight)); diff --git a/beluga_amcl/src/amcl_node.cpp b/beluga_amcl/src/amcl_node.cpp index 24a03cf05..8087e8f0b 100644 --- a/beluga_amcl/src/amcl_node.cpp +++ b/beluga_amcl/src/amcl_node.cpp @@ -846,7 +846,7 @@ void AmclNode::laser_callback( static_cast(get_parameter("max_beams").as_int()), static_cast(get_parameter("laser_min_range").as_double()), static_cast(get_parameter("laser_max_range").as_double()))); - particle_filter_->importance_sample(exec_policy); + particle_filter_->reweight(exec_policy); const auto time3 = std::chrono::high_resolution_clock::now(); particle_filter_->resample(); const auto time4 = std::chrono::high_resolution_clock::now(); diff --git a/beluga_system_tests/test/test_system.cpp b/beluga_system_tests/test/test_system.cpp index 8bee25421..1376ac194 100644 --- a/beluga_system_tests/test/test_system.cpp +++ b/beluga_system_tests/test/test_system.cpp @@ -94,7 +94,7 @@ TEST_P(BelugaSystemTest, testEstimatedPath) { pf.sample(); auto scan_copy = data_point.scan; pf.update_sensor(std::move(scan_copy)); - pf.importance_sample(); + pf.reweight(); pf.resample(); auto estimation = pf.estimate(); auto error = data_point.ground_truth.inverse() * estimation.first;