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

◆ covariance

eve::covariance = functor<covariance_t>
inlineconstexpr

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto covariance(kumi::non_empty_product_type xs, kumi::non_empty_product_type ys) noexcept; // 1
// Semantic options
constexpr auto covariance[kahan] (/*any of the above overloads*/) noexcept; // 2
constexpr auto covariance[unbiased](/*any of the above overloads*/) noexcept; // 3
constexpr auto covariance[widen] (/*any of the above overloads*/) noexcept; // 4
}
constexpr auto covariance
elementwise_callable object computing the elementwise covariance product of the vector of the first h...
Definition covariance.hpp:85
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 : tuples of floating value arguments.

Return value

  1. covariance product. \(\frac1N\sum_s (x_s-\bar{x_s})*(y_s-\bar{y_s})\). where N is the number of x_s (minus 1 if unbiased option is used).
  2. Uses a compensated kahan-like algorithm to compute the result more accurately
  3. see 1.
  4. Uses the upgraded type for computations and result
See also
`welford_covariance` for incremental or parallel covariance and averages computations.

Example

// revision 0
#include <eve/module/core.hpp>
#include "../../vec3.hpp"
#include <iostream>
#include <iomanip>
#include <tts/tts.hpp>
int main()
{
// scalar 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::covariance[eve::unbiased](a, b) = "<< eve::covariance[eve::unbiased](a, b) << std::endl;
std::cout << "eve::covariance[eve::unbiased](a, a) = " << eve::covariance[eve::unbiased](a, a) << std::endl;
std::cout << "eve::covariance[eve::unbiased](b, a) = " << eve::covariance[eve::unbiased](b, a) << std::endl;
std::cout << "eve::covariance[eve::unbiased](b, b) = " << eve::covariance[eve::unbiased](b, b) << std::endl;
// simd 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 << "eve::covariance[eve::widen][eve::unbiased](wa, wb) = "<< eve::covariance[eve::widen][eve::unbiased](wa, wb) << std::endl;
std::cout << "wa " << wa << std::endl;
std::cout << "wb " << 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::covariance[eve::unbiased](x, x) << std::endl;
std::cout << eve::covariance[eve::unbiased](x, y) << std::endl;
std::cout << eve::covariance[eve::unbiased](y, x) << std::endl;
}