| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //====================================================================================================================== | ||
| 2 | /* | ||
| 3 | POLYFLOAT - Extended precision floating points | ||
| 4 | Copyright : POLYFLOAT Contributors & Maintainers | ||
| 5 | SPDX-License-Identifier: BSL-1.0 | ||
| 6 | */ | ||
| 7 | //====================================================================================================================== | ||
| 8 | #pragma once | ||
| 9 | |||
| 10 | #include <polyfloat/details/callable.hpp> | ||
| 11 | #include <polyfloat/types/concepts.hpp> | ||
| 12 | #include <polyfloat/types/traits.hpp> | ||
| 13 | #include <type_traits> | ||
| 14 | #include <polyfloat/module/math/nthroot.hpp> | ||
| 15 | |||
| 16 | namespace plf | ||
| 17 | { | ||
| 18 | |||
| 19 | template<typename Options> | ||
| 20 | struct kolmmean_t : eve::strict_tuple_callable<kolmmean_t, Options, raw_option, pedantic_option> | ||
| 21 | { | ||
| 22 | |||
| 23 | template<typename F, typename G, concepts::polyfloat_like... Zs> | ||
| 24 | 76 | POLYFLOAT_ABI constexpr as_polyfloat_like_t<Zs...> operator()(F f, G g, Zs... zs) const noexcept | |
| 25 | { | ||
| 26 | 76 | return POLYFLOAT_CALL(f, g, zs...); | |
| 27 | } | ||
| 28 | |||
| 29 | 74 | POLYFLOAT_CALLABLE_OBJECT(kolmmean_t, kolmmean_); | |
| 30 | }; | ||
| 31 | //====================================================================================================================== | ||
| 32 | //! @addtogroup math | ||
| 33 | //! @{ | ||
| 34 | //! @var kolmmean | ||
| 35 | //! @brief Callable object computing the 'Kolmogorov-Nagumo-de Finetti' mean of the inputs: \f$ \mathbf{g}(\sum \mathbf{f}(x_s)) \f$. | ||
| 36 | //! | ||
| 37 | //! @groupheader{Header file} | ||
| 38 | //! | ||
| 39 | //! @code | ||
| 40 | //! #include <polyfloat/core.hpp> | ||
| 41 | //! @endcode | ||
| 42 | //! | ||
| 43 | //! @groupheader{Callable Signatures} | ||
| 44 | //! | ||
| 45 | //! @code | ||
| 46 | //! namespace polyfloat | ||
| 47 | //! { | ||
| 48 | //! template<polyfloat::concepts::polyfloat_like ... Ts> constexpr auto kolmmean(auto f, auto g, Ts ... ts) noexcept; | ||
| 49 | //! } | ||
| 50 | //! @endcode | ||
| 51 | //! | ||
| 52 | //! **Parameters** | ||
| 53 | //! | ||
| 54 | //! * `f`, `g`: two functions that will be used to compute the mean (see note above). | ||
| 55 | //! * `ts`: polyfloat like] arguments. | ||
| 56 | //! | ||
| 57 | //! **Return value** | ||
| 58 | //! | ||
| 59 | //! The kolmogorov mean of the inputs is returned//! | ||
| 60 | //! | ||
| 61 | //! @note For the result to be a proper kolmogorov mean, `f` must be mathematically continuous and injective and `g` be its inverse. | ||
| 62 | //! and **EVE** need them to be defined for a floating_value input, and returning the same type. | ||
| 63 | //! However \f$ \mathbf{g}(\sum \mathbf{f}(x_s, ...)) \f$ is returned if computable. | ||
| 64 | //! | ||
| 65 | //! @groupheader{External references} | ||
| 66 | //! * [wikipedia quasi-arithmetic mean](https://en.wikipedia.org/wiki/Quasi-arithmetic_mean) | ||
| 67 | //! | ||
| 68 | //! @groupheader{Example} | ||
| 69 | //! | ||
| 70 | //! @godbolt{doc/math/kolmmean.cpp} | ||
| 71 | //====================================================================================================================== | ||
| 72 | |||
| 73 | inline constexpr auto kolmmean = eve::functor<kolmmean_t>; | ||
| 74 | //====================================================================================================================== | ||
| 75 | //! @} | ||
| 76 | //====================================================================================================================== | ||
| 77 | } | ||
| 78 | |||
| 79 | namespace plf::_ | ||
| 80 | { | ||
| 81 | |||
| 82 | template<typename F, typename G, typename T0, typename... Ts, eve::callable_options O> | ||
| 83 | 74 | constexpr auto kolmmean_(POLYFLOAT_DELAY(), O const& o, F f, G g, T0 t0, Ts... ts) noexcept | |
| 84 | { | ||
| 85 | using r_t = as_polyfloat_like_t<T0, Ts...>; | ||
| 86 | using e_t = eve::element_type_t<r_t>; | ||
| 87 | 100 | auto cvt = [](auto a) { return plf::convert(a, as<e_t>()); }; | |
| 88 | 74 | constexpr auto sz = sizeof...(Ts); | |
| 89 | if constexpr (sz == 0) return g(f(t0)); | ||
| 90 | 74 | else return g(plf::average[o](f(cvt(t0)), f(cvt(ts))...)); | |
| 91 | } | ||
| 92 | } | ||
| 93 |