include
beluga
algorithm
thrun_recovery_probability_estimator.hpp
Go to the documentation of this file.
1
// Copyright 2024 Ekumen, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef BELUGA_ALGORITHM_THRUN_RECOVERY_PROBABILITY_ESTIMATOR_HPP
16
#define BELUGA_ALGORITHM_THRUN_RECOVERY_PROBABILITY_ESTIMATOR_HPP
17
18
#include <
beluga/algorithm/exponential_filter.hpp
>
19
#include <
beluga/type_traits/particle_traits.hpp
>
20
#include <
beluga/views/particles.hpp
>
21
22
#include <range/v3/numeric/accumulate.hpp>
23
24
namespace
beluga
{
25
27
38
class
ThrunRecoveryProbabilityEstimator
{
39
public
:
41
45
constexpr
ThrunRecoveryProbabilityEstimator
(
double
alpha_slow,
double
alpha_fast) noexcept
46
:
slow_filter_
{alpha_slow},
fast_filter_
{alpha_fast} {
47
assert(0 <= alpha_slow);
48
assert(alpha_slow <= alpha_fast);
49
}
50
52
56
constexpr
void
reset
() noexcept {
57
slow_filter_
.
reset
();
58
fast_filter_
.
reset
();
59
}
60
62
66
template
<
class
Range>
67
constexpr
double
operator()
(Range&& range) {
68
static_assert(ranges::sized_range<Range>);
69
static_assert(beluga::is_particle_range_v<Range>);
70
const
std::size_t size = range.size();
71
72
if
(size == 0) {
73
reset
();
74
return
0.0;
75
}
76
77
const
double
total_weight = ranges::accumulate(
beluga::views::weights
(range), 0.0);
78
const
double
average_weight = total_weight /
static_cast<
double
>
(size);
79
const
double
fast_average =
fast_filter_
(average_weight);
80
const
double
slow_average =
slow_filter_
(average_weight);
81
82
if
(std::abs(slow_average) < std::numeric_limits<double>::epsilon()) {
83
return
0.0;
84
}
85
86
return
std::clamp(1.0 - fast_average / slow_average, 0.0, 1.0);
87
}
88
89
private
:
90
ExponentialFilter
slow_filter_
;
91
ExponentialFilter
fast_filter_
;
92
};
93
94
}
// namespace beluga
95
96
#endif
exponential_filter.hpp
Implementation of an exponential filter.
beluga::ThrunRecoveryProbabilityEstimator::operator()
constexpr double operator()(Range &&range)
Update the estimation based on a particle range.
Definition:
thrun_recovery_probability_estimator.hpp:67
beluga::ExponentialFilter
Callable type implementing an exponential filter.
Definition:
exponential_filter.hpp:26
particles.hpp
Implementation of views related to particle ranges.
beluga::ThrunRecoveryProbabilityEstimator::ThrunRecoveryProbabilityEstimator
constexpr ThrunRecoveryProbabilityEstimator(double alpha_slow, double alpha_fast) noexcept
Constructor.
Definition:
thrun_recovery_probability_estimator.hpp:45
beluga::ExponentialFilter::reset
constexpr void reset() noexcept
Resets the output of the exponential filter to zero.
Definition:
exponential_filter.hpp:35
particle_traits.hpp
Implementation of traits for particle types, see the Particle named requirements.
beluga::ThrunRecoveryProbabilityEstimator
Random particle probability estimator.
Definition:
thrun_recovery_probability_estimator.hpp:38
beluga::ThrunRecoveryProbabilityEstimator::fast_filter_
ExponentialFilter fast_filter_
Exponential filter for the short-term average.
Definition:
thrun_recovery_probability_estimator.hpp:91
beluga::views::weights
constexpr auto weights
Definition:
particles.hpp:34
beluga::ThrunRecoveryProbabilityEstimator::reset
constexpr void reset() noexcept
Reset the internal state of the estimator.
Definition:
thrun_recovery_probability_estimator.hpp:56
beluga
The main Beluga namespace.
Definition:
3d_embedding.hpp:21
beluga::ThrunRecoveryProbabilityEstimator::slow_filter_
ExponentialFilter slow_filter_
Exponential filter for the long-term average.
Definition:
thrun_recovery_probability_estimator.hpp:90
beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53