on_effective_size_drop.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_POLICIES_ON_EFFECTIVE_SIZE_DROP_HPP
16 #define BELUGA_POLICIES_ON_EFFECTIVE_SIZE_DROP_HPP
17 
18 #include <range/v3/range/concepts.hpp>
19 
22 
28 namespace beluga::policies {
29 
30 namespace detail {
31 
35  static constexpr double kDefaultThreshold = 0.5;
36 
38 
44  template <class Range>
45  constexpr bool operator()(Range&& range, double threshold = kDefaultThreshold) const {
46  static_assert(ranges::sized_range<Range>);
47  const auto size = static_cast<double>(ranges::size(range));
48  return beluga::effective_sample_size(std::forward<Range>(range)) < size * threshold;
49  }
50 
52  constexpr auto operator()(double threshold) const {
53  return beluga::make_policy(ranges::bind_back(on_effective_size_drop_policy{}, threshold));
54  }
55 };
56 
57 } // namespace detail
58 
60 
65 
66 } // namespace beluga::policies
67 
68 #endif
beluga::policies::detail::on_effective_size_drop_policy
Implementation detail for a on_effective_size_drop_policy object.
Definition: on_effective_size_drop.hpp:33
beluga::policies
Definition: every_n.hpp:25
beluga::make_policy
constexpr detail::make_policy_fn make_policy
Make policy function objects.
Definition: policy.hpp:42
beluga::policies::detail::on_effective_size_drop_policy::operator()
constexpr auto operator()(double threshold) const
Overload that binds a specified threshold.
Definition: on_effective_size_drop.hpp:52
effective_sample_size.hpp
Implementation of an algorithm to calculate the effective sample size (ESS).
beluga::policies::on_effective_size_drop
constexpr policy< detail::on_effective_size_drop_policy > on_effective_size_drop
Policy that can be used to trigger an action based on the Effective Sample Size (ESS) metric.
Definition: on_effective_size_drop.hpp:64
policy.hpp
beluga::effective_sample_size
auto effective_sample_size(Range &&range)
Calculate the ESS of a given a range of weights.
Definition: effective_sample_size.hpp:46
beluga::policies::detail::on_effective_size_drop_policy::kDefaultThreshold
static constexpr double kDefaultThreshold
Default percentage threshold.
Definition: on_effective_size_drop.hpp:35
beluga::policy
Forward declaration of policy.
Definition: policy.hpp:24
beluga::policies::detail::on_effective_size_drop_policy::operator()
constexpr bool operator()(Range &&range, double threshold=kDefaultThreshold) const
Overload that implements the condition.
Definition: on_effective_size_drop.hpp:45


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53