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

◆ welford_covariance

eve::welford_covariance = functor<welford_covariance_t>
inlineconstexpr

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto welford_covariance(kumi::tuple xs, kumi::tuple ys) noexcept; // 1
constexpr auto welford_covariance(auto wcs...) noexcept; // 2
// Semantic options
constexpr auto welford_covariance[widen] (/*any of the above overloads*/) noexcept; // 4
constexpr auto welford_covariance[unbiased](/*any of the above overloads*/) noexcept; // 5
}
constexpr auto welford_covariance
elementwise_callable object computing the elementwise welford_covariance product of the vector of the...
Definition welford_covariance.hpp:138
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

  • xs, ys : tuple of values.
  • wcs : arguments or tuple of them. The arguments must all be results of previous welford_covariance calls, Return value
    1. A struct containing The value of the arithmetic means (averagex and averagey ), the centered cross moment of order 2 (mxy), the (sample) covariance value normalized by the number of elements involved (covariance) and the number of elements (count) involved is returned.
      This struct is convertible to the covariance floating value. and possesses four fields averagex, averagey, mxy and count and covariance,that can be output through an std:ostream.
    2. The parameters are composed in a unique covariance struct as if the covariance was computed on the whole original data set. Moreover if only one covariance result simd parameter is present, the the lanes individual corariance are grouped in an unique scalar covariance result, computed from all the datas of all the lanes.
    3. same as 3. on the tuple elements.
    4. the computation is done in the upgraded element type.
    5. with this option the normalisation is done by the number of elements involved, minus one.
Note
The Welford algorithm does not provides as much option as the `covariance` function, but is a quite stable algorithm that have the advantage to allow spliting the computation of the covariance in multiple calls. For instance: the call with four tuples:
  cwv = welford_corariance(kumi::cat(xs, ys), kumi::cat(ws, zs))
is equivalent to the sequence:
  cwxs = welford_covariance(xs, ws); cwys = welford_covariance(ys, zs)); cwv = welford_covariance(wxs, wys);
But the first two instructions can easily be executed in parallel.

Example

// revision 0
// revision 0
#include <eve/module/core.hpp>
#include "../../vec3.hpp"
#include <iostream>
#include <iomanip>
#include <tts/tts.hpp>
int main()
{
// scalar welford_covariance vec3<float>
vec3<float> a(1.0, 2.0, 3.0);
vec3<float> b(-3.0, -4.0, -6.0);
std::cout << "a " << a << std::endl;
std::cout << "b " << b << std::endl;
std::cout << "eve::welford_covariance[eve::unbiased](a, b) = "<< eve::welford_covariance[eve::unbiased](a, b) << std::endl;
std::cout << "eve::welford_covariance[eve::unbiased](a, a) = " << eve::welford_covariance[eve::unbiased](a, a) << std::endl;
std::cout << "eve::welford_covariance[eve::unbiased](b, a) = " << eve::welford_covariance[eve::unbiased](b, a) << std::endl;
std::cout << "eve::welford_covariance[eve::unbiased](b, b) = " << eve::welford_covariance[eve::unbiased](b, b) << std::endl;
// simd welford_covariance eve::wide<vec3<float>, eve::fixed<4>>;
auto wa = wv3_t(a, a, b, b);
auto wb = wv3_t(b, a, a, b);
std::cout << "wa " << wa << std::endl;
std::cout << "wb " << wb << std::endl;
std::cout << "eve::welford_covariance[eve::widen][eve::unbiased](wa, wb) = "<< eve::welford_covariance[eve::widen][eve::unbiased](wa, wb) << std::endl;
kumi::tuple x{4.0f, 3.0f, 2.0f, 1.0f};
kumi::tuple y{1.0f, 2.0f, 3.0f, 4.0f};
std::cout << eve::welford_covariance[eve::unbiased](x, x) << std::endl;
std::cout << eve::welford_covariance[eve::unbiased](x, y) << std::endl;
std::cout << eve::welford_covariance[eve::unbiased](y, x) << std::endl;
}