From f5bf7da4e14b6090ec9fac9cf7e28e696d9359ef Mon Sep 17 00:00:00 2001 From: Joel Falcou Date: Sat, 17 Dec 2022 10:55:34 +0100 Subject: [PATCH] Deprecate and remove proba/ module Proba distribution design is to be reforged later in another library. --- include/eve/module/proba.hpp | 23 - .../eve/module/proba/detail/attributes.hpp | 128 ----- include/eve/module/proba/detail/urg01.hpp | 40 -- .../proba/regular/binomial_distribution.hpp | 10 - .../proba/regular/cauchy_distribution.hpp | 10 - .../module/proba/regular/ev_distribution.hpp | 10 - .../regular/exponential_distribution.hpp | 10 - .../proba/regular/gamma_distribution.hpp | 10 - .../regular/impl/binomial_distribution.hpp | 508 ------------------ .../regular/impl/cauchy_distribution.hpp | 272 ---------- .../proba/regular/impl/ev_distribution.hpp | 370 ------------- .../regular/impl/exponential_distribution.hpp | 250 --------- .../proba/regular/impl/gamma_distribution.hpp | 402 -------------- .../regular/impl/lognormal_distribution.hpp | 370 ------------- .../regular/impl/normal_distribution.hpp | 467 ---------------- .../regular/impl/poisson_distribution.hpp | 240 --------- .../impl/uniform_continuous_distribution.hpp | 299 ----------- .../impl/uniform_discrete_distribution.hpp | 280 ---------- .../proba/regular/lognormal_distribution.hpp | 10 - .../proba/regular/normal_distribution.hpp | 10 - .../proba/regular/poisson_distribution.hpp | 10 - include/eve/module/proba/regular/proba.hpp | 19 - .../uniform_continuous_distribution.hpp | 10 - .../regular/uniform_discrete_distribution.hpp | 10 - test/doc/CMakeLists.txt | 2 - test/doc/proba/CMakeLists.txt | 16 - test/doc/proba/binomial_distribution.cpp | 73 --- test/doc/proba/cauchy_distribution.cpp | 68 --- test/doc/proba/essai_distrib.cpp | 41 -- test/doc/proba/essai_distrib_int.cpp | 40 -- test/doc/proba/ev_distribution.cpp | 78 --- test/doc/proba/exponential_distribution.cpp | 66 --- test/doc/proba/gamma_distribution.cpp | 81 --- test/doc/proba/lognormal_distribution.cpp | 80 --- test/doc/proba/normal_distribution.cpp | 79 --- test/doc/proba/poisson_distribution.cpp | 61 --- .../proba/uniform_continuous_distribution.cpp | 47 -- .../proba/uniform_discrete_distribution.cpp | 64 --- test/unit/module/CMakeLists.txt | 1 - test/unit/module/proba/CMakeLists.txt | 19 - .../module/proba/binomial_distribution.cpp | 58 -- .../unit/module/proba/cauchy_distribution.cpp | 68 --- test/unit/module/proba/ev_distribution.cpp | 59 -- .../module/proba/exponential_distribution.cpp | 61 --- test/unit/module/proba/gamma_distribution.cpp | 53 -- .../module/proba/lognormal_distribution.cpp | 64 --- .../unit/module/proba/normal_distribution.cpp | 62 --- .../module/proba/poisson_distribution.cpp | 41 -- .../proba/uniform_continuous_distribution.cpp | 38 -- .../proba/uniform_discrete_distribution.cpp | 38 -- 50 files changed, 5126 deletions(-) delete mode 100644 include/eve/module/proba.hpp delete mode 100644 include/eve/module/proba/detail/attributes.hpp delete mode 100644 include/eve/module/proba/detail/urg01.hpp delete mode 100644 include/eve/module/proba/regular/binomial_distribution.hpp delete mode 100644 include/eve/module/proba/regular/cauchy_distribution.hpp delete mode 100644 include/eve/module/proba/regular/ev_distribution.hpp delete mode 100644 include/eve/module/proba/regular/exponential_distribution.hpp delete mode 100644 include/eve/module/proba/regular/gamma_distribution.hpp delete mode 100644 include/eve/module/proba/regular/impl/binomial_distribution.hpp delete mode 100644 include/eve/module/proba/regular/impl/cauchy_distribution.hpp delete mode 100644 include/eve/module/proba/regular/impl/ev_distribution.hpp delete mode 100644 include/eve/module/proba/regular/impl/exponential_distribution.hpp delete mode 100644 include/eve/module/proba/regular/impl/gamma_distribution.hpp delete mode 100644 include/eve/module/proba/regular/impl/lognormal_distribution.hpp delete mode 100644 include/eve/module/proba/regular/impl/normal_distribution.hpp delete mode 100644 include/eve/module/proba/regular/impl/poisson_distribution.hpp delete mode 100644 include/eve/module/proba/regular/impl/uniform_continuous_distribution.hpp delete mode 100644 include/eve/module/proba/regular/impl/uniform_discrete_distribution.hpp delete mode 100644 include/eve/module/proba/regular/lognormal_distribution.hpp delete mode 100644 include/eve/module/proba/regular/normal_distribution.hpp delete mode 100644 include/eve/module/proba/regular/poisson_distribution.hpp delete mode 100644 include/eve/module/proba/regular/proba.hpp delete mode 100644 include/eve/module/proba/regular/uniform_continuous_distribution.hpp delete mode 100644 include/eve/module/proba/regular/uniform_discrete_distribution.hpp delete mode 100644 test/doc/proba/CMakeLists.txt delete mode 100644 test/doc/proba/binomial_distribution.cpp delete mode 100644 test/doc/proba/cauchy_distribution.cpp delete mode 100644 test/doc/proba/essai_distrib.cpp delete mode 100644 test/doc/proba/essai_distrib_int.cpp delete mode 100644 test/doc/proba/ev_distribution.cpp delete mode 100644 test/doc/proba/exponential_distribution.cpp delete mode 100644 test/doc/proba/gamma_distribution.cpp delete mode 100644 test/doc/proba/lognormal_distribution.cpp delete mode 100644 test/doc/proba/normal_distribution.cpp delete mode 100644 test/doc/proba/poisson_distribution.cpp delete mode 100644 test/doc/proba/uniform_continuous_distribution.cpp delete mode 100644 test/doc/proba/uniform_discrete_distribution.cpp delete mode 100644 test/unit/module/proba/CMakeLists.txt delete mode 100644 test/unit/module/proba/binomial_distribution.cpp delete mode 100644 test/unit/module/proba/cauchy_distribution.cpp delete mode 100644 test/unit/module/proba/ev_distribution.cpp delete mode 100644 test/unit/module/proba/exponential_distribution.cpp delete mode 100644 test/unit/module/proba/gamma_distribution.cpp delete mode 100644 test/unit/module/proba/lognormal_distribution.cpp delete mode 100644 test/unit/module/proba/normal_distribution.cpp delete mode 100644 test/unit/module/proba/poisson_distribution.cpp delete mode 100644 test/unit/module/proba/uniform_continuous_distribution.cpp delete mode 100644 test/unit/module/proba/uniform_discrete_distribution.cpp diff --git a/include/eve/module/proba.hpp b/include/eve/module/proba.hpp deleted file mode 100644 index 058957ffbd..0000000000 --- a/include/eve/module/proba.hpp +++ /dev/null @@ -1,23 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#pragma once - -//================================================================================================== -//! @addtogroup functions -//! @{ -//! @defgroup proba Probability distributions -//! @brief Probability distributions -//! -//! This module provides implementation for probability distribution functions and generators. -//! -//! **Required header:** @code{.cpp} #include @endcode -//! -//! @} -//================================================================================================== - -#include diff --git a/include/eve/module/proba/detail/attributes.hpp b/include/eve/module/proba/detail/attributes.hpp deleted file mode 100644 index 90ad465bc0..0000000000 --- a/include/eve/module/proba/detail/attributes.hpp +++ /dev/null @@ -1,128 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include - -#include -#include - -namespace eve -{ - - template - concept distribution = requires(D) - { - typename D::is_distribution_t; - }; - - template - concept continuous = requires(D) - { - typename D::continuous_t; - }; - - template - concept discrete = requires(D) - { - typename D::discrete_t; - }; - - template - concept mixed = requires(D) - { - typename D::mixed_t; - }; - - EVE_MAKE_CALLABLE(cdf_, cdf); // cumulative distribution function - EVE_MAKE_CALLABLE(pdf_, pdf); // density function (derivable distributions) - EVE_MAKE_CALLABLE(invcdf_, invcdf); // inverse of cumulative distribution function (quantile) - EVE_MAKE_CALLABLE(mgf_, mgf); // moment generating function - EVE_MAKE_CALLABLE(cf_, cf); // characteristic function - EVE_MAKE_CALLABLE(pmf_, pmf); // probability mass function (discrete distributions) - EVE_MAKE_CALLABLE(parameters_, parameters);//parameters stored in struct - EVE_MAKE_CALLABLE(kullback_, kullback); // kullback-leiber divergence - EVE_MAKE_CALLABLE(mean_, mean); // mean - EVE_MAKE_CALLABLE(median_, median); // median - EVE_MAKE_CALLABLE(mode_, mode); // mode - EVE_MAKE_CALLABLE(mad_, mad); // mean absolute deviation - EVE_MAKE_CALLABLE(stdev_, stdev); // standard deviation - EVE_MAKE_CALLABLE(var_, var); // variance - EVE_MAKE_CALLABLE(entropy_, entropy); // entropy - EVE_MAKE_CALLABLE(fisher_, fisher); // fisher information - EVE_MAKE_CALLABLE(skewness_, skewness); // skewness - EVE_MAKE_CALLABLE(kurtosis_, kurtosis); // kurtosis - EVE_MAKE_CALLABLE(scale_, scale); // scale - EVE_MAKE_CALLABLE(shape_, shape); // shape - EVE_MAKE_CALLABLE(rate_, rate); // rate - EVE_MAKE_CALLABLE(confidence_, confidence);// confidence bounds - - namespace detail - { - template < distribution D, floating_ordered_value U> - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_), D const &d, U const &x ) noexcept = delete; - template < distribution D, floating_ordered_value U> - EVE_FORCEINLINE auto pdf_(EVE_SUPPORTS(cpu_), D const &d, U const &x ) noexcept = delete; - template < distribution D, floating_ordered_value U> - EVE_FORCEINLINE auto invcdf_(EVE_SUPPORTS(cpu_), D const &d, U const &x ) noexcept = delete; - template < distribution D, floating_ordered_value U> - EVE_FORCEINLINE auto mgf_(EVE_SUPPORTS(cpu_), D const &d, U const &x ) noexcept = delete; - template < distribution D, floating_ordered_value U> - EVE_FORCEINLINE auto cf_(EVE_SUPPORTS(cpu_), D const &d, U const &x ) noexcept = delete; - template < distribution D, value U> - EVE_FORCEINLINE auto pmf_(EVE_SUPPORTS(cpu_), D const &d, U const &x ) noexcept = delete; - - // confidence bounds for N parameters distribution - template < distribution D, floating_ordered_value R, floating_ordered_value V, int N - , floating_ordered_value A> - EVE_FORCEINLINE auto confidence_(EVE_SUPPORTS(cpu_), D const &d - , R const & x - , std::array const &cov - , A const & alpha ) noexcept = delete; - - // confidence bounds for 1 parameter distribution - template < distribution D, floating_ordered_value R, floating_ordered_value V - , floating_ordered_value A> - EVE_FORCEINLINE auto confidence_(EVE_SUPPORTS(cpu_), D const &d - , R const & x - , V const &cov - , A const & alpha ) noexcept = delete; - - template < distribution D> - EVE_FORCEINLINE auto scale_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto mean_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto median_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto mad_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto kullback_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto stdev_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto var_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto skewness_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto kurtosis_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto fisher_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto entropy_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto shape_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - template < distribution D> - EVE_FORCEINLINE auto rate_(EVE_SUPPORTS(cpu_), D const &d ) noexcept = delete; - } -} diff --git a/include/eve/module/proba/detail/urg01.hpp b/include/eve/module/proba/detail/urg01.hpp deleted file mode 100644 index 659fbd17b2..0000000000 --- a/include/eve/module/proba/detail/urg01.hpp +++ /dev/null @@ -1,40 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include - - -namespace eve::detail -{ - template - EVE_FORCEINLINE auto urg01(Engine& eng, as const &) noexcept - { - if constexpr(scalar_value) - { - for(;;) { - T numerator = static_cast(eng() - (eng.min)()); - T divisor = static_cast((eng.max)() - (eng.min)()); - EVE_ASSERT(eve::all(divisor > T(0)), "divisor is negative"); - EVE_ASSERT(eve::all(numerator >= T(0) && numerator <= divisor), "numerator negative or greater than divisor"); - T result = numerator / divisor; - if(result < one(as(result))) return result; - } - } - else - { - using elt_t = element_type_t; - return [&]( std::index_sequence) - { - auto v = [&](auto) { return detail::urg01(eng, as()); }; - return T{ v(I)...}; - }( std::make_index_sequence< cardinal_v>{}); - } - } -} diff --git a/include/eve/module/proba/regular/binomial_distribution.hpp b/include/eve/module/proba/regular/binomial_distribution.hpp deleted file mode 100644 index e3c3c80d00..0000000000 --- a/include/eve/module/proba/regular/binomial_distribution.hpp +++ /dev/null @@ -1,10 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include diff --git a/include/eve/module/proba/regular/cauchy_distribution.hpp b/include/eve/module/proba/regular/cauchy_distribution.hpp deleted file mode 100644 index a578ac1d78..0000000000 --- a/include/eve/module/proba/regular/cauchy_distribution.hpp +++ /dev/null @@ -1,10 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include diff --git a/include/eve/module/proba/regular/ev_distribution.hpp b/include/eve/module/proba/regular/ev_distribution.hpp deleted file mode 100644 index 27977be3e7..0000000000 --- a/include/eve/module/proba/regular/ev_distribution.hpp +++ /dev/null @@ -1,10 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include diff --git a/include/eve/module/proba/regular/exponential_distribution.hpp b/include/eve/module/proba/regular/exponential_distribution.hpp deleted file mode 100644 index befd11b331..0000000000 --- a/include/eve/module/proba/regular/exponential_distribution.hpp +++ /dev/null @@ -1,10 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include diff --git a/include/eve/module/proba/regular/gamma_distribution.hpp b/include/eve/module/proba/regular/gamma_distribution.hpp deleted file mode 100644 index 1ac30ddce9..0000000000 --- a/include/eve/module/proba/regular/gamma_distribution.hpp +++ /dev/null @@ -1,10 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include diff --git a/include/eve/module/proba/regular/impl/binomial_distribution.hpp b/include/eve/module/proba/regular/impl/binomial_distribution.hpp deleted file mode 100644 index e5b89bb73f..0000000000 --- a/include/eve/module/proba/regular/impl/binomial_distribution.hpp +++ /dev/null @@ -1,508 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include - -namespace eve -{ - template < typename T, typename U, typename Internal = T> - struct binomial_distribution{}; - - template < floating_ordered_value T, floating_ordered_value U> - requires compatible_values - struct binomial_distribution - { - using is_distribution_t = void; - using n_type = T; - using p_type = U; - using value_type = common_compatible_t; - using elt_t = element_type_t; - - binomial_distribution(T n_, U p_) - : n(n_), p(p_), q(oneminus(p)) - { - EVE_ASSERT(all(is_gtz(n_)), "n must be strictly positive"); - EVE_ASSERT(all(p < one(as(p)) && is_gez(p)), "p must be in ]0, 1["); - if constexpr(scalar_value) init(); - } - - using rejdata = struct - { - value_type b; - value_type a; - value_type c; - value_type vr; - value_type alpha; - value_type lpq; - value_type m; - value_type h; - }; - - EVE_FORCEINLINE void init() noexcept - requires scalar_value - { - auto spq = eve::sqrt(n*p*q); - rej.b = fma(spq, value_type(2.53), value_type(1.15)); - auto invb = rec(rej.b); - rej.a = fma(value_type(0.01), eve::min(p, q), fma(rej.b, value_type(0.0248), value_type(-0.0873))); - rej.c = fma(n, eve::min(p, q), value_type(0.5)); - rej.vr = fma(invb,value_type(-4.2), value_type(0.92)); - rej.alpha = spq*fma(invb, value_type(5.1), value_type(2.83)); - rej.lpq = eve::log(eve::min(p, q)/eve::max(p, q)); - rej.m = (floor(inc(n)*eve::min(p, q))); - rej.h = (log_abs_gamma(inc(rej.m))+log_abs_gamma(inc(n-rej.m))); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - - auto flip = half(as(p)) < p; - auto pp = (flip)? q : p; - auto qq = oneminus(pp); - if (inc(n)*p < value_type(11)) - { - auto s = pp / qq; - auto a = inc(n)*s; - R r(pow_abs(qq, n));//const ? - auto u = detail::urg01(gen, as()); - auto x(zero(as())); - auto r1(inf(as())); - auto t = u > r; - while(any(t)) - { - u = sub[t](u, r); - x = inc[t](x); - r1 = if_else(t, (a/x-s)*r, r1); - if constexpr(std::same_as) - // If r gets too small then the round-off error - // becomes a problem. At this point, p(i) is - // decreasing exponentially, so if we just call - // it 0, it's close enough. Note that the - // minimum value of q_n is about 1e-7, so we - // may need to be a little careful to make sure that - // we don't terminate the first time through the loop - // for float. (Hence the test that r is decreasing) - if(all(r1 < eps(as()) && r1 < r)) break; - r = r1; - t = u > r; - } - return x; - } - else - { - auto gen1 = [this, &gen](auto v, R& us, R& k){ - auto u = detail::urg01(gen, as())-R(0.5); - us= R(0.5)- eve::abs(u); - k = floor(fma(fma(R(2), rej.a/us, rej.b), u, rej.c)); - auto t = (us >= R(0.07)) && (v <= rej.vr); - k = if_else(t, k, allbits); - }; - auto gen2= [&](){ - R v, us, k1, k(nan(as())); - auto isknan = is_nan(k); - while (any(isknan)) - { - v = detail::urg01(gen, as()); - gen1(v, us, k1); - k = if_else(isknan, k1, k); - isknan = is_nan(k); - } - - v *= rej.alpha/(rej.a/sqr(us)+rej.b); - auto kdone = (v <= (log_abs_gamma(inc(k))+log_abs_gamma(inc(n-k))-rej.h)+(k-rej.m)*rej.lpq); - k = if_else(kdone, k, allbits); - return if_else(flip, n-k, k); - }; - - R k = nan(as()); - auto isknan = is_nan(k); - while (any(isknan)) - { - auto k1 = gen2(); - k = if_else(isknan, k1, k); - isknan = is_nan(k); - } - return k; - } - } - - - n_type n; - p_type p, q; - rejdata rej; - }; - - template < floating_ordered_value U> - struct binomial_distribution - { - using is_distribution_t = void; - using n_type = callable_one_; - using p_type = U; - using value_type = U; - using elt_t = element_type_t; - - - binomial_distribution(callable_one_ const&, U p_) - : p(p_), q(oneminus(p)) - { - EVE_ASSERT(all(p <= one(as(p)) && is_gez(p)), "p must be in [0, 1]"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return if_else(detail::urg01(gen, as()) < p, zero, one(as())); -// return binarize(detail::urg01(gen, as()) < p); - } - - p_type p, q; - }; - - template < floating_ordered_value T> - struct binomial_distribution - { - using is_distribution_t = void; - using n_type = T; - using p_type = callable_half_; - using value_type = T; - using elt_t = element_type_t; - - binomial_distribution(T n_, callable_half_ const &) - : n(n_), exp2mn(exp2(-n)) - { - EVE_ASSERT(all(is_finite(n) && is_gtz(n)), "n must be finite and strictly positive"); - if constexpr(scalar_value) init(); - } - - using rejdata = struct - { - value_type spq; - value_type b; - value_type a; - value_type c; - value_type vr; - value_type alpha; - value_type lpq; - value_type m; - value_type h; - }; - - EVE_FORCEINLINE void init() noexcept - requires scalar_value - { - const auto p = value_type(0.5); - auto spq = eve::sqrt(n)*p; - rej.b = fma(spq, value_type(2.53), value_type(1.15)); - auto invb = rec(rej.b); - rej.a = fma(value_type(0.01), p, fma(rej.b, value_type(0.0248), value_type(-0.0873))); - rej.c = fma(n, p, p); - rej.vr = fma(invb,value_type(-4.2), value_type(0.92)); - rej.alpha = spq*fma(invb, value_type(5.1), value_type(2.83)); - rej.m = floor(inc(n)*p); - rej.h = log_abs_gamma(inc(rej.m))+log_abs_gamma(inc(n-rej.m)); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - if (n < value_type(21)) - { - R r(exp2mn); - auto a = inc(n); - auto u = detail::urg01(gen, as()); - auto x(zero(as())); - auto r1(inf(as())); - auto t = u > r; - while(any(t)) - { - u = sub[t](u, r); - x = inc[t](x); - r1 = if_else(t, dec(a/x) * r, r1); - if constexpr(std::same_as) - // If r gets too small then the round-off error - // becomes a problem. At this point, p(i) is - // decreasing exponentially, so if we just call - // it 0, it's close enough. Note that the - // minimum value of q_n is about 1e-7, so we - // may need to be a little careful to make sure that - // we don't terminate the first time through the loop - // for float. (Hence the test that r is decreasing) - if(all(r1 < eps(as()) && r1 < r)) break; - r = r1; - t = u > r; - } - return x; - } - else - { - auto gen1 = [this, &gen](auto v, R& us, R& k){ - auto u = detail::urg01(gen, as())-R(0.5); - us= R(0.5)- eve::abs(u); - k = floor(fma(fma(R(2), rej.a/us, rej.b), u, rej.c)); - auto t = (us >= R(0.07)) && (v <= rej.vr); - k = if_else(t, k, allbits); - }; - auto gen2= [&](){ - R v, us, k1, k(nan(as())); - auto isknan = is_nan(k); - while (any(isknan)) - { - v = detail::urg01(gen, as()); - gen1(v, us, k1); - k = if_else(isknan, k1, k); - isknan = is_nan(k); - } - - v *= rej.alpha/(rej.a/sqr(us)+rej.b); - auto kdone = (v <= (log_abs_gamma(inc(k))+log_abs_gamma(inc(n-k)))-rej.h); - k = if_else(kdone, k, allbits); - return k; - }; - - R k = nan(as()); - auto isknan = is_nan(k); - while (any(isknan)) - { - auto k1 = gen2(); - k = if_else(isknan, k1, k); - isknan = is_nan(k); - } - return k; - } - } - - value_type n; - value_type exp2mn; - rejdata rej; - }; - - template binomial_distribution(T,U) -> binomial_distribution; - - template < floating_ordered_value T> - struct binomial_distribution - { - using is_distribution_t = void; - using n_type = callable_one_; - using p_type = callable_half_; - using value_type = T; - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return binarize(detail::urg01(gen, as()) > R(0.5)); - } - - constexpr binomial_distribution( as const&) {} - }; - - template binomial_distribution(as const&) -> binomial_distribution; - - template - inline constexpr auto bernouilli = binomial_distribution(as{}); - - namespace detail - { - ////////////////////////////////////////////////////// - /// cdf - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , binomial_distribution const & d - , V const &x ) noexcept - { - auto k = floor(x); - if constexpr(floating_value && floating_value) - return if_else(is_ltz(x), zero, if_else(x < one(as(x)), betainc(d.q, d.n-k, inc(k)), one)); - else if constexpr(std::same_as && floating_value) - return if_else(is_ltz(x), zero, if_else(x < one(as(x)), d.q, one)); - else if constexpr(std::same_as && floating_value) - return betainc(half(as(x)), d.n-k, inc(k)); - else - return if_else(is_ltz(x), zero, if_else(x < one(as(x)), half(as(x)), one)); - } - - ////////////////////////////////////////////////////// - /// pmf - template - EVE_FORCEINLINE auto pmf_(EVE_SUPPORTS(cpu_) - , binomial_distribution const & d - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - { - auto fk = eve::min(eve::max(floor(x), zero(as(x))), d.n); - auto nmk = d.n-fk; - return pow_abs(d.p, fk)*pow_abs(d.q, nmk)*beta(inc(fk), inc(nmk))/inc(d.n); - } - else if constexpr(std::same_as && floating_value) - { - auto fk = eve::min(eve::max(floor(x), zero(as(x))), one(as(x))); - return if_else(is_eqz(fk), d.q, if_else(fk == one(as(fk)), d.p, zero)); - } - else if constexpr(std::same_as && floating_value) - { - auto fk = eve::min(eve::max(floor(x), zero(as(x))), d.n); - auto nmk = d.n-fk; - return d.exp2mn*beta(inc(fk), inc(nmk)*half(as(x))); - } - else - return if_else(is_eqz(x) || (x == one(as(x))), half(as(x)), zero); - } - - ////////////////////////////////////////////////////// - /// mgf - template - EVE_FORCEINLINE auto mgf_(EVE_SUPPORTS(cpu_) - , binomial_distribution const & d - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - { - return pow_abs(fma(d.p, exp(x), d.q), d.n); - } - else if constexpr(std::same_as && floating_value) - { - return fma(d.p, exp(x), d.q); - } - else if constexpr(std::same_as && floating_value) - { - return eve::sqrt(fma(d.p, exp(x), d.q)); - } - else - return half(as(x))*inc(exp(x)); - } - - ////////////////////////////////////////////////////// - /// median - template - EVE_FORCEINLINE auto median_(EVE_SUPPORTS(cpu_) - , binomial_distribution const & d) noexcept - { - if constexpr (floating_value && floating_value) - return floor(d.p*d.n); - else if constexpr (floating_value) - return floor(d.p); - else if constexpr (floating_value) - return floor(half(as())*d.n); - else - return zero(as()); - } - - - ////////////////////////////////////////////////////// - /// mean - template - EVE_FORCEINLINE auto mean_(EVE_SUPPORTS(cpu_) - , binomial_distribution const &d) noexcept - { - if constexpr (floating_value && floating_value) - return d.p*d.n; - else if constexpr (floating_value) - return d.p; - else if constexpr (floating_value) - return half(as())*d.n ; - else - return half(as()); - } - - ////////////////////////////////////////////////////// - /// mode - template - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_) - , binomial_distribution const & d) noexcept - { - return median(d); - } - - ////////////////////////////////////////////////////// - /// entropy - template - EVE_FORCEINLINE auto entropy_(EVE_SUPPORTS(cpu_) - , binomial_distribution const & d) noexcept - { - auto twopie = T(17.0794684453471341309271017390931489900697770715304); - if constexpr (floating_value && floating_value) - return half(as())*eve::log(twopie*d.n*d.p*d.q); // + o(1/n) - else if constexpr (floating_value) - return half(as())*eve::log(twopie*d.n*U(0.25)); // + o(1/n) - else if constexpr (floating_value) - return half(as())*eve::log(twopie*d.p*d.q); // + o(1/n) - else - return half(as())*eve::log(twopie*I(0.25)); // + o(1/n) - } - - - ////////////////////////////////////////////////////// - /// skewness - template - EVE_FORCEINLINE auto skewness_(EVE_SUPPORTS(cpu_) - , binomial_distribution const & d ) noexcept - { - if constexpr (floating_value) - return (d.q-d.p)/stdev(d); - else if constexpr (floating_value) - return zero(as()); - else - return zero(as()); - } - - ////////////////////////////////////////////////////// - /// kurtosis - template - EVE_FORCEINLINE auto kurtosis_(EVE_SUPPORTS(cpu_) - , binomial_distribution const & d) noexcept - { - if constexpr (floating_value) - return oneminus(6*d.p*d.q)/var(d); - else if constexpr (floating_value) - return half(as())/var(d); - else - return I(-2); - } - - ////////////////////////////////////////////////////// - /// var - template - EVE_FORCEINLINE auto var_(EVE_SUPPORTS(cpu_) - , binomial_distribution const & d) noexcept - { - if constexpr (floating_value&&(floating_value)) - return d.n*d.p*d.q; - else if constexpr (floating_value) - return T(0.25)*d.n; - else if constexpr (floating_value) - return d.p*d.q; - else - return I(0.25); - } - - ////////////////////////////////////////////////////// - /// stdev - template - EVE_FORCEINLINE auto stdev_(EVE_SUPPORTS(cpu_) - , binomial_distribution const & d) noexcept - { - if constexpr (floating_value&&(floating_value)) - return eve::sqrt(d.n*d.p*d.q); - else if constexpr (floating_value) - return T(0.5)*eve::sqrt(d.n); - else if constexpr (floating_value) - return eve::sqrt(d.p*d.q); - else - return I(0.5); - } - } -} diff --git a/include/eve/module/proba/regular/impl/cauchy_distribution.hpp b/include/eve/module/proba/regular/impl/cauchy_distribution.hpp deleted file mode 100644 index 93498b026d..0000000000 --- a/include/eve/module/proba/regular/impl/cauchy_distribution.hpp +++ /dev/null @@ -1,272 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include - -namespace eve -{ - template - struct cauchy_distribution{}; - - template < floating_ordered_value T, floating_ordered_value U> - requires compatible_values - struct cauchy_distribution - { - using is_distribution_t = void; - using m_type = T; - using s_type = U; - using value_type = common_compatible_t; - - cauchy_distribution(T m_, U s_) - : m(m_), s(s_) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - template < floating_ordered_value TT, floating_ordered_value UU> - requires std::constructible_from && std::constructible_from - cauchy_distribution(TT m_, UU s_) - : m(T(m_)), s(U(s_)) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - m_type m; - s_type s; - }; - - template - struct cauchy_distribution - { - using is_distribution_t = void; - using m_type = callable_zero_; - using s_type = U; - using value_type = U; - - cauchy_distribution(callable_zero_ const&, U s_) - : s(s_) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - } - - template < floating_ordered_value UU> - requires std::constructible_from - cauchy_distribution(callable_zero_ const & , UU s_) - : s(U(s_)) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - s_type s; - }; - - template < floating_ordered_value T> - struct cauchy_distribution - { - using is_distribution_t = void; - using m_type = T; - using s_type = decltype(eve::one); - using value_type = T; - - cauchy_distribution(T m_, callable_one_ const &) - : m(m_) - { - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - template < floating_ordered_value TT> - requires std::constructible_from - cauchy_distribution(TT m_, callable_one_ const &) - : m(T(m_)) - { - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - m_type m; - }; - - template cauchy_distribution(T,U) -> cauchy_distribution; - - template < floating_ordered_value T> - struct cauchy_distribution - { - using is_distribution_t = void; - using m_type = callable_zero_; - using s_type = callable_one_; - using value_type = T; - constexpr cauchy_distribution( as const&) {} - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - }; - - template cauchy_distribution(as const&) -> cauchy_distribution; - - template - inline constexpr auto cauchy_distribution_01 = cauchy_distribution(as{}); - - namespace detail - { - ////////////////////////////////////////////////////// - /// cdf - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , cauchy_distribution const & ca - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - return half(as(x)) + atanpi((x-ca.m)/ca.s); - else if constexpr(std::same_as && floating_value) - return half(as(x)) + atanpi(x/ca.s); - else if constexpr(std::same_as && floating_value) - return half(as(x)) + atanpi(x-ca.m); - else - return half(as(x)) + atanpi(x); - } - - ////////////////////////////////////////////////////// - /// pdf - template - EVE_FORCEINLINE auto pdf_(EVE_SUPPORTS(cpu_) - , cauchy_distribution const & ca - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - { - auto xmm = (x-ca.m); - return ca.s/(pi(as(x))*(sqr(ca.s)+sqr(xmm))); - } - else if constexpr(std::same_as && floating_value) - return ca.s/(pi(as(x))*(sqr(ca.s)+sqr(x))); - else if constexpr(std::same_as && floating_value) - { - auto xmm = (x-ca.m); - return rec(pi(as(x))*(inc(sqr(xmm)))); - } - else - return rec(pi(as(x))*(inc(sqr(x)))); - } - - ////////////////////////////////////////////////////// - /// invcdf - template - EVE_FORCEINLINE auto invcdf_(EVE_SUPPORTS(cpu_) - , cauchy_distribution const & ca - , V const &x ) noexcept - { - using U1 = std::conditional_t), U, I>; - using T1 = std::conditional_t),T, U1>; - using r_t = common_compatible_t; - r_t tmp; - if constexpr(floating_value && floating_value) - tmp = fma(tanpi(x-half(as(x))), ca.s, ca.m); - else if constexpr(std::same_as && floating_value) - tmp = tanpi(x-half(as(x)))*ca.s; - else if constexpr(std::same_as && floating_value) - tmp = tanpi(x-half(as(x)))+ca.m; - else - tmp = tanpi(x-half(as(x))); - - // as x is quarter_circle to [0, 1] limits values at 0 and 1 are properly defined - tmp = if_else(is_eqz(x), minf(as(x)), tmp); - tmp = if_else(x == one(as(x)), inf(as(x)), tmp); - return if_else(is_ltz(x) || x > one(as(x)), allbits, tmp); - } - - ////////////////////////////////////////////////////// - /// median - template - EVE_FORCEINLINE auto median_(EVE_SUPPORTS(cpu_) - , cauchy_distribution const & ca) noexcept - { - if constexpr (floating_value) - return ca.m; - else if constexpr (floating_value) - return zero(as()); - else - return zero(as()); - } - - ////////////////////////////////////////////////////// - /// scale - template - EVE_FORCEINLINE auto scale_(EVE_SUPPORTS(cpu_) - , cauchy_distribution const & ca) noexcept - { - if constexpr (floating_value) - return ca.s; - else if constexpr (floating_value) - return one(as()); - else - return one(as()); - } - - ////////////////////////////////////////////////////// - /// mode - template - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_) - , cauchy_distribution const & ca) noexcept - { - return median(ca); - } - - - ////////////////////////////////////////////////////// - /// entropy - template - EVE_FORCEINLINE auto entropy_(EVE_SUPPORTS(cpu_) - , cauchy_distribution const & ca) noexcept - { - if constexpr (floating_value) - return log(4*pi(as(ca.s))*ca.s); - else - return I(2.531024246969291); - } - - ////////////////////////////////////////////////////// - /// fisher - template - EVE_FORCEINLINE auto fisher_(EVE_SUPPORTS(cpu_) - , cauchy_distribution const & ca) noexcept - { - if constexpr (floating_value) - return rec(2*sqr(ca.s)); - else - return I(0.5); - } - } -} diff --git a/include/eve/module/proba/regular/impl/ev_distribution.hpp b/include/eve/module/proba/regular/impl/ev_distribution.hpp deleted file mode 100644 index d45b447cb7..0000000000 --- a/include/eve/module/proba/regular/impl/ev_distribution.hpp +++ /dev/null @@ -1,370 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace eve -{ - template < typename T, typename U, typename Internal = T> - struct ev_distribution{}; - - template < floating_ordered_value T, floating_ordered_value U> - requires compatible_values - struct ev_distribution - { - using is_distribution_t = void; - using m_type = T; - using s_type = U; - using value_type = common_compatible_t; - using parameters = struct { value_type m; value_type s;}; - - ev_distribution(T m_, U s_) - : m(m_), s(s_) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - parameters params() const noexcept - { - return { .m = m, .s = s }; - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - m_type m; - s_type s; - }; - - template < floating_ordered_value U> - struct ev_distribution - { - using is_distribution_t = void; - using m_type = callable_zero_; - using s_type = U; - using value_type = U; - using parameters = struct { callable_zero_ m; value_type s; }; - - ev_distribution(callable_zero_ const&, U s_) - : s(s_) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - } - - ev_distribution(parameters const & p) - : s(p.s) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - parameters params() const noexcept - { - return { .m = zero, .s = s }; - } - - - s_type s; - }; - - template < floating_ordered_value T> - struct ev_distribution - { - using is_distribution_t = void; - using m_type = T; - using s_type = decltype(eve::one); - using value_type = T; - using parameters = struct { value_type m; callable_one_ s; }; - - ev_distribution(T m_, callable_one_ const &) - : m(m_) - { - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - ev_distribution(parameters const & p) - : m(p.m) - { - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - parameters params() const noexcept - { - return { .m = m, .s = one }; - } - - m_type m; - }; - - template ev_distribution(T,U) -> ev_distribution; - - template < floating_ordered_value T> - struct ev_distribution - { - using is_distribution_t = void; - using m_type = callable_zero_; - using s_type = callable_one_; - using value_type = T; - using parameters = struct { callable_zero_ m; callable_one_ s; }; - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - parameters params() const noexcept - { - return { .m = zero, .s = one }; - } - - constexpr ev_distribution( as const&) {} - }; - - - template ev_distribution(as const&) -> ev_distribution; - - template - inline constexpr auto ev_distribution_01 = ev_distribution(as{}); - - namespace detail - { - ////////////////////////////////////////////////////// - /// cdf - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , ev_distribution const & d - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - return -expm1(-exp((x-d.m)/d.s)); - else if constexpr(floating_value) - return -expm1(-exp(x/d.s)); - else if constexpr(floating_value) - return -expm1(-exp(x-d.m)); - else - return -expm1(-exp(x)); - } - - ////////////////////////////////////////////////////// - /// pdf - template - EVE_FORCEINLINE auto pdf_(EVE_SUPPORTS(cpu_) - , ev_distribution const & d - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - { - auto invs = rec(d.s); - auto red = exp((x-d.m)*invs); - return red*exp(-red)*invs; - } - else if constexpr(floating_value) - { - auto invs = rec(d.s); - auto red = exp(x*invs); - return red*exp(-red)*invs; - - } - else if constexpr(floating_value) - { - auto red = exp(x-d.m); - return red*exp(-red); - } - else - { - auto red = exp(x); - return red*exp(-red); - } - } - - ////////////////////////////////////////////////////// - /// invcdf - template - EVE_FORCEINLINE auto invcdf_(EVE_SUPPORTS(cpu_) - , ev_distribution const & d - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - { - return fma(log(-log1p(-x)), d.s, d.m); - } - else if constexpr(std::same_as && floating_value) - { - return log(-log1p(-x))*d.s; - } - else if constexpr(std::same_as && floating_value) - { - return log(-log1p(-x))+d.m; - } - else - return log(-log1p(-x)); - } - - ////////////////////////////////////////////////////// - /// median - template - EVE_FORCEINLINE auto median_(EVE_SUPPORTS(cpu_) - , ev_distribution const & d) noexcept - { - using v_t = typename ev_distribution::value_type; - v_t mll2 = v_t(3.665129205816643e-01); - if constexpr (floating_value) - return fma(d.s, mll2, d.m); - else if constexpr (floating_value) - return d.s* mll2; - else if constexpr (floating_value) - return mll2+d.m; - else - return mll2; - } - - - ////////////////////////////////////////////////////// - /// mean - template - EVE_FORCEINLINE auto mean_(EVE_SUPPORTS(cpu_) - , ev_distribution const &d) noexcept - { - using v_t = typename ev_distribution::value_type; - v_t gamma(0.57721566490153286); - if constexpr (floating_value) - return fma(d.s, gamma, d.m); - else if constexpr (floating_value) - return d.s* gamma; - else if constexpr (floating_value) - return gamma+d.m; - else - return gamma; - } - - ////////////////////////////////////////////////////// - /// mode - template - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_) - , ev_distribution const & d) noexcept - { - if constexpr (floating_value) - return d.m; - else - return T{}(as::value_type>()); - } - - ////////////////////////////////////////////////////// - /// entropy - template - EVE_FORCEINLINE auto entropy_(EVE_SUPPORTS(cpu_) - , ev_distribution const & d) noexcept - { - using v_t = typename ev_distribution::value_type; - v_t igamma = T(1.57721566490153286); - if constexpr (floating_value) - return log(d.s)+igamma; - else - return igamma; - } - - ////////////////////////////////////////////////////// - /// skewness - template - EVE_FORCEINLINE auto skewness_(EVE_SUPPORTS(cpu_) - , ev_distribution const & ) noexcept - { - return I(1.13954709940464865749279301890499273124112364236172); - } - - ////////////////////////////////////////////////////// - /// kurtosis - template - EVE_FORCEINLINE auto kurtosis_(EVE_SUPPORTS(cpu_) - , ev_distribution const & ) noexcept - { - return I(2.4); - } - - ////////////////////////////////////////////////////// - /// var - template - EVE_FORCEINLINE auto var_(EVE_SUPPORTS(cpu_) - , ev_distribution const & d) noexcept - { - using v_t = typename ev_distribution::value_type; - v_t pi2o6(1.644934066848226436472415166646025189218949901206); - if constexpr (floating_value) - return sqr(d.s)*pi2o6; - else - return pi2o6; - } - - ////////////////////////////////////////////////////// - /// stdev - template - EVE_FORCEINLINE auto stdev_(EVE_SUPPORTS(cpu_) - , ev_distribution const & d) noexcept - { - using v_t = typename ev_distribution::value_type; - v_t sqrtpi2o6(1.2825498301618640955440363596710064114672606675640); - if constexpr (floating_value) - return d.s*sqrtpi2o6; - else - return sqrtpi2o6; - } - - ////////////////////////////////////////////////////// - /// confidence - template - EVE_FORCEINLINE auto confidence_(EVE_SUPPORTS(cpu_) - , ev_distribution const & d - , R const & x - , std::array const & cov - , A const & alpha ) noexcept - { - using v_t = typename ev_distribution::value_type; - R z = x; - auto normz = -invcdf(normal_distribution_01, alpha*v_t(0.5)); - auto halfwidth = normz; - if constexpr(floating_ordered_value && floating_ordered_value) - z = (z-d.m)/d.s; - else if constexpr(floating_ordered_value) - z -= d.m; - else if constexpr(floating_ordered_value) - z /= d.s; - auto zvar = fma(fma(cov[3], z, 2*cov[1]), z, cov[0]); - halfwidth *= eve::sqrt(zvar); - if constexpr(floating_ordered_value) - halfwidth /= d.s; - auto d01 = ev_distribution_01; - return kumi::make_tuple(cdf(d01, z), cdf(d01, z-halfwidth), cdf(d01, z+halfwidth)); - } - } -} diff --git a/include/eve/module/proba/regular/impl/exponential_distribution.hpp b/include/eve/module/proba/regular/impl/exponential_distribution.hpp deleted file mode 100644 index 23ca13b9f2..0000000000 --- a/include/eve/module/proba/regular/impl/exponential_distribution.hpp +++ /dev/null @@ -1,250 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace eve -{ - template < typename T, typename Internal = T> - struct exponential_distribution{}; - - template < floating_ordered_value T> - struct exponential_distribution - { - using is_distribution_t = void; - using lambda_type = T; - using value_type = T; - - exponential_distribution(T lambda_) : lambda(lambda_) { - EVE_ASSERT(all(is_gtz(lambda) && is_finite(lambda)), "lambda must be strictly positive and finite"); - } - template < floating_ordered_value TT> - requires std::constructible_from - exponential_distribution(TT lambda_) - : lambda(T(lambda_)) - { - EVE_ASSERT(all(is_gtz(lambda) && is_finite(lambda)), "lambda must be strictly positive and finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - exponential_distribution() : lambda(T(1)) {} - - lambda_type lambda; - }; - - - template exponential_distribution(T) -> exponential_distribution; - - template < floating_ordered_value T> - struct exponential_distribution < callable_one_, T> - { - using is_distribution_t = void; - using lambda_type = callable_one_; - using value_type = T; - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - constexpr exponential_distribution( as const&) {} - }; - - template exponential_distribution(as const&) -> exponential_distribution; - - template - inline constexpr auto exponential_distribution_1 = exponential_distribution(as{}); - - - namespace detail - { - ////////////////////////////////////////////////////// - /// cdf - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &expo - , U const &x ) noexcept - { - if constexpr(floating_value) - return -expm1(if_else(is_ltz(x), zero, -x*expo.lambda)); - else - return -expm1(if_else(is_ltz(x), zero, -x)); - } - - ////////////////////////////////////////////////////// - /// pdf - template - EVE_FORCEINLINE auto pdf_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &expo - , U const &x ) noexcept - { - if constexpr(floating_value) - return expo.lambda*exp(-expo.lambda*x); - else - return exp(-x); - } - - ////////////////////////////////////////////////////// - /// invcdf - template - EVE_FORCEINLINE auto invcdf_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &expo - , U const &p ) noexcept - { - if constexpr(floating_value) - return -log1p(-p)/expo.lambda; - else - return -log1p(-p); - } - - ////////////////////////////////////////////////////// - /// mgf - template - EVE_FORCEINLINE auto mgf_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &expo - , U const &t ) noexcept - { - if constexpr(floating_value) - return if_else(t < expo.lambda, expo.lambda/(expo.lambda-t), allbits); - else - return if_else(t - EVE_FORCEINLINE auto mean_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &expo) noexcept - { - if constexpr(floating_value) - return rec(expo.lambda); - else - return one(as()); - } - - - ////////////////////////////////////////////////////// - /// median - template - EVE_FORCEINLINE auto median_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &expo) noexcept - { - if constexpr(floating_value) - return log_2(as())*rec(expo.lambda); - else - return log_2(as()); - } - - ////////////////////////////////////////////////////// - /// mode - template - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &) noexcept - { - return zero(as()); - } - - ////////////////////////////////////////////////////// - /// var - template - EVE_FORCEINLINE auto var_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &expo) noexcept - { - if constexpr(floating_value) - return sqr(rec(expo.lambda)); - else - return one(as()); - } - - - ////////////////////////////////////////////////////// - /// stdev - template - EVE_FORCEINLINE auto stdev_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &expo) noexcept - { - if constexpr(floating_value) - return rec(expo.lambda); - else - return one(as()); - } - - ////////////////////////////////////////////////////// - /// skewness - template - EVE_FORCEINLINE auto skewness_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &) noexcept - { - return I(2); - } - - ////////////////////////////////////////////////////// - /// kurtosis - template - EVE_FORCEINLINE auto kurtosis_(EVE_SUPPORTS(cpu_) - , exponential_distribution const &) noexcept - { - return I(6); - } - - ////////////////////////////////////////////////////// - /// entropy - template - EVE_FORCEINLINE auto entropy_(EVE_SUPPORTS(cpu_) - , exponential_distribution const & expo) noexcept - { - if constexpr(floating_value) - return oneminus(log(expo.lambda)); - else - return one(as()); - } - - ////////////////////////////////////////////////////// - /// fisher - template - EVE_FORCEINLINE auto fisher_(EVE_SUPPORTS(cpu_) - , exponential_distribution const & expo) noexcept - { - if constexpr(floating_value) - return sqr(rec(expo.lambda)); - else - return one(as()); - } - - template - EVE_FORCEINLINE auto confidence_(EVE_SUPPORTS(cpu_) - , exponential_distribution const & d - , R const & x - , V const & pcov - , A const & alpha ) noexcept - { - using v_t = typename exponential_distribution::value_type; - R z = if_else(is_ltz(x), zero, x); - if constexpr(floating_ordered_value) z*= d.lambda; - auto normz = -invcdf(normal_distribution_01, alpha*v_t(0.5)); - auto halfwidth = normz*eve::sqrt(pcov); - if constexpr(floating_ordered_value) halfwidth *= d.lambda; - auto exp_halfwidth = eve::exp(halfwidth); - return kumi::make_tuple(-expm1(-z), -expm1(-z/exp_halfwidth), -expm1(-z*exp_halfwidth)); - } - - } -} diff --git a/include/eve/module/proba/regular/impl/gamma_distribution.hpp b/include/eve/module/proba/regular/impl/gamma_distribution.hpp deleted file mode 100644 index 2a205f2f42..0000000000 --- a/include/eve/module/proba/regular/impl/gamma_distribution.hpp +++ /dev/null @@ -1,402 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace eve -{ - template < typename T, typename U, typename Internal = T> - struct gamma_distribution{}; - - template < floating_ordered_value T, floating_ordered_value U> - requires compatible_values - struct gamma_distribution - { - using is_distribution_t = void; - using k_type = T; - using theta_type = U; - using value_type = common_compatible_t; - using parameters = struct { value_type m; value_type s; }; - - gamma_distribution(T k_, U theta_) - : k(k_), theta(theta_), invgk(tgamma(k_)) - { - EVE_ASSERT(all(is_gtz(theta) && is_finite(theta)), "theta must be strictly positive and finite"); - EVE_ASSERT(all(is_gtz(k) && is_finite(k)), "k must be strictly positive and finite"); - } - - gamma_distribution(parameters const & p) - : k(p.k), theta(p.theta) - { - EVE_ASSERT(all(is_gtz(theta) && is_finite(theta)), "theta must be strictly positive and finite"); - EVE_ASSERT(all(is_gtz(k) && is_finite(k)), "k must be strictly positive and finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - parameters params() const noexcept - { - return { .k = k, .theta = theta }; - } - - k_type k; - theta_type theta; - value_type invgk; - }; - - template < floating_ordered_value U> - struct gamma_distribution - { - using is_distribution_t = void; - using k_type = callable_one_; - using theta_type = U; - using value_type = U; - using parameters = struct { callable_one_ m; value_type s;}; - - gamma_distribution(callable_one_ const&, U theta_) - : theta(theta_) - { - EVE_ASSERT(all(is_gtz(theta) && is_finite(theta)), "theta must be strictly positive and finite"); - } - - gamma_distribution(parameters const & p) - : theta(p.theta) - { - EVE_ASSERT(all(is_gtz(theta) && is_finite(theta)), "theta must be strictly positive and finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - parameters params() noexcept - { - return { .k = one, .theta = theta }; - } - - theta_type theta; - }; - - template < floating_ordered_value T> - struct gamma_distribution - { - using is_distribution_t = void; - using k_type = T; - using theta_type = decltype(eve::one); - using value_type = T; - using parameters = struct { value_type m; callable_one_ s;}; - - gamma_distribution(T k_, callable_one_ const &) - : k(k_) - { - EVE_ASSERT(all(is_gtz(k) && is_finite(k)), "k must be strictly positive and finite"); - } - - gamma_distribution(parameters const & p) - : k(p.k) - { - EVE_ASSERT(all(is_gtz(k) && is_finite(k)), "k must be strictly positive and finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return invcdf(*this, detail::urg01(gen, as())); - } - - parameters params() noexcept - { - return { .k = k, .theta = one }; - } - - k_type k; - }; - - template gamma_distribution(T,U) -> gamma_distribution; - - template < floating_ordered_value T> - struct gamma_distribution - { - using is_distribution_t = void; - using k_type = callable_zero_; - using theta_type = callable_one_; - using value_type = T; - using parameters = struct { callable_one_ m; callable_one_ s;}; - - - gamma_distribution(parameters const & ) { } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - auto d = exponential_distribution_1; - return d(gen, as(R())); - } - - parameters params() noexcept - { - return { .k = one, .theta = one }; - } - - constexpr gamma_distribution( as const&) {} - }; - - - template gamma_distribution(as const&) -> gamma_distribution; - - template - inline constexpr auto gamma_distribution_11 = gamma_distribution(as{}); - - namespace detail - { - ////////////////////////////////////////////////////// - /// pdf - template - EVE_FORCEINLINE auto pdf_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - return if_else(is_gtz(x), d.invgk*pow_abs(x/d.theta, d.k)*exp(-x/d.theta)/x, zero); - else if constexpr(std::same_as && floating_value) - return if_else(is_gtz(x), exp(-x/d.theta)/d.theta, zero); - else if constexpr(std::same_as && floating_value) - return if_else(is_gtz(x), d.invgk*pow_abs(x, dec(d.k))*exp(-x), zero); - else - return if_else(is_gtz(x), exp(-x), zero); - } - - ////////////////////////////////////////////////////// - /// cdf - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - { - return eve::gamma_p(if_else(is_ltz(x), zero, x/d.theta), d.k); - } - else if constexpr(floating_value) - { - return -eve::expm1(if_else(is_ltz(x), zero,-x/d.theta)); - } - else if constexpr(floating_value) - { - return eve::gamma_p(if_else(is_ltz(x), zero, x), d.k); - } - else - return -eve::expm1(if_else(is_ltz(x), zero,-x)); - } - - ////////////////////////////////////////////////////// - /// mgf - template - EVE_FORCEINLINE auto mgf_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d - , V const &x ) noexcept - { - auto invsqrt_2pi = V(0.39894228040143267793994605993438186847585863116493); - if constexpr(floating_value && floating_value) - { - return pow_abs(oneminus(d.theta*x), -d.k); - } - else if constexpr(floating_value) - { - return rec(oneminus(x*d.theta)); - } - else if constexpr(std::same_as && floating_value) - { - return pow_abs(oneminus(x), -d.k);; - } - else - return rec(oneminus(x)); - } - - ////////////////////////////////////////////////////// - /// invcdf - template - EVE_FORCEINLINE auto invcdf_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d - , V const &p ) noexcept - { - if constexpr(floating_value && floating_value) - { - return gamma_p_inv( p, d.k)*d.theta; - } - else if constexpr(std::same_as && floating_value) - { - return -log1p(-p)*d.theta; - } - else if constexpr(std::same_as && floating_value) - { - return inc(gamma_p_inv(p, d.k)); - } - else - return -log1p(-p); - } - - ////////////////////////////////////////////////////// - /// mean - template - EVE_FORCEINLINE auto mean_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d) noexcept - { - if constexpr (floating_value && floating_value) - return d.k*d.theta; - else if constexpr (floating_value) - return d.k; - else if constexpr (floating_value) - return d.theta; - else - return one(as()); - } - - - ////////////////////////////////////////////////////// - /// mode - template - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d) noexcept - { - if constexpr (floating_value && floating_value) - return if_else(d.k > one(as(d.k)), dec(d.k)*d.theta, zero); - else if constexpr (floating_value && std::same_as) - return if_else(d.k > one(as(d.k)), dec(d.k), zero); - else if constexpr (floating_value && std::same_as) - return zero(as()); - else if constexpr (std::same_as && std::same_as) - return zero(as()); - } - - ////////////////////////////////////////////////////// - /// entropy - template - EVE_FORCEINLINE auto entropy_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d) noexcept - { - if constexpr (floating_value && floating_value) - return d.k+eve::log(d.theta)+ log_abs_gamma(d.k)+oneminus(d.k)*digamma(d.k); - else if constexpr (floating_value) - return d.k+ log_abs_gamma(d.k)+oneminus(d.k)*digamma(d.k); - else if constexpr (floating_value) - return inc(eve::log(d.theta)); - else - return one(as()); - } - - - ////////////////////////////////////////////////////// - /// skewness - template - EVE_FORCEINLINE auto skewness_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d) noexcept - { - if constexpr (floating_value) - return 2/eve::sqrt(d.k); - else - return I(2); - } - - ////////////////////////////////////////////////////// - /// kurtosis - template - EVE_FORCEINLINE auto kurtosis_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d) noexcept - { - if constexpr (floating_value) - return 6/d.k; - else - return I(6); - } - - ////////////////////////////////////////////////////// - /// var - template - EVE_FORCEINLINE auto var_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d) noexcept - { - if constexpr (floating_value && floating_value) - return d.k*sqr(d.theta); - else if constexpr (floating_value) - return d.k; - else if constexpr (floating_value) - return sqr(d.theta); - else - return one(as()); - } - - ////////////////////////////////////////////////////// - /// stdev - template - EVE_FORCEINLINE auto stdev_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d) noexcept - { - if constexpr (floating_value && floating_value) - return eve::sqrt(d.k)*d.theta; - else if constexpr (floating_value) - return eve::sqrt(d.k); - else if constexpr (floating_value) - return d.theta; - else - return one(as()); - } - - ////////////////////////////////////////////////////// - /// confidence - template - EVE_FORCEINLINE auto confidence_(EVE_SUPPORTS(cpu_) - , gamma_distribution const & d - , R const & p - , std::array const & pcov - , A const & alpha ) noexcept - { - using v_t = typename normal_distribution::value_type; - auto z = cdf(d, p); - auto l = eve::log(p/(1-p)); - auto dp = rec(p*(1-p)); - auto k = one(as()); - if constexpr(floating_ordered_value) k = d.k; - auto dgamma_p = [](auto x, auto k){ return exp(dec(k) * log(x) - x - log_abs_gamma(k));}; - auto da = dgamma_p(z, k)* dp; - R db; - if constexpr(floating_ordered_value && floating_ordered_value) - db = eve::exp(k*eve::log(z)-z-eve::log_abs_gamma(k)+eve::log(d.theta))* dp; - else if constexpr(floating_ordered_value) - db = -eve::exp(k*eve::log(z)-z-eve::log_abs_gamma(k))* dp; - else if constexpr(floating_ordered_value) - db = -eve::exp(eve::log(z)-z+eve::log(d.theta))* dp; - else - db = -eve::exp(eve::log(z)-z)*dp; - auto varL = fma(da, fma(pcov[0], da, 2*pcov[1]*db), pcov[2]*sqr(db)); - auto halfwidth = -invcdf(normal_distribution_01, alpha*v_t(0.5))*eve::sqrt(varL); - auto expllo = exp(l - halfwidth); - auto explup = exp(l + halfwidth); - auto plo = expllo/inc(expllo); - auto pup = explup/inc(explup); - return kumi::make_tuple(p, plo, pup); - } - } -} diff --git a/include/eve/module/proba/regular/impl/lognormal_distribution.hpp b/include/eve/module/proba/regular/impl/lognormal_distribution.hpp deleted file mode 100644 index 6d6d0fe362..0000000000 --- a/include/eve/module/proba/regular/impl/lognormal_distribution.hpp +++ /dev/null @@ -1,370 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace eve -{ - template < typename T, typename U, typename Internal = T> - struct lognormal_distribution{}; - - template < floating_ordered_value T, floating_ordered_value U> - requires compatible_values - struct lognormal_distribution - { - using is_distribution_t = void; - using m_type = T; - using s_type = U; - using value_type = common_compatible_t; - using parameters = struct { value_type m; value_type s;}; - - lognormal_distribution(T m_, U s_) - : m(m_), s(s_) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - parameters params() const noexcept - { - return { .m = m, .s = s }; - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - auto n = normal_distribution(m, s); - return exp(n(gen, as())); - } - - m_type m; - s_type s; - }; - - template < floating_ordered_value U> - struct lognormal_distribution - { - using is_distribution_t = void; - using m_type = callable_zero_; - using s_type = U; - using value_type = U; - using parameters = struct { callable_zero_ m; value_type s; }; - - lognormal_distribution(callable_zero_ const&, U s_) - : s(s_) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - } - - lognormal_distribution(parameters const & p) - : s(p.s) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - auto n = normal_distribution(zero, s); - return exp(n(gen, as())); - } - - parameters params() const noexcept - { - return { .m = zero, .s = s }; - } - - - s_type s; - }; - - template < floating_ordered_value T> - struct lognormal_distribution - { - using is_distribution_t = void; - using m_type = T; - using s_type = decltype(eve::one); - using value_type = T; - using parameters = struct { value_type m; callable_one_ s; }; - - lognormal_distribution(T m_, callable_one_ const &) - : m(m_) - { - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - lognormal_distribution(parameters const & p) - : m(p.m) - { - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - auto n = normal_distribution(m, one); - return exp(n(gen, as())); - } - - parameters params() const noexcept - { - return { .m = m, .s = one }; - } - - m_type m; - }; - - template lognormal_distribution(T,U) -> lognormal_distribution; - - template < floating_ordered_value T> - struct lognormal_distribution - { - using is_distribution_t = void; - using m_type = callable_zero_; - using s_type = callable_one_; - using value_type = T; - using parameters = struct { callable_zero_ m; callable_one_ s; }; - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - auto n = normal_distribution_01; - return exp(n(gen, as())); - } - - parameters params() const noexcept - { - return { .m = zero, .s = one }; - } - - constexpr lognormal_distribution( as const&) {} - }; - - - template lognormal_distribution(as const&) -> lognormal_distribution; - - template - inline constexpr auto lognormal_distribution_01 = lognormal_distribution(as{}); - - namespace detail - { - ////////////////////////////////////////////////////// - /// cdf - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d - , V const &x ) noexcept - { - auto [m, s] = d.params(); - if constexpr(floating_value || floating_value) - return if_else(is_gtz(x), cdf(normal_distribution(m, s), eve::log(x)), zero); - else - return if_else(is_gtz(x), cdf(normal_distribution_01, eve::log(x)), zero); - } - - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , raw_type const & - , lognormal_distribution const &d - , V const &x ) noexcept - { - auto [m, s] = d.params(); - if constexpr(floating_value || floating_value) - return if_else(is_gtz(x), raw(cdf)(normal_distribution(m, s), eve::log(x)), zero); - else - return if_else(is_gtz(x), raw(cdf)(normal_distribution_01, eve::log(x)), zero); - } - - ////////////////////////////////////////////////////// - /// pdf - template - EVE_FORCEINLINE auto pdf_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d - , V const &x ) noexcept - { - auto [m, s] = d.params(); - if constexpr(floating_value || floating_value) - return if_else(is_gtz(x), pdf(normal_distribution(m, s), eve::log(x))/x, zero); - else - return if_else(is_gtz(x), pdf(normal_distribution_01, eve::log(x))/x, zero); - } - - ////////////////////////////////////////////////////// - /// invcdf - template - EVE_FORCEINLINE auto invcdf_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d - , V const &x ) noexcept - { - auto [m, s] = d.params(); - if constexpr(floating_value || floating_value) - return eve::exp(invcdf(normal_distribution(m, s), x)); - else - return eve::exp(invcdf(normal_distribution_01, x)); - } - - ////////////////////////////////////////////////////// - /// median - template - EVE_FORCEINLINE auto median_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d) noexcept - { - auto [m, s] = d.params(); - if constexpr(floating_value || floating_value) - return exp(median(normal_distribution(m, s))); - else - { - return I(1.0); - } - } - - - ////////////////////////////////////////////////////// - /// mean - template - EVE_FORCEINLINE auto mean_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const &d) noexcept - { - if constexpr (floating_value) - return median(d)*exp(sqr(d.s)*half(as())); - else - { - auto sqrte = I(1.64872127070012814684865078781416357165377610071014); - return median(d)*sqrte; - } - } - - ////////////////////////////////////////////////////// - /// mode - template - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d) noexcept - { - if constexpr (floating_value) - return median(d)*exp(-sqr(d.s)); - else - { - auto inve = I( 0.367879441171442); - return median(d)*inve; - } - } - - ////////////////////////////////////////////////////// - /// var - template - EVE_FORCEINLINE auto var_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d) noexcept - { - if constexpr (floating_value && floating_value) - { - auto s2 = sqr(d.s); - return eve::expm1(s2)*exp(2*d.m+s2); - } - else if constexpr (floating_value) // s = 1 - { - auto em1 = T(.7182818284590452353602874713526624977572470937); - return em1*eve::exp(2*d.m+1); - } - else if constexpr (floating_value) // m = 0 - { - auto s2 = sqr(d.s); - return eve::expm1(s2)*exp(s2); - } - else - return I(4.6707742704716049918701399892223453154230684768519); - } - - - ////////////////////////////////////////////////////// - /// skewness - template - EVE_FORCEINLINE auto skewness_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d) noexcept - { - if constexpr (floating_value) - { - auto es2 = exp(sqr(d.s)); - return (es2+2)*sqrt(dec(es2)); - } - else - return I(6.1848771386325547948354157320560072900223261742372); - } - - ////////////////////////////////////////////////////// - /// kurtosis - template - EVE_FORCEINLINE auto kurtosis_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d) noexcept - { - if constexpr (floating_value) - { - auto s2 = sqr(d.s); - return exp(4*s2)+2*exp(3*s2)+3*exp(2*s2)-6; - } - else - return I(10.936392176311525241658602893749337636307499427378); - - } - - - ////////////////////////////////////////////////////// - /// entropy - template - EVE_FORCEINLINE auto entropy_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d) noexcept - { - using v_t = typename lognormal_distribution::value_type; - auto sqrt2pi = v_t(2.50662827463100050241576528481104525300698674061); - auto sqrt2pie = v_t(4.1327313541224929384693918842998526494455219169913); - if constexpr (floating_value) - return eve::log2(d.s*exp(d.m+half(as(d.m)))*sqrt2pi); - else if constexpr (floating_value) // s = 1 - return eve::log2(exp(d.m+half(as(d.m)))*sqrt2pi); - else if constexpr (floating_value) // m = 0 - return eve::log2(d.s*sqrt2pie); - else - return eve::log2(sqrt2pie); - } - - ////////////////////////////////////////////////////// - /// stdev - template - EVE_FORCEINLINE auto stdev_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d) noexcept - { - return sqrt(var(d)); - } - - - ////////////////////////////////////////////////////// - /// confidence - template - EVE_FORCEINLINE auto confidence_(EVE_SUPPORTS(cpu_) - , lognormal_distribution const & d - , R const & x - , std::array const & cov - , A const & alpha ) noexcept - { - R xx = if_else(is_gtz(x), eve::log(x), zero); - auto par = d.params(); - auto dn = normal_distribution(par.m, par.s); - return confidence(dn, xx, cov, alpha); - } - } -} diff --git a/include/eve/module/proba/regular/impl/normal_distribution.hpp b/include/eve/module/proba/regular/impl/normal_distribution.hpp deleted file mode 100644 index f70002ccd2..0000000000 --- a/include/eve/module/proba/regular/impl/normal_distribution.hpp +++ /dev/null @@ -1,467 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include - -namespace eve -{ - - namespace detail - { - template < typename G, typename R> EVE_FORCEINLINE - auto box_muller(G & gen, as const & ) noexcept - { - auto x1 = detail::urg01(gen, as()); - auto x2 = detail::urg01(gen, as()); - auto rho = eve::sqrt(-2*eve::log1p(-x1)); - return rho*half_circle(cospi)(2*x2); - } - } - - template < typename T, typename U, typename Internal = T> - struct normal_distribution{}; - - template < floating_ordered_value T, floating_ordered_value U> - requires compatible_values - struct normal_distribution - { - using is_distribution_t = void; - using m_type = T; - using s_type = U; - using value_type = common_compatible_t; - using parameters = struct { value_type m; value_type s; }; - - normal_distribution(T m_, U s_) - : m(m_), s(s_) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - normal_distribution(parameters const & p) - : m(p.m), s(p.s) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return fma(m, detail::box_muller(gen, as()), s); - } - - parameters params() const noexcept - { - return { .m = m, .s = s }; - } - - m_type m; - s_type s; - }; - - template < floating_ordered_value U> - struct normal_distribution - { - using is_distribution_t = void; - using m_type = callable_zero_; - using s_type = U; - using value_type = U; - using parameters = struct { callable_zero_ m; value_type s;}; - - normal_distribution(callable_zero_ const&, U s_) - : s(s_) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - } - - normal_distribution(parameters const & p) - : s(p.s) - { - EVE_ASSERT(all(is_gtz(s) && is_finite(s)), "s must be strictly positive and finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - - return detail::box_muller(gen, as())*s; - } - - parameters params() noexcept - { - return { .m = zero, .s = s }; - } - - s_type s; - }; - - template < floating_ordered_value T> - struct normal_distribution - { - using is_distribution_t = void; - using m_type = T; - using s_type = decltype(eve::one); - using value_type = T; - using parameters = struct { value_type m; callable_one_ s;}; - - normal_distribution(T m_, callable_one_ const &) - : m(m_) - { - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - normal_distribution(parameters const & p) - : m(p.m) - { - EVE_ASSERT(all(is_finite(m)), "m must be finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return detail::box_muller(gen, as())+m; - } - - parameters params() noexcept - { - return { .m = m, .s = one }; - } - - m_type m; - }; - - template normal_distribution(T,U) -> normal_distribution; - - template < floating_ordered_value T> - struct normal_distribution - { - using is_distribution_t = void; - using m_type = callable_zero_; - using s_type = callable_one_; - using value_type = T; - using parameters = struct { callable_zero_ m; callable_one_ s;}; - - - normal_distribution(parameters const & ) { } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return detail::box_muller(gen, as()); - } - - parameters params() noexcept - { - return { .m = zero, .s = one }; - } - - constexpr normal_distribution( as const&) {} - }; - - - template normal_distribution(as const&) -> normal_distribution; - - template - inline constexpr auto normal_distribution_01 = normal_distribution(as{}); - - namespace detail - { - ////////////////////////////////////////////////////// - /// cdf - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - return half(as(x))*erfc(invsqrt_2(as(x))*((d.m-x)/d.s)); - else if constexpr(std::same_as && floating_value) - return half(as(x))*erfc(invsqrt_2(as(x))*(-x/d.s)); - else if constexpr(std::same_as && floating_value) - return half(as(x))*erfc(invsqrt_2(as(x))*((d.m-x))); - else - return half(as(x))*erfc(invsqrt_2(as(x))*(-x)); - } - - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , raw_type const & - , normal_distribution const &d - , V const &x ) noexcept - { - using elt_t = element_type_t; - if constexpr(std::same_as) - { - auto eval = [](auto l) - { - auto al = eve::abs(l); - auto k = rec(fma(T(0.2316419f),al,one(as(l)))); - auto w = horn(k); - auto invsqrt_2pi = T(0.39894228040143267793994605993438186847585863116493); - w*=k*invsqrt_2pi*eve::exp(-sqr(l)*half(as(l))); - return if_else(is_gtz(l),oneminus(w),w); - }; - if constexpr(floating_value && floating_value) - return eval((x-d.m)/d.s); - else if constexpr(std::same_as && floating_value) - return eval(x/d.s); - else if constexpr(std::same_as && floating_value) - return eval(x-d.m); - else - return eval(x); - } - else return cdf(d, x); - } - - ////////////////////////////////////////////////////// - /// pdf - template - EVE_FORCEINLINE auto pdf_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d - , V const &x ) noexcept - { - auto invsqrt_2pi = V(0.39894228040143267793994605993438186847585863116493); - if constexpr(floating_value && floating_value) - { - auto invsig = rec(d.s); - return eve::exp(mhalf(as(x))*sqr((x-d.m)*invsig))*invsqrt_2pi*invsig; - } - else if constexpr(std::same_as && floating_value) - { - auto invsig = rec(d.s); - return eve::exp(mhalf(as(x))*sqr(x*invsig))*invsqrt_2pi*invsig; - } - else if constexpr(std::same_as && floating_value) - { - return eve::exp(mhalf(as(x))*sqr((x-d.m)))*invsqrt_2pi; - } - else - return eve::exp(mhalf(as(x))*sqr(x))*invsqrt_2pi; - } - - ////////////////////////////////////////////////////// - /// mgf - template - EVE_FORCEINLINE auto mgf_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d - , V const &x ) noexcept - { - auto invsqrt_2pi = V(0.39894228040143267793994605993438186847585863116493); - if constexpr(floating_value && floating_value) - { - return eve::exp(d.m*x+sqr(d.s*x)*half(as(x))); - } - else if constexpr(std::same_as && floating_value) - { - return eve::exp(sqr(d.s*x)*half(as(x))); - } - else if constexpr(std::same_as && floating_value) - { - return eve::exp(d.m*x+sqr(x)*half(as(x))); - } - else - return eve::exp(sqr(d)*half(as(x))); - } - - ////////////////////////////////////////////////////// - /// invcdf - template - EVE_FORCEINLINE auto invcdf_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d - , V const &x ) noexcept - { - if constexpr(floating_value && floating_value) - { - return fma(-sqrt_2(as(x))*erfc_inv( T(2)*x), d.s, d.m); - } - else if constexpr(std::same_as && floating_value) - { - return -sqrt_2(as(x))*erfc_inv(2*x)*d.s; - } - else if constexpr(std::same_as && floating_value) - { - return -sqrt_2(as(x))*erfc_inv(2*x)+d.m; - } - else - return -sqrt_2(as(x))*erfc_inv(2*x); - } - - ////////////////////////////////////////////////////// - /// median - template - EVE_FORCEINLINE auto median_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d) noexcept - { - if constexpr (floating_value) - return d.m; - else if constexpr (floating_value) - return zero(as()); - else - return zero(as()); - } - - - ////////////////////////////////////////////////////// - /// mean - template - EVE_FORCEINLINE auto mean_(EVE_SUPPORTS(cpu_) - , normal_distribution const &d) noexcept - { - return median(d); - } - - ////////////////////////////////////////////////////// - /// mode - template - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d) noexcept - { - return median(d); - } - - ////////////////////////////////////////////////////// - /// entropy - template - EVE_FORCEINLINE auto entropy_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d) noexcept - { - auto twopie = T(17.0794684453471341309271017390931489900697770715304); - if constexpr (floating_value) - return half(as())*log(twopie*sqr(d.s)); - else - return half(as())*log(twopie); - } - - - ////////////////////////////////////////////////////// - /// skewness - template - EVE_FORCEINLINE auto skewness_(EVE_SUPPORTS(cpu_) - , normal_distribution const & ) noexcept - { - return I(0); - } - - ////////////////////////////////////////////////////// - /// kurtosis - template - EVE_FORCEINLINE auto kurtosis_(EVE_SUPPORTS(cpu_) - , normal_distribution const & ) noexcept - { - return I(0); - } - - ////////////////////////////////////////////////////// - /// mad - template - EVE_FORCEINLINE auto mad_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d) noexcept - { - auto sqrt_2o_pi = T(0.79788456080286535587989211986876373695171726232986); - if constexpr (floating_value) - return d.s*sqrt_2o_pi; - else - return sqrt_2o_pi; - } - - ////////////////////////////////////////////////////// - /// var - template - EVE_FORCEINLINE auto var_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d) noexcept - { - if constexpr (floating_value) - return sqr(d.s); - else - return one(as()); - } - - ////////////////////////////////////////////////////// - /// stdev - template - EVE_FORCEINLINE auto stdev_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d) noexcept - { - if constexpr (floating_value) - return d.s; - else - return one(as()); - } - - ////////////////////////////////////////////////////// - /// kullback - template - EVE_FORCEINLINE auto kullback_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d1 - , normal_distribution const & d2 ) noexcept - { - if constexpr (floating_value && floating_value) - { - auto srap = d1.s/d2.s; - return half(as())*(dec(sqr(srap)+sqr((d1.m-d2.m)/d2.s))+T(2)*eve::log(srap)); - } - else if constexpr(std::same_as && floating_value) - { - auto srap = d1.s/d2.s; - return half(as())*(dec(sqr(srap))+T(2)*eve::log(srap)); - } - else if constexpr(std::same_as && floating_value) - { - return half(as())*dec(oneminus(sqr((d1.m-d2.m)/d2.s))); - } - else - return zero(as()); - } - - ////////////////////////////////////////////////////// - /// confidence - template - EVE_FORCEINLINE auto confidence_(EVE_SUPPORTS(cpu_) - , normal_distribution const & d - , R const & x - , std::array const & cov - , A const & alpha ) noexcept - { - using v_t = typename normal_distribution::value_type; - R z = x; - auto normz = -invcdf(normal_distribution_01, alpha*v_t(0.5)); - auto halfwidth = normz; - if constexpr(floating_ordered_value && floating_ordered_value) - z = (z-d.m)/d.s; - else if constexpr(floating_ordered_value) - z -= d.m; - else if constexpr(floating_ordered_value) - z /= d.s; - auto zvar = fma(fma(cov[3], z, 2*cov[1]), z, cov[0]); - halfwidth *= eve::sqrt(zvar); - if constexpr(floating_ordered_value) - halfwidth /= d.s; - auto d01 = normal_distribution_01; - return kumi::make_tuple(cdf(d01, z), cdf(d01, z-halfwidth), cdf(d01, z+halfwidth)); - } - } -} diff --git a/include/eve/module/proba/regular/impl/poisson_distribution.hpp b/include/eve/module/proba/regular/impl/poisson_distribution.hpp deleted file mode 100644 index 7c3a3b672f..0000000000 --- a/include/eve/module/proba/regular/impl/poisson_distribution.hpp +++ /dev/null @@ -1,240 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include - -namespace eve -{ - template < typename T, typename Internal = T> - struct poisson_distribution{}; - - template < floating_ordered_value T> - struct poisson_distribution - { - using is_distribution_t = void; - using lambda_type = T; - using value_type = T; - - poisson_distribution(T lambda_) : lambda(lambda_), expmlambda(eve::exp(-lambda)){ - EVE_ASSERT(all(is_gtz(lambda) && is_finite(lambda)), "lambda must be strictly positive and finite"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - if (lambda < value_type(10)) - { - R p(expmlambda); - R x(zero(as())); - auto u = detail::urg01(gen, as()); - auto t = u > p; - while(any(t)) { - u = sub[t](u, p); - x = inc[t](x); - p = if_else(t, lambda*p/x, p); - t = u > p; - } - return x; - } - else - { - R k(R(0)); - auto p=detail::urg01(gen, as()); - auto t = p>expmlambda; - while (any(t)) - { - p = mul[t](p, detail::urg01(gen, as())); - k = inc[t](k); - t = p>expmlambda; - } - return k; - } - } - - - lambda_type lambda; - lambda_type expmlambda; - - - }; - - - template poisson_distribution(T) -> poisson_distribution; - - - template < floating_ordered_value T> - struct poisson_distribution < callable_one_, T> - { - using is_distribution_t = void; - using lambda_type = callable_one_; - using value_type = T; - using elt_t = element_type_t; - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - auto p = R(expm1); - R x(zero(as())); - auto u = detail::urg01(gen, as()); - auto t = u > p; - while(any(t)) { - u = sub[t](u, p); - x = inc[t](x); - p = div[t](p, x); - t = u > p; - } - return x; - } - constexpr poisson_distribution( as const&) {} - static constexpr elt_t expm1 = elt_t(0.36787944117144232159552377016146086744581113103176); - - }; - - template poisson_distribution(as const&) -> poisson_distribution; - - template - inline constexpr auto poisson_distribution_1 = poisson_distribution(as{}); - - namespace detail - { - - ////////////////////////////////////////////////////// - /// cdf - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , poisson_distribution const &d - , U const &x ) noexcept - { - U l = one(as()); - if constexpr(floating_ordered_value) l = U(d.lambda); - auto tmp = gamma_p(floor(x+1), l); - return if_else(is_flint(x) && is_gez(x), tmp, zero); - } - - ////////////////////////////////////////////////////// - /// pmf - template - EVE_FORCEINLINE auto pmf_(EVE_SUPPORTS(cpu_) - , poisson_distribution const &d - , U const &x ) noexcept - { - if constexpr(floating_value) - return if_else(is_flint(x) && is_gez(x) - , d.expmlambda*pow_abs(d.lambda, x)/tgamma(inc(x)) - , zero); - else - return if_else(is_flint(x) && is_gez(x) - , rec(tgamma(inc(x))) - , zero); - } - - ////////////////////////////////////////////////////// - /// mgf - template - EVE_FORCEINLINE auto mgf_(EVE_SUPPORTS(cpu_) - , poisson_distribution const &d - , U const &t ) noexcept - { - if constexpr(floating_value) - return eve::exp(d.lambda*expm1(t)); - else - return eve::exp(expm1(t)); - } - - ////////////////////////////////////////////////////// - /// mean - template - EVE_FORCEINLINE auto mean_(EVE_SUPPORTS(cpu_) - , poisson_distribution const &d) noexcept - { - if constexpr(floating_value) - return d.lambda; - else - return one(as()); - } - - - ////////////////////////////////////////////////////// - /// median - template - EVE_FORCEINLINE auto median_(EVE_SUPPORTS(cpu_) - , poisson_distribution const &d) noexcept - { - if constexpr(floating_value) - return floor(d.lambda + T(1/3.0) - T(0.02/d.lambda)); //approximate (exact for integral lambda) - else - return one(as()); - } - - ////////////////////////////////////////////////////// - /// mode - template - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_) - , poisson_distribution const & d) noexcept - { - if constexpr(floating_value) - return if_else(is_flint(d.lambda), dec(d.lambda), floor(d.lambda)); - else - return zero(as()); - } - - ////////////////////////////////////////////////////// - /// var - template - EVE_FORCEINLINE auto var_(EVE_SUPPORTS(cpu_) - , poisson_distribution const &d) noexcept - { - if constexpr(floating_value) - return d.lambda; - else - return one(as()); - } - - - ////////////////////////////////////////////////////// - /// stdev - template - EVE_FORCEINLINE auto stdev_(EVE_SUPPORTS(cpu_) - , poisson_distribution const &d) noexcept - { - if constexpr(floating_value) - return eve::sqrt(d.lambda); - else - return one(as()); - } - - ////////////////////////////////////////////////////// - /// skewness - template - EVE_FORCEINLINE auto skewness_(EVE_SUPPORTS(cpu_) - , poisson_distribution const & d) noexcept - { - if constexpr(floating_value) - return rsqrt(d.lambda); - else - return one(as()); - } - - ////////////////////////////////////////////////////// - /// kurtosis - template - EVE_FORCEINLINE auto kurtosis_(EVE_SUPPORTS(cpu_) - , poisson_distribution const & d) noexcept - { - if constexpr(floating_value) - return rec(d.lambda); - else - return one(as()); - } - } -} diff --git a/include/eve/module/proba/regular/impl/uniform_continuous_distribution.hpp b/include/eve/module/proba/regular/impl/uniform_continuous_distribution.hpp deleted file mode 100644 index 10742484e0..0000000000 --- a/include/eve/module/proba/regular/impl/uniform_continuous_distribution.hpp +++ /dev/null @@ -1,299 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include - -namespace eve -{ - - template < typename T, typename U - , typename V = common_compatible_floating_elt_t > - struct uniform_continuous_distribution - { - using is_distribution_t = void; - using continuous_t = void; - using a_type = T; - using b_type = U; - using elt_t = V; - using i_t = common_compatible_t; - using value_type = std::conditional_t< scalar_value, V, wide>>; - - uniform_continuous_distribution(T a_, U b_) - : a(convert(a_, as())), b(convert(b_, as())) - { - check_constraints(); - } - - uniform_continuous_distribution(T a_, U b_, V) - : a(convert(a_, as())), b(convert(b_, as())) - { - check_constraints(); - } - - uniform_continuous_distribution(T a_, U b_, as) - : a(convert(a_, as())), b(convert(b_, as())) - { - check_constraints(); - } - - void check_constraints() - { - EVE_ASSERT(all(is_finite(a)), "a must be finite"); - EVE_ASSERT(all(is_finite(b)), "b must be finite"); - EVE_ASSERT(all(a < b) , "a must be stricty less than b"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return fma(detail::urg01(gen, as()), b-a, a); - } - - value_type a; - value_type b; - }; - - template uniform_continuous_distribution(T,U) -> uniform_continuous_distribution; - template uniform_continuous_distribution(T,U,V) -> uniform_continuous_distribution; - template uniform_continuous_distribution(T,U,as) -> uniform_continuous_distribution; - - template < floating_ordered_value T> - struct uniform_continuous_distribution - { - using is_distribution_t = void; - using continuous_t = void; - using a_type = callable_zero_; - using b_type = callable_one_; - using value_type = T; - using elt_t = element_type_t; - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return detail::urg01(gen, as()); - } - - constexpr uniform_continuous_distribution() { } - constexpr uniform_continuous_distribution( as const&) { } - }; - - - template uniform_continuous_distribution(as const&) -> uniform_continuous_distribution; - - template - inline constexpr auto uniform_continuous_distribution_01 = uniform_continuous_distribution(); - - namespace detail - { - ////////////////////////////////////////////////////// - /// cdf continuous - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & d - , V const &x ) noexcept - requires compatible_values::value_type> - && continuous> - { - if constexpr(floating_value && floating_value) - return if_else(x < d.a, zero, if_else(x > d.b, one(as(x)), (x-d.a)/(d.b-d.a))); - else if constexpr(floating_value) - return if_else(x < d.a, zero, if_else(x > one(as(x)), one(as(x)), (x-d.a)/oneminus(d.a))); - else if constexpr(floating_value) - return if_else(is_ltz(x), zero, if_else(x > d.b, one(as(x)), x/d.b)); - else - return if_else(is_ltz(x), zero, if_else(x > one(as(x)), one(as(x)), x));; - } - - ////////////////////////////////////////////////////// - /// pdf continuous - template - EVE_FORCEINLINE auto pdf_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & d - , V const &x ) noexcept - requires compatible_values::value_type> - && continuous> - { - if constexpr(floating_value && floating_value) - return if_else((x < d.a) || (x > d.b), zero, rec(d.b-d.a)); - else if constexpr(floating_value) - return if_else(x < d.a || x > one(as(x)), one(as(x)), rec(oneminus(d.a))); - else if constexpr(floating_value) - return if_else(is_ltz(x) || x > d.b, one(as(x)), rec(d.b)); - else - return if_else(is_ltz(x), zero, if_else(x > one(as(x)), one, x));; - } - - ////////////////////////////////////////////////////// - /// mgf continuous - template - EVE_FORCEINLINE auto mgf_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & d - , V const &x ) noexcept - requires compatible_values::value_type> - && continuous> { - if constexpr(floating_value && floating_value) - return if_else(is_eqz(x), one(as(x)), (eve::exp(x*d.b)-eve::exp(x*d.a))/(x*(d.b-d.a))); - else if constexpr(floating_value) - return if_else(is_eqz(x), one(as(x)), (eve::exp(x)-eve::exp(x*d.a))/(x*oneminus(d.a))); - else if constexpr(floating_value) - return if_else(is_eqz(x), one(as(x)), eve::expm1(x*d.b)/(x*d.b)); - else - return if_else(is_eqz(x), one(as(x)), eve::expm1(x)/x); - } - - ////////////////////////////////////////////////////// - /// invcdf continuous - template - EVE_FORCEINLINE auto invcdf_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & d - , V const &x ) noexcept - requires compatible_values::value_type> - && continuous> { - EVE_ASSERT(all(is_gez(x) && x < one(as(x))), " x must be in [0, 1]"); - if constexpr(floating_value && floating_value) - return lerp(x, d.a, d.b); - else if constexpr(floating_value) - return lerp(x, d.a, one(as(d.a))); - else if constexpr(floating_value) - return lerp(x, zero(as(d.b)), d.b); - else - return x; - } - - ////////////////////////////////////////////////////// - /// mean continuous - template - EVE_FORCEINLINE auto mean_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & d) noexcept - { - if constexpr (value && value) - return average(d.a, d.b); - else if constexpr(floating_value) - return average(d.a, one(as(d.a))); - else if constexpr(floating_value) - return d.b*half(as(d.b)); - else - { - using v_t = typename uniform_continuous_distribution::value_type; - return half(as()); - } - } - - ////////////////////////////////////////////////////// - /// median continuous - template - EVE_FORCEINLINE auto median_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const &d) noexcept - requires continuous> - { - if constexpr (floating_value) - return d.a; - else - { - using v_t = typename uniform_continuous_distribution::value_type; - return zero(as()); - } - } - - ////////////////////////////////////////////////////// - /// mode continuous - template - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & d) noexcept - { - return median(d); - } - - ////////////////////////////////////////////////////// - /// entropy continuous - template - EVE_FORCEINLINE auto entropy_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & d) noexcept - requires continuous> - { - if constexpr (floating_value && floating_value) - return eve::log(d.b-d.a); - else if constexpr(floating_value) - return eve::log1p(-d.a); - else if constexpr(floating_value) - return log(d.b); - else - { - using v_t = typename uniform_continuous_distribution::value_type; - return zero(as()); - } - } - - ////////////////////////////////////////////////////// - /// skewness continuous - template - EVE_FORCEINLINE auto skewness_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & ) noexcept - { - using v_t = typename uniform_continuous_distribution::value_type; - return zero(as()); - } - - ////////////////////////////////////////////////////// - /// kurtosis continuous - template - EVE_FORCEINLINE auto kurtosis_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & ) noexcept - requires continuous> - { - using v_t = typename uniform_continuous_distribution::value_type; - return v_t(-1.2); - } - - ////////////////////////////////////////////////////// - /// var continuous - template - EVE_FORCEINLINE auto var_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & d) noexcept - requires continuous> - { - using v_t = typename uniform_continuous_distribution::value_type; - auto oneo12 = v_t(8.333333333333333e-02); - if constexpr (floating_value && floating_value) - return sqr(d.b-d.a)*oneo12; - else if constexpr(floating_value) - return sqr(oneminus(d.a))*oneo12; - else if constexpr(floating_value) - return sqr(d.b)*oneo12; - else - return oneo12; - } - - ////////////////////////////////////////////////////// - /// stdev continuous - template - EVE_FORCEINLINE auto stdev_(EVE_SUPPORTS(cpu_) - , uniform_continuous_distribution const & d) noexcept - requires continuous> - { - using v_t = typename uniform_continuous_distribution::value_type; - auto s1 = v_t(2.886751345948129e-01); - if constexpr (floating_value && floating_value) - return s1*(d.b-d.a); - else if constexpr(floating_value) - return s1*oneminus(d.a); - else if constexpr(floating_value) - return s1*d.b; - else - return s1; - } - } -} diff --git a/include/eve/module/proba/regular/impl/uniform_discrete_distribution.hpp b/include/eve/module/proba/regular/impl/uniform_discrete_distribution.hpp deleted file mode 100644 index d69c23cfc1..0000000000 --- a/include/eve/module/proba/regular/impl/uniform_discrete_distribution.hpp +++ /dev/null @@ -1,280 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace eve -{ - template < typename T, typename U - , typename V = common_compatible_floating_elt_t> - struct uniform_discrete_distribution{}; - - template < typename T, typename U, typename V > - requires compatible_values - struct uniform_discrete_distribution - { - using is_distribution_t = void; - using discrete_t = void; - using a_type = T; - using b_type = U; - using elt_t = V; - using i_t = common_compatible_t; - using value_type = std::conditional_t< scalar_value, V, wide>>; - - uniform_discrete_distribution(T a_, U b_) - : a(convert(a_, as())), b(convert(b_, as())), n(inc(b-a)) - { - check_constraints(); - } - - uniform_discrete_distribution(T a_, U b_, V) - : a(convert(a_, as())), b(convert(b_, as())), n(inc(b-a)) - { - check_constraints(); - } - - uniform_discrete_distribution(T a_, U b_, as) - : a(convert(a_, as())), b(convert(b_, as())), n(inc(b-a)) - { - check_constraints(); - } - - void check_constraints() - { - EVE_ASSERT(all(is_flint(a)), "a must be flint"); - EVE_ASSERT(all(is_flint(b)), "b must be flint"); - EVE_ASSERT(all(a < b) , "a must be stricty less than b"); - } - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return floor(fma(detail::urg01(gen, as()), n, a)); - } - - value_type a; - value_type b; - value_type n; - }; - - - template < floating_ordered_value T> - struct uniform_discrete_distribution// : uniform_discrete_distribution_base < T, T, T> - { - using is_distribution_t = void; - using discrete_t = void; - using a_type = callable_zero_; - using b_type = callable_one_; - using value_type = T; - using elt_t = element_type_t; - - template < typename G, typename R = value_type> auto operator()(G & gen, as const & ) - requires scalar_value - { - return floor(2*detail::urg01(gen, as())); - } - - constexpr uniform_discrete_distribution() { } - constexpr uniform_discrete_distribution( as const&) { } - - }; - - template uniform_discrete_distribution(T,U) -> uniform_discrete_distribution; - template uniform_discrete_distribution(T,U,V) -> uniform_discrete_distribution; - template uniform_discrete_distribution(T,U,as) -> uniform_discrete_distribution; - - template uniform_discrete_distribution(T,U) -> uniform_discrete_distribution; - template uniform_discrete_distribution(T,U,V) -> uniform_discrete_distribution; - template uniform_discrete_distribution(T,U,as) -> uniform_discrete_distribution; - - template uniform_discrete_distribution(T const&) -> uniform_discrete_distribution; - template uniform_discrete_distribution(as const&) -> uniform_discrete_distribution>; - - template - inline constexpr auto uniform_discrete_distribution_01 = uniform_discrete_distribution(); - - namespace detail - { - ////////////////////////////////////////////////////// - // only 3 branches because if U is not a value type b - // must be callable_one and so a zero - ////////////////////////////////////////////////////// - /// cdf discrete - template - EVE_FORCEINLINE auto cdf_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const & d - , V const &x ) noexcept - requires compatible_values::value_type> - { - if constexpr(value && value) - return inc(floor(x)-d.a)/d.n; - else if constexpr(floating_value) - return inc(floor(x))/inc(d.b); - else - return inc(floor(x))*half(as(x)); - } - - ////////////////////////////////////////////////////// - /// pmf discrete - template - EVE_FORCEINLINE auto pmf_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const & d - , V const &x ) noexcept - requires compatible_values::value_type> - { - if constexpr(value && value) - return if_else((x < d.a) || (x > d.b) || is_not_flint(x), zero, rec(d.n)); - else if constexpr(floating_value) - return if_else(is_ltz(x) || (x > d.b) || is_not_flint(x), zero, rec(inc(d.b))); - else - return if_else(is_ltz(x) || (x > one(as(x))) || is_not_flint(x), zero, half(as(x)));; - } - - ////////////////////////////////////////////////////// - /// mgf discrete - template - EVE_FORCEINLINE auto mgf_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const & d - , V const &x ) noexcept - requires compatible_values::value_type> - { - if constexpr(value && value) - return if_else(is_eqz(x), one(as(x)), (eve::exp(x*inc(d.b))-eve::exp(x*d.a))/(d.n*expm1(x))); - else if constexpr(floating_value) - return if_else(is_eqz(x), one(as(x)), eve::expm1(x*inc(d.b))/inc(d.b)*expm1(x)); - else - return inc(exp(x))*half(as(x)); - } - - ////////////////////////////////////////////////////// - /// mean discrete - template - EVE_FORCEINLINE auto mean_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const & d) noexcept - { - if constexpr (value && value) - return average(d.a, d.b); - else if constexpr(floating_value) - return average(one(as(d.b)), d.b); - else - { - using v_t = typename uniform_discrete_distribution::value_type; - return half(as()); - } - } - - ////////////////////////////////////////////////////// - /// median discrete - template - EVE_FORCEINLINE auto median_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const &d) noexcept - { - if constexpr (value && value) - return floor(average(d.a, d.b)); - else if constexpr(floating_value) - return floor(average(one(as(d.b)), d.b)); - else - { - using v_t = typename uniform_discrete_distribution::value_type; - return zero(as()); - } - } - - ////////////////////////////////////////////////////// - /// mode discrete - template - EVE_FORCEINLINE auto mode_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const & d) noexcept - { - if constexpr (value) - return d.a; - else - { - using v_t = typename uniform_discrete_distribution::value_type; - return zero(as()); - } - } - - ////////////////////////////////////////////////////// - /// entropy discrete - template - EVE_FORCEINLINE auto entropy_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const & d) noexcept - { - if constexpr (floating_value && floating_value) - return eve::log(d.n); - else if constexpr (floating_value) - return eve::log(inc(d.b)); - else - { - using v_t = typename uniform_discrete_distribution::value_type; - return log_2(as()); - } - } - - ////////////////////////////////////////////////////// - /// skewness discrete - template - EVE_FORCEINLINE auto skewness_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const & ) noexcept - { - using v_t = typename uniform_discrete_distribution::value_type; - return zero(as()); - } - - ////////////////////////////////////////////////////// - /// kurtosis discrete - template - EVE_FORCEINLINE auto kurtosis_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const & d) noexcept - { - using v_t = typename uniform_discrete_distribution::value_type; - return v_t(-1.2)*inc(sqr(d.n))/dec(sqr(d.n)); - } - - ////////////////////////////////////////////////////// - /// var discrete - template - EVE_FORCEINLINE auto var_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const & d) noexcept - { - using v_t = typename uniform_discrete_distribution::value_type; - auto oneo12 = v_t(8.333333333333333e-02); - if constexpr (value && value) - return dec(sqr(d.n))*oneo12; - else if constexpr (floating_value) - return dec(sqr(inc(d.b)))*oneo12; - else - return I(0.25); - } - - ////////////////////////////////////////////////////// - /// stdev discrete - template - EVE_FORCEINLINE auto stdev_(EVE_SUPPORTS(cpu_) - , uniform_discrete_distribution const & d) noexcept - { - using v_t = typename uniform_discrete_distribution::value_type; - auto s1 = v_t(2.886751345948129e-01); - if constexpr (value && value) - return s1*sqrt(dec(sqr(d.n))); - else if constexpr (floating_value) - return s1*sqrt(dec(sqr(inc(d.b)))); - else - return I(0.5); - } - } -} diff --git a/include/eve/module/proba/regular/lognormal_distribution.hpp b/include/eve/module/proba/regular/lognormal_distribution.hpp deleted file mode 100644 index b4656a703e..0000000000 --- a/include/eve/module/proba/regular/lognormal_distribution.hpp +++ /dev/null @@ -1,10 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include diff --git a/include/eve/module/proba/regular/normal_distribution.hpp b/include/eve/module/proba/regular/normal_distribution.hpp deleted file mode 100644 index de1a8180c2..0000000000 --- a/include/eve/module/proba/regular/normal_distribution.hpp +++ /dev/null @@ -1,10 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include diff --git a/include/eve/module/proba/regular/poisson_distribution.hpp b/include/eve/module/proba/regular/poisson_distribution.hpp deleted file mode 100644 index fa59795576..0000000000 --- a/include/eve/module/proba/regular/poisson_distribution.hpp +++ /dev/null @@ -1,10 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include diff --git a/include/eve/module/proba/regular/proba.hpp b/include/eve/module/proba/regular/proba.hpp deleted file mode 100644 index 387dd434af..0000000000 --- a/include/eve/module/proba/regular/proba.hpp +++ /dev/null @@ -1,19 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/include/eve/module/proba/regular/uniform_continuous_distribution.hpp b/include/eve/module/proba/regular/uniform_continuous_distribution.hpp deleted file mode 100644 index 75e9fbce8d..0000000000 --- a/include/eve/module/proba/regular/uniform_continuous_distribution.hpp +++ /dev/null @@ -1,10 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include diff --git a/include/eve/module/proba/regular/uniform_discrete_distribution.hpp b/include/eve/module/proba/regular/uniform_discrete_distribution.hpp deleted file mode 100644 index ab2b7c6c5f..0000000000 --- a/include/eve/module/proba/regular/uniform_discrete_distribution.hpp +++ /dev/null @@ -1,10 +0,0 @@ -//================================================================================================== -/* - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include diff --git a/test/doc/CMakeLists.txt b/test/doc/CMakeLists.txt index c99554140e..7a102e68e8 100644 --- a/test/doc/CMakeLists.txt +++ b/test/doc/CMakeLists.txt @@ -11,8 +11,6 @@ add_subdirectory(complex) add_subdirectory(elliptic) add_subdirectory(math) add_subdirectory(polynomial) -add_subdirectory(proba) add_subdirectory(special) - add_subdirectory(core) add_subdirectory(traits) diff --git a/test/doc/proba/CMakeLists.txt b/test/doc/proba/CMakeLists.txt deleted file mode 100644 index 78cb7e6e0d..0000000000 --- a/test/doc/proba/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -##================================================================================================== -## EVE - Expressive Vector Engine -## Copyright : EVE Project Contributors -## SPDX-License-Identifier: BSL-1.0 -##================================================================================================== - -make_unit( "doc.proba" binomial_distribution.cpp ) -make_unit( "doc.proba" cauchy_distribution.cpp ) -make_unit( "doc.proba" ev_distribution.cpp ) -make_unit( "doc.proba" exponential_distribution.cpp ) -make_unit( "doc.proba" gamma_distribution.cpp ) -make_unit( "doc.proba" lognormal_distribution.cpp ) -make_unit( "doc.proba" normal_distribution.cpp ) -make_unit( "doc.proba" poisson_distribution.cpp ) -make_unit( "doc.proba" uniform_continuous_distribution.cpp ) -make_unit( "doc.proba" uniform_discrete_distribution.cpp ) diff --git a/test/doc/proba/binomial_distribution.cpp b/test/doc/proba/binomial_distribution.cpp deleted file mode 100644 index 3106ad9a06..0000000000 --- a/test/doc/proba/binomial_distribution.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include - -using wide_ft = eve::wide >; - -int main() -{ - wide_ft x = { 0.0f, 1.0f, 3.0f, 5.0f }; - wide_ft n = { 2.0f, 3.0f, 6.0, 20.0f }; - wide_ft p = { 0.1f, 0.5f, 0.75, 0.9f }; - - auto bi = eve::binomial_distribution(n, p); - - std::cout - << "---- simd" << '\n' - << "<- x = " << x << '\n' - << "<- n = " << n << '\n' - << "<- p = " << p << '\n' - << "-> median(bi) = " << eve::median(bi) << '\n' - << "-> mode(bi) = " << eve::mode(bi) << '\n' - << "-> mean(bi) = " << eve::mean(bi) << '\n' - << "-> var(bi) = " << eve::var(bi) << '\n' - << "-> entropy(bi) = " << eve::entropy(bi) << '\n' - << "-> pmf(bi, x) = " << eve::pmf(bi, x) << '\n' - << "-> cdf(bi, x) = " << eve::cdf(bi, x) << '\n' - << "-> mgf(bi, x) = " << eve::mgf(bi, x) << '\n'; - - float xf = 9.0f; - float mf = 10.0f; - float sf = 0.5; - auto bif = eve::binomial_distribution(mf, sf); - - std::cout - << "---- scalar" << '\n' - << "<- xf = " << xf << '\n' - << "<- mf = " << mf << '\n' - << "<- sf = " << sf << '\n' - << "-> cdf(bif, xf) = " << eve::cdf(bif, xf) << '\n' - << "-> mode(bif) = " << eve::mode(bif) << '\n'; - - - - auto d1 = eve::binomial_distribution(10.0f, eve::half); - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d1(gen, eve::as()) "<< d1(gen, eve::as()) << std::endl - << "-> d1(gen) "<< d1(gen, eve::as()) << std::endl; - - auto d2 = eve::binomial_distribution(30.0f, eve::half); - std::cout - << "generator \n" - << "-> d2(gen, eve::as()) "<< d2(gen, eve::as()) << std::endl - << "-> d2(gen) "<< d2(gen, eve::as()) << std::endl; - - auto d3 = eve::binomial_distribution(30.0f, 0.3f); - std::cout - << "generator \n" - << "-> d3(gen, eve::as()) "<< d3(gen, eve::as()) << std::endl - << "-> d3(gen) "<< d3(gen, eve::as()) << std::endl; - - auto d4 = eve::binomial_distribution(eve::one, 0.3f); - std::cout - << "generator \n" - << "-> d4(gen, eve::as()) "<< d4(gen, eve::as()) << std::endl - << "-> d4(gen) "<< d4(gen, eve::as()) << std::endl; - - - return 0; -} diff --git a/test/doc/proba/cauchy_distribution.cpp b/test/doc/proba/cauchy_distribution.cpp deleted file mode 100644 index 3e1503098b..0000000000 --- a/test/doc/proba/cauchy_distribution.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include -#include - -using wide_ft = eve::wide >; - -int main() -{ - wide_ft x = { 0.0f, 1.0f, -1.0f, 5.0f }; - wide_ft p = { 0.0f, 0.5f, 0.75f, 1.0f }; - wide_ft m = { 0.0f, -1.0f, 1.0f, 2.0f }; - wide_ft s = { 1.0f, 2.0f, 3.0f, 4.0f }; - - auto ca = eve::cauchy_distribution(0.0f, s); - - std::cout - << "---- simd" << '\n' - << "<- x = " << x << '\n' - << "<- m = " << m << '\n' - << "<- s = " << s << '\n' - << "<- p = " << p << '\n' - << "-> median(ca) = " << eve::median(ca) << '\n' - << "-> mode(ca) = " << eve::mode(ca) << '\n' - << "-> fisher(ca) = " << eve::fisher(ca) << '\n' - << "-> pdf(ca, x) = " << eve::pdf(ca, x) << '\n' - << "-> invcdf(ca, p) = " << eve::invcdf(ca, p) << '\n' - << "-> cdf(ca, x) = " << eve::cdf(ca, x) << '\n'; - - float xf = 9.0f; - float mf = 10.0f; - float sf = 2.0; - auto caf = eve::cauchy_distribution(mf, sf); - - std::cout - << "---- scalar" << '\n' - << "<- xf = " << xf << '\n' - << "<- mf = " << mf << '\n' - << "<- sf = " << sf << '\n' - << "-> cdf(caf, xf) = " << eve::cdf(caf, xf) << '\n' - << "-> mode(caf) = " << eve::mode(caf) << '\n'; - - auto ca0= eve::cauchy_distribution{eve::zero, s}; - - std::cout - << "---- simd" << '\n' - << "<- x = " << x << '\n' - << "<- m = " << m << '\n' - << "<- s = " << s << '\n' - << "<- p = " << p << '\n' - << "-> median(ca0) = " << eve::median(ca0) << '\n' - << "-> mode(ca0) = " << eve::mode(ca0) << '\n' - << "-> fisher(ca0) = " << eve::fisher(ca0) << '\n' - << "-> pdf(ca0, x) = " << eve::pdf(ca0, x) << '\n' - << "-> invcdf(ca0, p) = " << eve::invcdf(ca0, p) << '\n' - << "-> cdf(ca0, x) = " << eve::cdf(ca0, x) << '\n'; - - - auto d1 = eve::cauchy_distribution(1.0f, 5.0f); - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d1(gen, eve::as()) "<< d1(gen, eve::as()) << std::endl - << "-> d1(gen) "<< d1(gen, eve::as()) << std::endl; - - return 0; -} diff --git a/test/doc/proba/essai_distrib.cpp b/test/doc/proba/essai_distrib.cpp deleted file mode 100644 index a239f6458c..0000000000 --- a/test/doc/proba/essai_distrib.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -#include -#include - -int main() -#include -{ - using eve::as; - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - eve::tests_real_distribution d(eve::valmin(as()), eve::valmax(as())); - std::vector v; - double minipos = eve::inf(as ()); - double maxipos = 0; - double maxineg = eve::minf(as ()); - double minineg = 0; - for(std::size_t i = 0; i < 10000; ++i) - { - auto val = d(gen); - if (val > 0) - { - if (val > maxipos) maxipos = val; - if (val < minipos) minipos = val; - } - else - { - if (val > maxineg) maxineg = val; - if (val < minineg) minineg = val; - } - - v.push_back(val); -// std::cout << std::setprecision(7) << val << std::endl; - } - std::cout << "minipos " << minipos << std::endl; - std::cout << "maxipos " << maxipos << std::endl; - std::cout << "minineg " << minineg << std::endl; - std::cout << "maxineg " << maxineg << std::endl; -} diff --git a/test/doc/proba/essai_distrib_int.cpp b/test/doc/proba/essai_distrib_int.cpp deleted file mode 100644 index d9d7ad2d90..0000000000 --- a/test/doc/proba/essai_distrib_int.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -#include -#include -#include - -int main() -#include -{ - using i_t = std::int64_t; - using eve::as; - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - eve::tests_integral_distribution d(eve::valmin(as()), -1); //eve::valmax(as())); - std::vector v; - i_t minipos = eve::valmax(as ()); - i_t maxipos = 0; - i_t maxineg = eve::valmin(as ()); - i_t minineg = 0; - for(std::size_t i = 0; i < 10000; ++i) - { - auto val = d(gen); - if (val > 0) - { - if (val > maxipos) maxipos = val; - if (val < minipos) minipos = val; - } - else - { - if (val > maxineg) maxineg = val; - if (val < minineg) minineg = val; - } - v.push_back(val); - } - std::cout << "minipos " << +minipos << std::endl; - std::cout << "maxipos " << +maxipos << std::endl; - std::cout << "minineg " << +minineg << std::endl; - std::cout << "maxineg " << +maxineg << std::endl; -} diff --git a/test/doc/proba/ev_distribution.cpp b/test/doc/proba/ev_distribution.cpp deleted file mode 100644 index 6a117d20c5..0000000000 --- a/test/doc/proba/ev_distribution.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include -#include - -using wide_ft = eve::wide >; - -int main() -{ - wide_ft x = { 0.0f, 1.0f, -1.0f, 5.0f }; - wide_ft p = { 0.0f, 0.5f, 0.75f, 1.0f }; - wide_ft m = { 0.0f, -1.0f, 1.0f, 2.0f }; - wide_ft s = { 1.0f, 2.0f, 3.0f, 4.0f }; - - auto d = eve::ev_distribution(m, s); - - std::cout - << "---- simd" << '\n' - << "<- x = " << x << '\n' - << "<- m = " << m << '\n' - << "<- s = " << s << '\n' - << "<- p = " << p << '\n' - << "-> median(d) = " << eve::median(d) << '\n' - << "-> mode(d) = " << eve::mode(d) << '\n' - << "-> mean(d) = " << eve::mean(d) << '\n' - << "-> var(d) = " << eve::var(d) << '\n' - << "-> entropy(d) = " << eve::entropy(d) << '\n' - << "-> pdf(d, x) = " << eve::pdf(d, x) << '\n' - << "-> invcdf(d, p) = " << eve::invcdf(d, p) << '\n' - << "-> cdf(d, x) = " << eve::cdf(d, x) << '\n'; - - float xf = 9.0f; - float mf = 10.0f; - float sf = 2.0; - auto df = eve::ev_distribution(mf, sf); - - std::cout - << "---- scalar" << '\n' - << "<- xf = " << xf << '\n' - << "<- mf = " << mf << '\n' - << "<- sf = " << sf << '\n' - << "-> cdf(df, xf) = " << eve::cdf(df, xf) << '\n' - << "-> mode(df) = " << eve::mode(df) << '\n'; - - - auto d1 = eve::ev_distribution(1.0f, 5.0f); - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d1(gen, eve::as()) "<< d1(gen, eve::as()) << std::endl - << "-> d1(gen) "<< d1(gen, eve::as()) << std::endl; - - { - auto d2 = eve::ev_distribution_01; - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d2(gen, eve::as()) "<< d2(gen, eve::as()) << std::endl - << "-> d2(gen) "<< d2(gen, eve::as()) << std::endl; - } - - { - auto d3 = eve::ev_distribution(1.0, 1.0); - std::array cov = {1.0, 0.0, 0.0, 1.0}; - auto [r, plo, phi] = eve::confidence(d3 - , 0.0 - , cov - , 0.05); - std::cout - << "confidence \n" - << "r " << r << std::endl - << "plo " << plo<< std::endl - << "phi " << phi<< std::endl; - } -} diff --git a/test/doc/proba/exponential_distribution.cpp b/test/doc/proba/exponential_distribution.cpp deleted file mode 100644 index 73052a31d8..0000000000 --- a/test/doc/proba/exponential_distribution.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -#include - -using wide_ft = eve::wide >; - -int main() -{ - wide_ft x = { 0.0f, 1.0f, -1.0f, 5.0f }; - wide_ft p = { 0.0f, 0.5f, 0.75f, 1.0f }; - wide_ft lambda = { 1.0f, 2.0f, 3.0f, 4.0f }; - - auto ex = eve::exponential_distribution(lambda); - - std::cout - << "---- simd" << '\n' - << "<- x = " << x << '\n' - << "<- lambda = " << lambda << '\n' - << "<- p = " << p << '\n' - << "-> median(ex) = " << eve::median(ex) << '\n' - << "-> mean(ex) = " << eve::mean(ex) << '\n' - << "-> mode(ex) = " << eve::mode(ex) << '\n' - << "-> stdev(ex) = " << eve::stdev(ex) << '\n' - << "-> var(ex) = " << eve::var(ex) << '\n' - << "-> fisher(ex) = " << eve::fisher(ex) << '\n' - << "-> skewness(ex) = " << eve::skewness(ex) << '\n' - << "-> kurtosis(ex) = " << eve::kurtosis(ex) << '\n' - << "-> pdf(ex, x) = " << eve::pdf(ex, x) << '\n' - << "-> invcdf(ex, p) = " << eve::invcdf(ex, p) << '\n' - << "-> cdf(ex, x) = " << eve::cdf(ex, x) << '\n' - << "-> mgf(ex, x) = " << eve::mgf(ex, x) << '\n'; - - float xf = 9.0f; - float lf = 10.0f; - auto exf = eve::exponential_distribution(lf); - - std::cout - << "---- scalar" << '\n' - << "<- xf = " << xf << '\n' - << "<- lf = " << lf << '\n' - << "-> cdf(exf, xf) = " << eve::cdf(exf, xf) << '\n' - << "-> mode(exf) = " << eve::mode(exf) << '\n'; - - auto d1 = eve::exponential_distribution(2.0f); - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d1(gen, eve::as()) "<< d1(gen, eve::as()) << std::endl - << "-> d1(gen) "<< d1(gen, eve::as()) << std::endl; - - { - auto d3 = eve::exponential_distribution(1.0); - auto [r, plo, phi] = eve::confidence(d3 - , 5.0 - , 0.5 - , 0.05); - std::cout - << "confidence \n" - << "r " << r << std::endl - << "plo " << plo<< std::endl - << "phi " << phi<< std::endl; - } - return 0; -} diff --git a/test/doc/proba/gamma_distribution.cpp b/test/doc/proba/gamma_distribution.cpp deleted file mode 100644 index 47eb41bfdb..0000000000 --- a/test/doc/proba/gamma_distribution.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include - -using wide_ft = eve::wide >; - -int main() -{ - wide_ft x = { 0.0f, 1.0f, -1.0f, 5.0f }; - wide_ft p = { 0.0f, 0.5f, 0.75f, 1.0f }; - wide_ft theta = { 0.5f, 2.0f, 0.3f, 4.0f }; - wide_ft k = { 1.0f, 2.0f, 3.0f, 0.5f }; - - auto ga = eve::gamma_distribution(k, theta); - - std::cout - << "---- simd" << '\n' - << "<- x = " << x << '\n' - << "<- theta = " << theta << '\n' - << "<- k = " << k << '\n' - << "<- p = " << p << '\n' - << "-> mode(ga) = " << eve::mode(ga) << '\n' - << "-> mean(ga) = " << eve::mean(ga) << '\n' - << "-> var(ga) = " << eve::var(ga) << '\n' - << "-> entropy(ga) = " << eve::entropy(ga) << '\n' - << "-> pdf(ga, x) = " << eve::pdf(ga, x) << '\n' - << "-> invcdf(ga, p) = " << eve::invcdf(ga, p) << '\n' - << "-> cdf(ga, x) = " << eve::cdf(ga, x) << '\n'; - - float xf = 9.0f; - float thetaf = 10.0f; - float kf = 2.0; - auto gaf = eve::gamma_distribution(kf, thetaf); - - std::cout - << "---- scalar" << '\n' - << "<- xf = " << xf << '\n' - << "<- thetaf = " << thetaf << '\n' - << "<- kf = " << kf << '\n' - << "-> cdf(gaf, xf) = " << eve::cdf(gaf, xf) << '\n' - << "-> mode(gaf) = " << eve::mode(gaf) << '\n'; - - - auto d1 = eve::gamma_distribution(2.0f, 5.0f); - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d1(gen, eve::as()) "<< d1(gen, eve::as()) << std::endl - << "-> d1(gen) "<< d1(gen, eve::as()) << std::endl; - - { - auto d2 = eve::gamma_distribution_11; - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d2(gen, eve::as()) "<< d2(gen, eve::as()) << std::endl - << "-> d2(gen) "<< d2(gen, eve::as()) << std::endl; - } - - { - auto d3 = eve::gamma_distribution(2.0, 4.0); - std::array cov = {0.5, 0.0, 0.0, 0.5}; - auto [r, plo, phi] = eve::confidence(d3 - , 0.2 - , cov - , 0.05); - std::cout - << "confidence \n" - << "r " << r << std::endl - << "plo " << plo<< std::endl - << "phi " << phi<< std::endl; - } - - - - return 0; -} diff --git a/test/doc/proba/lognormal_distribution.cpp b/test/doc/proba/lognormal_distribution.cpp deleted file mode 100644 index bfa8950353..0000000000 --- a/test/doc/proba/lognormal_distribution.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include -#include -#include - -using wide_ft = eve::wide >; - -int main() -{ - wide_ft x = { 0.0f, 1.0f, -1.0f, 5.0f }; - wide_ft p = { 0.0f, 0.5f, 0.75f, 1.0f }; - wide_ft m = { 0.0f, -1.0f, 1.0f, 2.0f }; - wide_ft s = { 1.0f, 2.0f, 3.0f, 4.0f }; - - auto d = eve::lognormal_distribution(m, s); - - std::cout - << "---- simd" << '\n' - << "<- x = " << x << '\n' - << "<- m = " << m << '\n' - << "<- s = " << s << '\n' - << "<- p = " << p << '\n' - << "-> median(d) = " << eve::median(d) << '\n' - << "-> mode(d) = " << eve::mode(d) << '\n' - << "-> mean(d) = " << eve::mean(d) << '\n' - << "-> var(d) = " << eve::var(d) << '\n' - << "-> entropy(d) = " << eve::entropy(d) << '\n' - << "-> pdf(d, x) = " << eve::pdf(d, x) << '\n' - << "-> invcdf(d, p) = " << eve::invcdf(d, p) << '\n' - << "-> cdf(d, x) = " << eve::cdf(d, x) << '\n'; - - float xf = 9.0f; - float mf = 10.0f; - float sf = 2.0; - auto df = eve::lognormal_distribution(mf, sf); - - std::cout - << "---- scalar" << '\n' - << "<- xf = " << xf << '\n' - << "<- mf = " << mf << '\n' - << "<- sf = " << sf << '\n' - << "-> cdf(df, xf) = " << eve::cdf(df, xf) << '\n' - << "-> mode(df) = " << eve::mode(df) << '\n'; - - - auto d1 = eve::lognormal_distribution(1.0f, 5.0f); - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d1(gen, eve::as()) "<< d1(gen, eve::as()) << std::endl - << "-> d1(gen) "<< d1(gen, eve::as()) << std::endl; - - { - auto d2 = eve::lognormal_distribution_01; - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d2(gen, eve::as()) "<< d2(gen, eve::as()) << std::endl - << "-> d2(gen) "<< d2(gen, eve::as()) << std::endl; - } - - { - auto d3 = eve::lognormal_distribution(0.0, 1.0); - std::array cov = {1.0, 0.0, 0.0, 1.0}; - auto [r, plo, phi] = eve::confidence(d3 - , 5.0 - , cov - , 0.05); - std::cout - << "confidence \n" - << "r " << r << std::endl - << "plo " << plo<< std::endl - << "phi " << phi<< std::endl; - } - - return 0; -} diff --git a/test/doc/proba/normal_distribution.cpp b/test/doc/proba/normal_distribution.cpp deleted file mode 100644 index 6130285c42..0000000000 --- a/test/doc/proba/normal_distribution.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include -#include - -using wide_ft = eve::wide >; - -int main() -{ - wide_ft x = { 0.0f, 1.0f, -1.0f, 5.0f }; - wide_ft p = { 0.0f, 0.5f, 0.75f, 1.0f }; - wide_ft m = { 0.0f, -1.0f, 1.0f, 2.0f }; - wide_ft s = { 1.0f, 2.0f, 3.0f, 4.0f }; - - auto no = eve::normal_distribution(m, s); - - std::cout - << "---- simd" << '\n' - << "<- x = " << x << '\n' - << "<- m = " << m << '\n' - << "<- s = " << s << '\n' - << "<- p = " << p << '\n' - << "-> median(no) = " << eve::median(no) << '\n' - << "-> mode(no) = " << eve::mode(no) << '\n' - << "-> mean(no) = " << eve::mean(no) << '\n' - << "-> var(no) = " << eve::var(no) << '\n' - << "-> entropy(no) = " << eve::entropy(no) << '\n' - << "-> pdf(no, x) = " << eve::pdf(no, x) << '\n' - << "-> invcdf(no, p) = " << eve::invcdf(no, p) << '\n' - << "-> cdf(no, x) = " << eve::cdf(no, x) << '\n'; - - float xf = 9.0f; - float mf = 10.0f; - float sf = 2.0; - auto nof = eve::normal_distribution(mf, sf); - - std::cout - << "---- scalar" << '\n' - << "<- xf = " << xf << '\n' - << "<- mf = " << mf << '\n' - << "<- sf = " << sf << '\n' - << "-> cdf(nof, xf) = " << eve::cdf(nof, xf) << '\n' - << "-> mode(nof) = " << eve::mode(nof) << '\n'; - - - auto d1 = eve::normal_distribution(1.0f, 5.0f); - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d1(gen, eve::as()) "<< d1(gen, eve::as()) << std::endl - << "-> d1(gen) "<< d1(gen, eve::as()) << std::endl; - - { - auto d2 = eve::normal_distribution_01; - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d2(gen, eve::as()) "<< d2(gen, eve::as()) << std::endl - << "-> d2(gen) "<< d2(gen, eve::as()) << std::endl; - } - - { - auto d3 = eve::normal_distribution(1.0, 1.0); - std::array cov = {1.0, 0.0, 0.0, 1.0}; - auto [r, plo, phi] = eve::confidence(d3 - , 0.0 - , cov - , 0.05); - std::cout - << "confidence \n" - << "r " << r << std::endl - << "plo " << plo<< std::endl - << "phi " << phi<< std::endl; - } - return 0; -} diff --git a/test/doc/proba/poisson_distribution.cpp b/test/doc/proba/poisson_distribution.cpp deleted file mode 100644 index cdc7a0c7c6..0000000000 --- a/test/doc/proba/poisson_distribution.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include -#include - -using wide_ft = eve::wide >; - -int main() -{ - wide_ft x = { 0.0f, 1.0f, 3.0f, 5.0f }; - wide_ft lambda = { 0.02f, 0.5f, 1.0f, 10.0f }; - - - - auto po = eve::poisson_distribution(lambda); - - std::cout - << "---- simd" << '\n' - << "<- x = " << x << '\n' - << "<- lambda = " << lambda << '\n' - << "-> median(po) = " << eve::median(po) << " \\\\ possibly approximate\n" - << "-> mode(po) = " << eve::mode(po) << '\n' - << "-> mean(po) = " << eve::mean(po) << '\n' - << "-> var(po) = " << eve::var(po) << '\n' - << "-> pmf(po, x) = " << eve::pmf(po, x) << '\n' - << "-> cdf(po, x) = " << eve::cdf(po, x) << '\n' - << "-> mgf(po, x) = " << eve::mgf(po, x) << '\n'; - - float xf = 2.0f; - float lf = 1.0f; - auto pof = eve::poisson_distribution(lf); - - std::cout - << "---- scalar" << '\n' - << "<- xf = " << xf << '\n' - << "<- lf = " << lf << '\n' - << "-> cdf(pof, xf) = " << eve::cdf(pof, xf) << '\n' - << "-> mean(pof) = " << eve::mean(pof) << '\n' - << "-> var(pof) = " << eve::var(pof) << '\n'; - - auto d1 = eve::poisson_distribution(15.0f); - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d1(gen, eve::as()) "<< d1(gen, eve::as()) << std::endl - << "-> d1(gen) "<< d1(gen, eve::as()) << std::endl; - - { - auto d2 = eve::poisson_distribution_1; - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d2(gen, eve::as()) "<< d2(gen, eve::as()) << std::endl - << "-> d2(gen) "<< d2(gen, eve::as()) << std::endl; - } - - - return 0; -} diff --git a/test/doc/proba/uniform_continuous_distribution.cpp b/test/doc/proba/uniform_continuous_distribution.cpp deleted file mode 100644 index ed465e330c..0000000000 --- a/test/doc/proba/uniform_continuous_distribution.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include - - -int main() -{ - using wide_dt = eve::wide >; - wide_dt x = { 0.0f, 1.0f, 5.0f, 12.0f }; - wide_dt b = { 2, 3, 6, 20 }; - wide_dt a = { -2, 0, 3, 4}; - - auto d = eve::uniform_continuous_distribution(a, b); - - std::cout - << "---- simd with wide double initialization continuous distribution" << '\n' - << "<- x = " << x << '\n' - << "<- a = " << d.a << '\n' - << "<- b = " << d.b << '\n' - << "-> median(d) = " << eve::median(d) << '\n' - << "-> mode(d) = " << eve::mode(d) << '\n' - << "-> mean(d) = " << eve::mean(d) << '\n' - << "-> var(d) = " << eve::var(d) << '\n' - << "-> entropy(d) = " << eve::entropy(d) << '\n' - << "-> pdf(d, x) = " << eve::pdf(d, x) << '\n' - << "-> cdf(d, x) = " << eve::cdf(d, x) << '\n' - << "-> mgf(d, x) = " << eve::mgf(d, x) << '\n'; - - auto d1 = eve::uniform_continuous_distribution(1.0, 5.0); - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d1(gen, eve::as()) "<< d1(gen, eve::as()) << std::endl - << "-> d1(gen) "<< d1(gen, eve::as()) << std::endl; - - auto d2 = eve::uniform_continuous_distribution_01; - std::cout - << "generator \n" - << "-> d2(gen, eve::as()) "<< d2(gen, eve::as()) << std::endl - << "-> d2(gen) "<< d2(gen, eve::as()) << std::endl; - - - - return 0; -} diff --git a/test/doc/proba/uniform_discrete_distribution.cpp b/test/doc/proba/uniform_discrete_distribution.cpp deleted file mode 100644 index e3a163c773..0000000000 --- a/test/doc/proba/uniform_discrete_distribution.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include - - -int main() -{ - using wide_dt = eve::wide >; - using wide_it = eve::wide >; - wide_dt x = { 0.0f, 1.0f, 5.0f, 12.0f }; - wide_it b = { 2, 3, 6, 20 }; - wide_it a = { -2, 0, 3, 4}; - - auto d = eve::uniform_discrete_distribution(a, b, eve::as()); - - std::cout - << "---- simd initialization" << '\n' - << "<- x = " << x << '\n' - << "<- a = " << d.a << '\n' - << "<- b = " << d.b << '\n' - << "<- n = " << d.n << '\n' - << "-> median(d) = " << eve::median(d) << '\n' - << "-> mode(d) = " << eve::mode(d) << '\n' - << "-> mean(d) = " << eve::mean(d) << '\n' - << "-> var(d) = " << eve::var(d) << '\n' - << "-> entropy(d) = " << eve::entropy(d) << '\n' - << "-> cdf(d, x) = " << eve::cdf(d, x) << '\n' - << "-> pmf(d, x) = " << eve::pmf(d, x) << '\n' - << "-> mgf(d, x) = " << eve::mgf(d, x) << '\n' - ; - - auto d0 = eve::uniform_discrete_distribution_01; - - std::cout - << "---- 01 version" << '\n' - << "<- x = " << x << '\n' - << "-> median(d0) = " << eve::median(d0) << '\n' - << "-> mode(d0) = " << eve::mode(d0) << '\n' - << "-> mean(d0) = " << eve::mean(d0) << '\n' - << "-> var(d0) = " << eve::var(d0) << '\n' - << "-> entropy(d0) = " << eve::entropy(d0) << '\n' - << "-> cdf(d0, x) = " << eve::cdf(d0, x) << '\n' - << "-> pmf(d0, x) = " << eve::pmf(d0, x) << '\n' - << "-> mgf(d0, x) = " << eve::mgf(d0, x) << '\n' - ; - - - auto d1 = eve::uniform_discrete_distribution(1.0, 5.0); - std::random_device rd; //Will be used to obtain a seed for the random number engine - std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd() - std::cout - << "generator \n" - << "-> d1(gen, eve::as()) "<< d1(gen, eve::as()) << std::endl - << "-> d1(gen) "<< d1(gen, eve::as()) << std::endl; - - auto d2 = eve::uniform_discrete_distribution_01; - std::cout - << "generator \n" - << "-> d2(gen, eve::as()) "<< d2(gen, eve::as()) << std::endl - << "-> d2(gen) "<< d2(gen, eve::as()) << std::endl; - - return 0; -} diff --git a/test/unit/module/CMakeLists.txt b/test/unit/module/CMakeLists.txt index da589c9840..a253ad7e23 100644 --- a/test/unit/module/CMakeLists.txt +++ b/test/unit/module/CMakeLists.txt @@ -7,7 +7,6 @@ ## Modules add_subdirectory(core) add_subdirectory(complex) -add_subdirectory(proba) if(EVE_USE_BOOST) add_subdirectory(bessel) diff --git a/test/unit/module/proba/CMakeLists.txt b/test/unit/module/proba/CMakeLists.txt deleted file mode 100644 index 73a1b02bca..0000000000 --- a/test/unit/module/proba/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -##================================================================================================== -## EVE - Expressive Vector Engine -## Copyright : EVE Project Contributors -## SPDX-License-Identifier: BSL-1.0 -##================================================================================================== - -add_custom_target(unit.proba.exe ) -add_dependencies(unit.exe unit.proba.exe ) - -make_unit( "unit.proba" binomial_distribution.cpp ) -make_unit( "unit.proba" cauchy_distribution.cpp ) -make_unit( "unit.proba" ev_distribution.cpp ) -make_unit( "unit.proba" exponential_distribution.cpp ) -make_unit( "unit.proba" gamma_distribution.cpp ) -make_unit( "unit.proba" lognormal_distribution.cpp ) -make_unit( "unit.proba" normal_distribution.cpp ) -make_unit( "unit.proba" poisson_distribution.cpp ) -make_unit( "unit.proba" uniform_continuous_distribution.cpp ) -make_unit( "unit.proba" uniform_discrete_distribution.cpp ) diff --git a/test/unit/module/proba/binomial_distribution.cpp b/test/unit/module/proba/binomial_distribution.cpp deleted file mode 100644 index 6dbbde1952..0000000000 --- a/test/unit/module/proba/binomial_distribution.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include -#include -#include - -TTS_CASE_TPL("Check eve::binomial_distribution behavior" - , eve::test::simd::ieee_reals - ) - (tts::type) -{ - { - auto bino = eve::binomial_distribution{T(4), T(0.25)}; - TTS_ULP_EQUAL(eve::median(bino) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::mean(bino) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::mode(bino) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::var(bino) , T(0.75) , 0); - TTS_ULP_EQUAL(eve::stdev(bino) , T(8.660254037844386e-01) , 0); - TTS_ULP_EQUAL(eve::cdf(bino, T(0.0)) , T(3.1640625e-01) , 2.0); - TTS_ULP_EQUAL(eve::pmf(bino, T(1.0)) , T(1.0546875e-3) , 1.0); - } - { - auto bino = eve::binomial_distribution{eve::one, T(0.25)}; - TTS_ULP_EQUAL(eve::median(bino) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::mean(bino) , T(0.25) , 0); - TTS_ULP_EQUAL(eve::mode(bino) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::var(bino) , T(1.875e-01) , 0); - TTS_ULP_EQUAL(eve::stdev(bino) , T(4.330127018922193e-01) , 0); - TTS_ULP_EQUAL(eve::cdf(bino, T(0.0)) , T(0.75) , 1.0); - TTS_ULP_EQUAL(eve::pmf(bino, T(1.0)) , T(0.25) , 1.0); - } - { - auto bino = eve::binomial_distribution{T(4), eve::half}; - TTS_ULP_EQUAL(eve::median(bino) , T(2.0) , 0); - TTS_ULP_EQUAL(eve::mean(bino) , T(2.0) , 0); - TTS_ULP_EQUAL(eve::mode(bino) , T(2.0) , 0); - TTS_ULP_EQUAL(eve::var(bino) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::stdev(bino) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::cdf(bino, T(0.0)) , T(0.0625) , 1.0); - TTS_ULP_EQUAL(eve::pmf(bino, T(1.0)) , T(1.041666666666667e-02) , 1.0); - } - { - auto bino = eve::bernouilli; - TTS_ULP_EQUAL(eve::median(bino) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::mean(bino) , T(0.5) , 0); - TTS_ULP_EQUAL(eve::mode(bino) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::var(bino) , T(0.25) , 0); - TTS_ULP_EQUAL(eve::stdev(bino) , T(0.5) , 0); - TTS_ULP_EQUAL(eve::cdf(bino, T(0.0)) , T(0.5) , 1.0); - TTS_ULP_EQUAL(eve::pmf(bino, T(1.0)) , T(0.5) , 1.0); - } -}; diff --git a/test/unit/module/proba/cauchy_distribution.cpp b/test/unit/module/proba/cauchy_distribution.cpp deleted file mode 100644 index ab3596fe96..0000000000 --- a/test/unit/module/proba/cauchy_distribution.cpp +++ /dev/null @@ -1,68 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include -#include -#include -#include - -TTS_CASE_TPL("Check eve::cauchy_distribution behavior" - , eve::test::simd::ieee_reals - ) - (tts::type) -{ - auto inf = eve::inf(eve::as()); - { - auto ca = eve::cauchy_distribution{T(1.0), T(2.0)}; - TTS_ULP_EQUAL(eve::cdf(ca, T(0.0)) , T(3.524163823495667e-01) , 0.5); - TTS_ULP_EQUAL(eve::pdf(ca, T(1.0)) , T(1.591549430918953e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(ca, T(0.0)) , -inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ca, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ca, T(0.5)) , T(1) , 0.5); - TTS_ULP_EQUAL(eve::median(ca) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::mode(ca) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::scale(ca) , T(2.0) , 0); - TTS_ULP_EQUAL(eve::fisher(ca) , T(1/8.0) , 0); - } - { - auto ca = eve::cauchy_distribution(eve::zero, T(2.0)); - TTS_ULP_EQUAL(eve::cdf(ca, T(0.0)) , T(0.5) , 0.5); - TTS_ULP_EQUAL(eve::pdf(ca, T(1.0)) , T(1.273239544735163e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(ca, T(0.0)) , -inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ca, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ca, T(0.5)) , T(0) , 0.5); - TTS_ULP_EQUAL(eve::median(ca) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::mode(ca) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::scale(ca) , T(2.0) , 0); - TTS_ULP_EQUAL(eve::fisher(ca) , T(1/8.0) , 0); - } - { - auto ca = eve::cauchy_distribution(T(2.0), eve::one); - TTS_ULP_EQUAL(eve::cdf(ca, T(0.0)) , T(1.475836176504333e-01) , 0.5); - TTS_ULP_EQUAL(eve::pdf(ca, T(1.0)) , T(1.591549430918953e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(ca, T(0.0)) , -inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ca, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ca, T(0.5)) , T(2) , 0.5); - TTS_ULP_EQUAL(eve::median(ca) , T(2.0) , 0); - TTS_ULP_EQUAL(eve::mode(ca) , T(2.0) , 0); - TTS_ULP_EQUAL(eve::scale(ca) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::fisher(ca) , T(0.5) , 0); - } - { - auto ca = eve::cauchy_distribution_01; - TTS_ULP_EQUAL(eve::cdf(ca, T(0.0)) , T(0.5) , 0.5); - TTS_ULP_EQUAL(eve::pdf(ca, T(1.0)) , T(1.591549430918953e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(ca, T(0.0)) , -inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ca, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ca, T(0.5)) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::median(ca) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::mode(ca) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::scale(ca) , T(1) , 0); - TTS_ULP_EQUAL(eve::fisher(ca) , T(0.5) , 0); - } -}; diff --git a/test/unit/module/proba/ev_distribution.cpp b/test/unit/module/proba/ev_distribution.cpp deleted file mode 100644 index 5cfb24773b..0000000000 --- a/test/unit/module/proba/ev_distribution.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include -#include -#include - - -TTS_CASE_TPL("Check eve::ev_distribution behavior" - , eve::test::simd::ieee_reals - ) - (tts::type) -{ - auto inf = eve::inf(eve::as()); - { - auto ev = eve::ev_distribution{T(1.0), T(2.0)}; - TTS_ULP_EQUAL(eve::median(ev) , T(1.733025841163329) , 1.0); - TTS_ULP_EQUAL(eve::mean(ev) , T(2.154431329803066) , 0.5); - TTS_ULP_EQUAL(eve::mode(ev) , T(1.0) , 0.5); - TTS_ULP_EQUAL(eve::var(ev) , T(6.579736267392906) , 0.5); - TTS_ULP_EQUAL(eve::stdev(ev) , T(2.565099660323728) , 0.5); - TTS_ULP_EQUAL(eve::cdf(ev, T(0.0)) , T(4.547607881073950e-01) , 0.5); - TTS_ULP_EQUAL(eve::pdf(ev, T(1.0)) , T(1.839397205857212e-01) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ev, T(0.0)) , -inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ev, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ev, T(0.5)) , T(2.669741588366713e-01) , 0.5); - } - { - auto ev = eve::ev_distribution{eve::zero, T(2.0)}; - TTS_ULP_EQUAL(eve::median(ev) , T(7.330258411633287e-01) , 0.5); - TTS_ULP_EQUAL(eve::mean(ev) , T(1.154431329803066) , 0.5); - TTS_ULP_EQUAL(eve::mode(ev) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::var(ev) , T(6.579736267392906) , 0.5); - TTS_ULP_EQUAL(eve::stdev(ev) , T(2.565099660323728) , 0.5); - TTS_ULP_EQUAL(eve::cdf(ev, T(1.0)) , T(8.077043544520350e-01) , 1); - TTS_ULP_EQUAL(eve::pdf(ev, T(1.0)) , T(1.585209605389711e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(ev, T(0.0)) , -inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ev, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ev, T(0.5)) , T(-7.330258411633287e-01) , 0.5); - } - { - auto ev = eve::ev_distribution_01; - TTS_ULP_EQUAL(eve::median(ev) , T(3.665129205816643e-01) , 0.5); - TTS_ULP_EQUAL(eve::mean(ev) , T(0.57721566490153286) , 0.5); - TTS_ULP_EQUAL(eve::mode(ev) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::var(ev) , T(1.644934066848226) , 1.0); - TTS_ULP_EQUAL(eve::stdev(ev) , T(1.282549830161864) , 0.5); - TTS_ULP_EQUAL(eve::cdf(ev, T(1.0)) , T(9.340119641546875e-01) , 0.5); - TTS_ULP_EQUAL(eve::pdf(ev, T(1.0)) , T(1.793740787340172e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(ev, T(0.0)) , -inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ev, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ev, T(0.5)) , T(-3.665129205816643e-01) , 0.5); - } -}; diff --git a/test/unit/module/proba/exponential_distribution.cpp b/test/unit/module/proba/exponential_distribution.cpp deleted file mode 100644 index acf1fbfefe..0000000000 --- a/test/unit/module/proba/exponential_distribution.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include -#include -#include -#include -#include - -TTS_CASE_TPL("Check eve::exponential_distribution behavior" - , eve::test::simd::ieee_reals - ) - (tts::type) -{ - using elt_t = eve::element_type_t; - auto inf = eve::inf(eve::as()); - { - auto ex = eve::exponential_distribution{T(2.0)}; - TTS_ULP_EQUAL(eve::median(ex) , T(eve::log_2(eve::as())/2) , 0.5); - TTS_ULP_EQUAL(eve::mean (ex) , T(0.5) , 0.5); - TTS_ULP_EQUAL(eve::mode (ex) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::var (ex) , T(0.25) , 0.5); - TTS_ULP_EQUAL(eve::stdev (ex) , T(0.5) , 0.5); - TTS_ULP_EQUAL(eve::cdf(ex, T(1.0)) , T(8.646647167633873e-01) , 0.5); - TTS_ULP_EQUAL(eve::pdf(ex, T(1.0)) , T(2.706705664732254e-01) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ex, T(0.0)) , T(0) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ex, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ex, T(0.5)) , T(3.465735902799726e-01) , 0.5); - } - { - auto ex = eve::exponential_distribution{T(2.0)}; - TTS_ULP_EQUAL(eve::median(ex) , T(eve::log_2(eve::as())/2) , 0.5); - TTS_ULP_EQUAL(eve::mean (ex) , T(0.5) , 0.5); - TTS_ULP_EQUAL(eve::mode (ex) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::var (ex) , T(0.25) , 0.5); - TTS_ULP_EQUAL(eve::stdev (ex) , T(0.5) , 0.5); - TTS_ULP_EQUAL(eve::cdf(ex, elt_t(1.0)) , T(8.646647167633873e-01) , 0.5); - TTS_ULP_EQUAL(eve::pdf(ex, elt_t(1.0)) , T(2.706705664732254e-01) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ex, elt_t(0.0)) , T(0) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ex, elt_t(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ex, elt_t(0.5)) , T(3.465735902799726e-01) , 0.5); - } - { - auto ex = eve::exponential_distribution_1; - TTS_ULP_EQUAL(eve::median(ex) , T(eve::log_2(eve::as())) , 0.5); - TTS_ULP_EQUAL(eve::mean (ex) , T(1) , 0.5); - TTS_ULP_EQUAL(eve::mode (ex) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::var (ex) , T(1) , 0.5); - TTS_ULP_EQUAL(eve::stdev (ex) , T(1) , 0.5); - TTS_ULP_EQUAL(eve::cdf(ex, T(1.0)) , T(6.321205588285577e-01) , 0.5); - TTS_ULP_EQUAL(eve::pdf(ex, T(1.0)) , T(3.678794411714423e-01) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ex, T(0.0)) , T(0) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ex, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(ex, T(0.5)) , T(0.69314718055994530942) , 0.5); - } -}; diff --git a/test/unit/module/proba/gamma_distribution.cpp b/test/unit/module/proba/gamma_distribution.cpp deleted file mode 100644 index 3035fc2c64..0000000000 --- a/test/unit/module/proba/gamma_distribution.cpp +++ /dev/null @@ -1,53 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include -#include -#include - -TTS_CASE_TPL("Check eve::gamma_distribution behavior" - , eve::test::simd::ieee_reals - ) - (tts::type) -{ - auto inf = eve::inf(eve::as()); - { - auto d = eve::gamma_distribution{T(2.0), T(2.0)}; - TTS_ULP_EQUAL(eve::mean(d) , T(4.0) , 0.5); - TTS_ULP_EQUAL(eve::var(d) , T(8.0) , 0.5); - TTS_ULP_EQUAL(eve::stdev(d) , T(2.828427124746190) , 0.5); - TTS_ULP_EQUAL(eve::cdf(d, T(0.0)) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::cdf(d, T(1.0)) , T(9.020401043104986e-02) , 5); - TTS_ULP_EQUAL(eve::pdf(d, T(1.0)) , T(1.516326649281584e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(d, T(0.0)) , T(0) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(d, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(d, T(0.5)) , T(3.356693980033322) , 4.0); - } - { - auto d = eve::gamma_distribution{eve::one, T(2.0)}; - TTS_ULP_EQUAL(eve::mean(d) , T(2.0) , 0.5); - TTS_ULP_EQUAL(eve::var(d) , T(4.0) , 0.5); - TTS_ULP_EQUAL(eve::stdev(d) , T(2.0) , 0.5); - TTS_ULP_EQUAL(eve::cdf(d, T(1.0)) , T(3.934693402873666e-01) , 2.0); - TTS_ULP_EQUAL(eve::pdf(d, T(1.0)) , T(3.032653298563167e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(d, T(0.0)) , T(0) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(d, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(d, T(0.5)) , T(1.386294361119891) , 1.0); - } - { - auto d = eve::gamma_distribution_11; - TTS_ULP_EQUAL(eve::mean(d) , T(1.0) , 0.5); - TTS_ULP_EQUAL(eve::var(d) , T(1.0) , 0.5); - TTS_ULP_EQUAL(eve::stdev(d) , T(1.0) , 0.5); - TTS_ULP_EQUAL(eve::cdf(d, T(1.0)) , T(6.321205588285577e-01) , 1); - TTS_ULP_EQUAL(eve::pdf(d, T(1.0)) , T(3.678794411714423e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(d, T(0.0)) , T(0) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(d, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(d, T(0.5)) , T(6.931471805599453e-01) , 0.5); - } -}; diff --git a/test/unit/module/proba/lognormal_distribution.cpp b/test/unit/module/proba/lognormal_distribution.cpp deleted file mode 100644 index 2b86c6c4b7..0000000000 --- a/test/unit/module/proba/lognormal_distribution.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include -#include -#include -#include - -TTS_CASE_TPL("Check eve::lognormal_distribution behavior" - , eve::test::simd::ieee_reals - ) - (tts::type) -{ - auto inf = eve::inf(eve::as()); - { - auto lno = eve::lognormal_distribution{T(1.0), T(2.0)}; - TTS_ULP_EQUAL(eve::median(lno) , T(2.718281828459045235360287471) , 0.5); - TTS_ULP_EQUAL(eve::mean(lno) , T(20.085536923187667740928529654) , 0.5); - TTS_ULP_EQUAL(eve::mode(lno) , T(4.978706836786394e-02) , 0.5); - TTS_ULP_EQUAL(eve::var(lno) , T(21623.0370013139813943) , 0.5); - TTS_ULP_EQUAL(eve::stdev(lno) , T(147.047737151286967345379028091) , 0.5); - TTS_ULP_EQUAL(eve::cdf(lno, T(0.0)) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::raw(eve::cdf)(lno, T(0.0)), T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::pdf(lno, T(1.0)) , T(1.760326633821498e-01) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(lno, T(0.0)) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(lno, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(lno, T(0.5)) , T(2.718281828459045235360287471) , 0.5); - } - { - auto lno = eve::lognormal_distribution{eve::zero, T(2.0)}; - TTS_ULP_EQUAL(eve::median(lno) , T(1.0) , 0.5); - TTS_ULP_EQUAL(eve::mean(lno) , T(7.389056098930650) , 0.5); - TTS_ULP_EQUAL(eve::mode(lno) , T(1.831563888873418e-02) , 0.5); - TTS_ULP_EQUAL(eve::var(lno) , T(2926.359837008584) , 0.5); - TTS_ULP_EQUAL(eve::stdev(lno) , T(54.09583936874058) , 0.5); - TTS_ULP_EQUAL(eve::cdf(lno, T(1.0)) , T(0.5) , 1); - TTS_ULP_EQUAL(eve::raw(eve::cdf)(lno, T(1.0)), T(0.5) , 1); - TTS_ULP_EQUAL(eve::pdf(lno, T(1.0)) , T(1.994711402007164e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(lno, T(0.0)) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(lno, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(lno, T(0.5)) , T(1) , 0.5); - } - { - auto inf = eve::inf(eve::as()); - - auto lno = eve::lognormal_distribution_01; - TTS_ULP_EQUAL(eve::median(lno) , T(1.0) , 0.0); - TTS_ULP_EQUAL(eve::mean(lno) , T(1.648721270700128) , 0.5); - TTS_ULP_EQUAL(eve::mode(lno) , T(0.367879441171442) , 0.5); - TTS_ULP_EQUAL(eve::var(lno) , T(4.670774270471604) , 0.5); - TTS_ULP_EQUAL(eve::stdev(lno) , T(2.161197415895088) , 0.5); - TTS_ULP_EQUAL(eve::cdf(lno, T(1.0)) , T(0.5) , 1); - TTS_ULP_EQUAL(eve::raw(eve::cdf)(lno, T(1.0)), T(0.5) , 1); - TTS_ULP_EQUAL(eve::pdf(lno, T(1.0)) , T(3.989422804014327e-01) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(lno, T(0.0)) , T(0.0) , 0.5); - TTS_ULP_EQUAL(eve::invcdf(lno, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(lno, T(0.5)) , T(1) , 0.5); - } -}; diff --git a/test/unit/module/proba/normal_distribution.cpp b/test/unit/module/proba/normal_distribution.cpp deleted file mode 100644 index 1fbb01a3cc..0000000000 --- a/test/unit/module/proba/normal_distribution.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include -#include -#include -#include - -TTS_CASE_TPL("Check eve::normal_distribution behavior" - , eve::test::simd::ieee_reals - ) - (tts::type) -{ - auto inf = eve::inf(eve::as()); - { - auto no = eve::normal_distribution{T(1.0), T(2.0)}; - TTS_ULP_EQUAL(eve::median(no) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::mean(no) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::mode(no) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::var(no) , T(4.0) , 0); - TTS_ULP_EQUAL(eve::stdev(no) , T(2.0) , 0); - TTS_ULP_EQUAL(eve::cdf(no, T(0.0)) , T(0.30853753872598689636229538939166226011639782444542) , 1.0); - TTS_ULP_EQUAL(eve::raw(eve::cdf)(no, T(0.0)), T(0.30853753872598689636229538939166226011639782444542) , 1.0); - TTS_ULP_EQUAL(eve::pdf(no, T(1.0)) , T(0.19947114020071633896997302996719093423792931558246) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(no, T(0.0)) , -inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(no, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(no, T(0.5)) , T(1) , 0.5); - } - { - auto no = eve::normal_distribution{eve::zero, T(2.0)}; - TTS_ULP_EQUAL(eve::median(no) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::mean(no) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::mode(no) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::var(no) , T(4.0) , 0); - TTS_ULP_EQUAL(eve::stdev(no) , T(2.0) , 0); - TTS_ULP_EQUAL(eve::cdf(no, T(-1.0)) , T(0.30853753872598689636229538939166226011639782444542) , 1.0); - TTS_ULP_EQUAL(eve::raw(eve::cdf)(no, T(-1.0)), T(0.30853753872598689636229538939166226011639782444542) , 1.0); - TTS_ULP_EQUAL(eve::pdf(no, T(0.0)) , T(0.19947114020071633896997302996719093423792931558246) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(no, T(0.0)) , -inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(no, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(no, T(0.5)) , T(0) , 0.5); - } - { - auto no = eve::normal_distribution_01; - TTS_ULP_EQUAL(eve::median(no) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::mean(no) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::mode(no) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::var(no) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::stdev(no) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::cdf(no, T(0.0)) , T(0.5) , 1); - TTS_ULP_EQUAL(eve::raw(eve::cdf)(no, T(0.0)), T(0.5) , 1); - TTS_ULP_EQUAL(eve::pdf(no, T(0.0)) , T(2*0.19947114020071633896997302996719093423792931558246) , 1.0); - TTS_ULP_EQUAL(eve::invcdf(no, T(0.0)) , -inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(no, T(1.0)) , inf , 0.5); - TTS_ULP_EQUAL(eve::invcdf(no, T(0.5)) , T(0) , 0.5); - } -}; diff --git a/test/unit/module/proba/poisson_distribution.cpp b/test/unit/module/proba/poisson_distribution.cpp deleted file mode 100644 index 1ab0f9af96..0000000000 --- a/test/unit/module/proba/poisson_distribution.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include -#include -#include -#include - -TTS_CASE_TPL("Check eve::poisson_distribution behavior" - , eve::test::simd::ieee_reals - ) - (tts::type) -{ - { - auto ex = eve::poisson_distribution{T(2.0)}; - TTS_ULP_EQUAL(eve::median(ex) , T(2) , 0.5); - TTS_ULP_EQUAL(eve::mean (ex) , T(2) , 0.5); - TTS_ULP_EQUAL(eve::mode (ex) , T(1) , 0.5); - TTS_ULP_EQUAL(eve::var (ex) , T(2) , 0.5); - TTS_ULP_EQUAL(eve::stdev (ex) , T(eve::sqrt_2(eve::as())) , 0.5); - TTS_ULP_EQUAL(eve::cdf(ex, T(1.0)) , T( 5.939941502901619e-01) , 3.5); - TTS_ULP_EQUAL(eve::cdf(ex, T(10.0)) , T(9.997995795905170e-01) , 0.5); - TTS_ULP_EQUAL(eve::pmf(ex, T(1.0)) , T(2.706705664732254e-01) , 0.5); - } - { - auto ex = eve::poisson_distribution_1; - TTS_ULP_EQUAL(eve::median(ex) , T(1) , 0.5); - TTS_ULP_EQUAL(eve::mean (ex) , T(1) , 0.5); - TTS_ULP_EQUAL(eve::mode (ex) , T(0) , 0.5); - TTS_ULP_EQUAL(eve::var (ex) , T(1) , 0.5); - TTS_ULP_EQUAL(eve::stdev (ex) , T(1) , 0.5); - TTS_ULP_EQUAL(eve::cdf(ex, T(1.0)) , T(8.646647167633873e-01) , 3.5); - TTS_ULP_EQUAL(eve::cdf(ex, T(10.0)) , T(9.999832982992097e-01) , 0.5); - TTS_ULP_EQUAL(eve::pmf(ex, T(1.0)) , T(1) , 0.5); - } -}; diff --git a/test/unit/module/proba/uniform_continuous_distribution.cpp b/test/unit/module/proba/uniform_continuous_distribution.cpp deleted file mode 100644 index f573382f97..0000000000 --- a/test/unit/module/proba/uniform_continuous_distribution.cpp +++ /dev/null @@ -1,38 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include -#include - -TTS_CASE_TPL("Check eve::uniform_continuous_distribution behavior" - , eve::test::simd::ieee_reals - ) - (tts::type) -{ - { - auto d = eve::uniform_continuous_distribution{T(1), T(2)}; - TTS_ULP_EQUAL(eve::median(d) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::mean(d) , T(1.5) , 0); - TTS_ULP_EQUAL(eve::mode(d) , T(1) , 0); - TTS_ULP_EQUAL(eve::var(d) , T(1/12.0) , 0); - TTS_ULP_EQUAL(eve::stdev(d) , T(2.886751345948129e-01) , 1); - TTS_ULP_EQUAL(eve::cdf(d, T(0.0)) , T(0) , 1.0); - TTS_ULP_EQUAL(eve::cdf(d, T(1.5)) , T(0.5) , 1.0); - TTS_ULP_EQUAL(eve::pdf(d, T(1.0)) , T(1) , 1.0); - } - { - auto d = eve::uniform_continuous_distribution_01; - TTS_ULP_EQUAL(eve::median(d) , T(0) , 0); - TTS_ULP_EQUAL(eve::mean(d) , T(0.5) , 0); - TTS_ULP_EQUAL(eve::mode(d) , T(0) , 0); - TTS_ULP_EQUAL(eve::var(d) , T(1/12.0) , 0); - TTS_ULP_EQUAL(eve::stdev(d) , T(2.886751345948129e-01) , 1); - TTS_ULP_EQUAL(eve::cdf(d, T(0.0)) , T(0) , 1.0); - TTS_ULP_EQUAL(eve::pdf(d, T(1.0)) , T(1) , 1.0); - } -}; diff --git a/test/unit/module/proba/uniform_discrete_distribution.cpp b/test/unit/module/proba/uniform_discrete_distribution.cpp deleted file mode 100644 index 3aaa7298be..0000000000 --- a/test/unit/module/proba/uniform_discrete_distribution.cpp +++ /dev/null @@ -1,38 +0,0 @@ -//================================================================================================== -/** - EVE - Expressive Vector Engine - Copyright : EVE Project Contributors - SPDX-License-Identifier: BSL-1.0 -**/ -//================================================================================================== -#include "test.hpp" -#include -#include - -TTS_CASE_TPL("Check eve::uniform_discrete_distribution_distribution behavior" - , eve::test::simd::ieee_reals - ) - (tts::type) -{ - { - auto d = eve::uniform_discrete_distribution{T(1), T(2)}; - TTS_ULP_EQUAL(eve::median(d) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::mean(d) , T(1.5) , 0); - TTS_ULP_EQUAL(eve::mode(d) , T(1.0) , 0); - TTS_ULP_EQUAL(eve::var(d) , T(0.25) , 0); - TTS_ULP_EQUAL(eve::stdev(d) , T(0.5) , 1); - TTS_ULP_EQUAL(eve::cdf(d, T(0.0)) , T(0) , 1.0); - TTS_ULP_EQUAL(eve::cdf(d, T(1.5)) , T(0.5) , 1.0); - TTS_ULP_EQUAL(eve::pmf(d, T(1.0)) , T(0.5) , 1.0); - } - { - auto d = eve::uniform_discrete_distribution_01; - TTS_ULP_EQUAL(eve::median(d) , T(0) , 0); - TTS_ULP_EQUAL(eve::mean(d) , T(0.5) , 0); - TTS_ULP_EQUAL(eve::mode(d) , T(0.0) , 0); - TTS_ULP_EQUAL(eve::var(d) , T(0.25) , 0); - TTS_ULP_EQUAL(eve::stdev(d) , T(0.5) , 1); - TTS_ULP_EQUAL(eve::cdf(d, T(0.0)) , T(0.5) , 1.0); - TTS_ULP_EQUAL(eve::pmf(d, T(1.0)) , T(0.5) , 1.0); - } -};