E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ variance

eve::variance = functor<variance_t>
inlineconstexpr

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto variance(eve::floating_value auto ... xs) noexcept; // 1
constexpr auto variance(kumi::non_empty_product_type auto const& xs) noexcept; // 2
// Lanes masking
constexpr auto variance[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto variance[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Semantic options
constexpr auto variance[raw] (/* any of the above overloads */) noexcept; // 4
constexpr auto variance[widen](/* any of the above overloads */) noexcept; // 5
constexpr auto variance[kahan](/* any of the above overloads */) noexcept; // 6
constexpr auto variance[unbiased](/* any of the above overloads */) noexcept; // 7
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
The concept floating_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:116
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:134
constexpr auto variance
tuple_callable computing the variance of its arguments.
Definition variance.hpp:108
typename decltype(detail::as_translated_type(as< T >{}))::type translate_t
Returns the final translated type of T.
Definition translation.hpp:107
EVE Main Namespace.
Definition abi.hpp:19

Parameters

Return value

The value of the variance of the arguments is returned.

  1. the computation of the variance of its arguments.
  2. the computation is made on the tuple values.
  3. The operation is performed conditionnaly
  4. No provision is made to avoid inaccuracies.
  5. The variance is computed in the double sized element type (if available).
  6. Compensated algorithm for better precision.
  7. the normalizing factor N-1 instead of N to get the best unbiased estimate.
See also
`welford_variance` for incremental or parallel variance and average computations.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, 1.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, -eve::smallestposval(eve::as(1.0)), eve::smallestposval(eve::as(1.0))};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << std::setprecision(15);
std::cout << "-> variance(wf0, wf1) = " << eve::variance(wf0, wf1) << "\n";
std::cout << "-> variance(wi0, wi1) = " << eve::variance(wi0, wi1) << "\n";
std::cout << "-> variance[ignore_last(2)](wi0, wi1) = " << eve::variance[eve::ignore_last(2)](wi0, wi1) << "\n";
std::cout << "-> variance[wi0 != 0](wi0, wi1) = " << eve::variance[wi0 != 0](wi0, wi1) << "\n";
std::cout << "-> variance[raw](wi0, wi1) = " << eve::variance[eve::raw](wi0, wi1) << "\n";
std::cout << "-> variance(1.0f, eps_2, eps_2, eps_2) = " << eve::variance(1.0f, eps_2, eps_2, eps_2) << "\n";
std::cout << "-> variance[kahan](1.0f, eps_2, eps_2, eps_2) = " << eve::variance[eve::kahan](1.0f, eps_2, eps_2, eps_2) << " // float computation\n";
std::cout << "-> variance[raw](1.0f, eps_2, eps_2, eps_2) = " << eve::variance[eve::raw](1.0f, eps_2, eps_2, eps_2) << "\n";
auto deps_2 = double(eps_2);
std::cout << "-> variance(1.0, deps_2, deps_2, eps_2) = " << float(eve::variance[eve::kahan](1.0, deps_2, deps_2, deps_2)) << " // double computation converted to float\n";
auto tup = kumi::tuple{1.0f, eps_2, eps_2, eps_2};
std::cout << "-> variance[kahan](tup) = " << eve::variance[eve::kahan](tup) << "\n";
std::cout <<eve::variance(1.0f, 2.0f, 3.0f, 4.0f) << "\n";
std::cout <<eve::variance[eve::raw](1.0f, 2.0f, 3.0f, 4.0f) << "\n";
std::cout <<eve::variance[eve::unbiased](1.0f, 2.0f, 3.0f, 4.0f) << "\n";
std::cout <<eve::variance[eve::unbiased][eve::raw](1.0f, 2.0f, 3.0f, 4.0f) << "\n";
std::cout <<eve::variance[eve::unbiased][eve::raw][eve::widen](1.0f, 2.0f, 3.0f, 4.0f) << "\n";
}
constexpr auto eps
Computes a constant to the machine epsilon.
Definition eps.hpp:74
constexpr auto smallestposval
Computes the smallest normal positive value.
Definition smallestposval.hpp:71
Lightweight type-wrapper.
Definition as.hpp:29
Conditional expression ignoring the k last lanes from a eve::simd_value.
Definition conditional.hpp:320
Wrapper for SIMD registers.
Definition wide.hpp:94