| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //====================================================================================================================== | ||
| 2 | /* | ||
| 3 | POLYFLOAT - Extended precision floating points | ||
| 4 | Copyright : POLYFLOAT Contributors & Maintainers | ||
| 5 | SPDX-License-Identifier: BSL-1.0 | ||
| 6 | */ | ||
| 7 | //====================================================================================================================== | ||
| 8 | #pragma once | ||
| 9 | |||
| 10 | #include <polyfloat/details/callable.hpp> | ||
| 11 | #include <polyfloat/types/concepts.hpp> | ||
| 12 | #include <polyfloat/types/traits.hpp> | ||
| 13 | #include <type_traits> | ||
| 14 | |||
| 15 | namespace plf | ||
| 16 | { | ||
| 17 | |||
| 18 | template<typename Options> | ||
| 19 | struct sigmoid_t : plf::elementwise_callable<sigmoid_t, eve::sigmoid_t, Options, raw_option, pedantic_option> | ||
| 20 | { | ||
| 21 | 20 | template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept | |
| 22 | { | ||
| 23 | 20 | return POLYFLOAT_CALL(z); | |
| 24 | } | ||
| 25 | |||
| 26 | 16 | POLYFLOAT_CALLABLE_OBJECT(sigmoid_t, sigmoid_); | |
| 27 | }; | ||
| 28 | //====================================================================================================================== | ||
| 29 | //! @addtogroup math | ||
| 30 | //! @{ | ||
| 31 | //! @var sigmoid | ||
| 32 | //! @brief return the sigmoidonential value. | ||
| 33 | //! | ||
| 34 | //! @groupheader{Header file} | ||
| 35 | //! | ||
| 36 | //! @code | ||
| 37 | //! #include <polyfloat/core.hpp> | ||
| 38 | //! @endcode | ||
| 39 | //! | ||
| 40 | //! @groupheader{Callable Signatures} | ||
| 41 | //! | ||
| 42 | //! @code | ||
| 43 | //! namespace polyfloat | ||
| 44 | //! | ||
| 45 | //! { | ||
| 46 | //! // Regular overload | ||
| 47 | //! constexpr auto sigmoid( auto x) noexcept; // 1 | ||
| 48 | //! | ||
| 49 | //! // Lanes masking | ||
| 50 | //! constexpr auto sigmoid[conditional_expr auto c]( auto x) noexcept; // 2 | ||
| 51 | //! constexpr auto sigmoid[logical_value auto m]( auto x) noexcept; // 2 | ||
| 52 | //! } | ||
| 53 | //! @endcode | ||
| 54 | //! | ||
| 55 | //! **Parameters** | ||
| 56 | //! | ||
| 57 | //! * `x`: [floating value](@ref eve::floating_value). | ||
| 58 | //! * `c`: [Conditional expression](@ref eve::conditional_expr) masking the operation. | ||
| 59 | //! * `m`: [Logical value](@ref eve::logical_value) masking the operation. | ||
| 60 | //! | ||
| 61 | //! **Return value** | ||
| 62 | //! | ||
| 63 | //! 1. Returns \f$\frac{1}{1+e^{-x}}\f$. In particular: | ||
| 64 | //! * If the element is \f$1/2\f$, \f$1\f$ is returned | ||
| 65 | //! * If the element is \f$-\infty\f$, \f$+0\f$ is returned | ||
| 66 | //! * If the element is \f$\infty\f$, \f$1\f$ is returned | ||
| 67 | //! * If the element is a `NaN`, `NaN` is returned | ||
| 68 | //! 2. [The operation is performed conditionally](@ref conditional). | ||
| 69 | //! | ||
| 70 | //! @groupheader{External references} | ||
| 71 | //! * [Wolfram MathWorld](https://www.wolframalpha.com/input/?i=sigmoid) | ||
| 72 | //! * [Wikipedia](https://en.wikipedia.org/wiki/Sigmoid_function) | ||
| 73 | //! | ||
| 74 | //! | ||
| 75 | //! @groupheader{Example} | ||
| 76 | //! | ||
| 77 | //! @godbolt{doc/math/sigmoid.cpp} | ||
| 78 | //====================================================================================================================== | ||
| 79 | |||
| 80 | inline constexpr auto sigmoid = eve::functor<sigmoid_t>; | ||
| 81 | //====================================================================================================================== | ||
| 82 | //! @} | ||
| 83 | //====================================================================================================================== | ||
| 84 | } | ||
| 85 | |||
| 86 | namespace plf::_ | ||
| 87 | { | ||
| 88 | |||
| 89 | 16 | template<typename T, eve::callable_options O> constexpr auto sigmoid_(POLYFLOAT_DELAY(), O const& o, T xx) noexcept | |
| 90 | { | ||
| 91 | 16 | return plf::rec[eve::pedantic](plf::inc(plf::exp[o](-xx))); | |
| 92 | } | ||
| 93 | } | ||
| 94 |