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

◆ welford_average

auto eve::welford_average = functor<welford_average_t>
inlineconstexpr

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto welford_average(auto ... xs) noexcept; //1
constexpr auto welford_average(non_empty_product_type xs) noexcept; //2
//Semantic options
constexpr auto welford_average[widen](/*any previous overload*/) noexcept; //3
}
constexpr auto welford_average
tuple_callable computing the arithmetic mean of its arguments with the Welford algorithm,...
Definition welford_average.hpp:134
constexpr auto widen
Computes the result in the upgraded element type.
Definition core.hpp:106
EVE Main Namespace.
Definition abi.hpp:19

Parameters

  • xs...:the parameters can be a mix of floating values and previous results of calls to welford_average

Return value

  1. A struct containing The value of the arithmetic mean and the number of elements on which the mean was calculated is returned.

    This struct is convertible to the average floating value. and possess two fields average and count.

  2. The computation on the tuple elements
  3. The computation and result use the upgraded data type if available
Note
The Welford algorithm does not provides as much option as the average function, but is a quite stable algorithm that have the advantage to allow splitting the computation of the average in multiple calls. For instance: the call with two tuples:
  wavg = welford_average(kumi::cat(xs, ys))
is equivalent to the sequence:
  wxs = welford_average(xs); wys = welford_average(xs); wavg = welford_average(wxs, wys);
But the first two instructions can easily be executed in parallel.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
#include <tts/tts.hpp>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{2.0, 3.0, -1.0, -2.0, -3.0, -4.0, 18.0, 32.0};
using t_t = decltype(wf0);
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
auto ma = eve::welford_average(wf0, 2*wf0, 3*wf0);
auto mb = eve::welford_average(wf1, wf0);
auto mab= eve::average(wf0, 2*wf0, 3*wf0, wf1, wf0);
auto wmab = eve::welford_average(ma, mb);
std::cout << "ma = welford_average(wf0, 2*wf0, 3*wf0) = " << t_t(ma) << std::endl;
std::cout << "mb = welford_average(wf1, wf0) = " << t_t(mb) << std::endl;
std::cout << "eve::average(wf0, 2*wf0, 3*wf0, wf1, wf0) = " << mab << std::endl;
std::cout << "eve::welford_average(ma, mb) = " << t_t(wmab) << std::endl;
}
constexpr auto average
tuple_callable computing the arithmetic mean of its arguments.
Definition average.hpp:131
Wrapper for SIMD registers.
Definition wide.hpp:94