E.V.E
v2023.02.15
Loading...
Searching...
No Matches
◆
variance
eve::variance = functor<variance_t>
inline
constexpr
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
}
eve::conditional_expr
Specifies that a type is a Conditional Expression.
Definition
conditional.hpp:28
eve::floating_value
The concept floating_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition
value.hpp:116
eve::logical_value
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition
value.hpp:134
eve::variance
constexpr auto variance
tuple_callable computing the variance of its arguments.
Definition
variance.hpp:108
eve::translate_t
typename decltype(detail::as_translated_type(as< T >{}))::type translate_t
Returns the final translated type of T.
Definition
translation.hpp:107
eve
EVE Main Namespace.
Definition
abi.hpp:19
Parameters
xs...
:
floating value
arguments or tuple of floating values.
c
:
Conditional expression
masking the operation.
m
:
Logical value
masking the operation.
Return value
The value of the variance of the arguments is returned.
the computation of the variance of its arguments.
the computation is made on the tuple values.
The operation is performed conditionnaly
No provision is made to avoid inaccuracies.
The variance is computed in the double sized element type (if available).
Compensated algorithm for better precision.
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
Wikipedia Variance
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"
;
auto
eps_2
=
eve::eps
(
eve::as<float>
())/2;
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"
;
}
eve::eps
constexpr auto eps
Computes a constant to the machine epsilon.
Definition
eps.hpp:74
eve::smallestposval
constexpr auto smallestposval
Computes the smallest normal positive value.
Definition
smallestposval.hpp:71
eve::as
Lightweight type-wrapper.
Definition
as.hpp:29
eve::ignore_last
Conditional expression ignoring the k last lanes from a eve::simd_value.
Definition
conditional.hpp:320
eve::wide
Wrapper for SIMD registers.
Definition
wide.hpp:94
eve