General Utility Library for C++14
2.12
|
Statistical utility functions and classes.
Classes | |
struct | gul14::MinMax< DataT, typename, typename > |
Object that is designed to holds two values: minimum and maximum of something. More... | |
class | gul14::StandardDeviationMean< DataT, typename > |
A struct holding a standard deviation and a mean value. More... | |
Typedefs | |
using | gul14::statistics_result_type = double |
Type used to return statistic properties. | |
using | gul14::ContainerView< IteratorT >::value_type = std::decay_t< decltype(*begin_)> |
Functions | |
template<typename ElementT > | |
auto | gul14::ElementAccessor () |
Return a mock element accessor for containers. More... | |
gul14::StandardDeviationMean< DataT, typename >::operator DataT () const noexcept | |
Cast to DataT results in standard deviation value. More... | |
auto | gul14::StandardDeviationMean< DataT, typename >::sigma () const noexcept -> DataT |
Get the standard deviation value. | |
auto | gul14::StandardDeviationMean< DataT, typename >::mean () const noexcept -> DataT |
Get the arithmetic mean value. | |
template<typename ResultT = statistics_result_type, typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | gul14::mean (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
Calculate the arithmetic mean value of all elements in a container. More... | |
template<typename ResultT = statistics_result_type, typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | gul14::rms (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
Calculate the root mean square of all elements in a container. More... | |
template<typename ResultT = statistics_result_type, typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | gul14::median (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
Find the median of all elements in a container. More... | |
template<typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | gul14::maximum (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> DataT |
Return the maximum element value in a container. More... | |
template<typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | gul14::minimum (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> DataT |
Return the minimum element value in a container. More... | |
template<typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | gul14::min_max (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> MinMax< DataT > |
Find the minimum and maximum element values in a container. More... | |
template<typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | gul14::remove_outliers (ContainerT &&cont, std::size_t outliers, Accessor accessor=ElementAccessor< ElementT >()) -> ContainerT & |
Remove elements that are far away from other elements. More... | |
template<typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | gul14::remove_outliers (ContainerT const &cont, std::size_t outliers, Accessor accessor=ElementAccessor< ElementT >()) -> std::vector< ElementT > |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The original container is not modified. More... | |
template<typename ResultT = statistics_result_type, typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | gul14::standard_deviation (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> StandardDeviationMean< ResultT > |
Calculate the standard deviation of all elements in a container. More... | |
template<typename ResultT = statistics_result_type, typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename OpClosure , typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | gul14::accumulate (ContainerT const &container, OpClosure op, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
Calculate some aggregate value from all elements of a container. More... | |
template<typename ResultT = statistics_result_type, typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | gul14::mean (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename ResultT = statistics_result_type, typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | gul14::rms (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename ResultT = statistics_result_type, typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | gul14::median (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | gul14::maximum (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> DataT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | gul14::minimum (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> DataT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | gul14::min_max (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> MinMax< DataT > |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | gul14::remove_outliers (IteratorT const &begin, IteratorT const &end, std::size_t outliers, Accessor accessor=ElementAccessor< ElementT >()) -> std::vector< ElementT > |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The original container is not modified. More... | |
template<typename ResultT = statistics_result_type, typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | gul14::standard_deviation (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> StandardDeviationMean< ResultT > |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename ResultT = statistics_result_type, typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename OpClosure > | |
auto | gul14::accumulate (IteratorT const &begin, IteratorT const &end, OpClosure op, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
Variables | |
DataT | gul14::MinMax< DataT, typename, typename >::min { std::numeric_limits<DataT>::max() } |
Minimum value. | |
DataT | gul14::MinMax< DataT, typename, typename >::max { std::numeric_limits<DataT>::lowest() } |
Maximum value. | |
DataT | gul14::MinMax< DataT, std::enable_if_t< std::is_floating_point< DataT >::value > >::min { NAN } |
DataT | gul14::MinMax< DataT, std::enable_if_t< std::is_floating_point< DataT >::value > >::max { NAN } |
DataT | gul14::StandardDeviationMean< DataT, typename >::sigma_ { NAN } |
The standard deviation (sigma) value. | |
DataT | gul14::StandardDeviationMean< DataT, typename >::mean_ { NAN } |
The mean value. | |
IteratorT const & gul14::ContainerView< IteratorT >::begin_ | |
IteratorT const & gul14::ContainerView< IteratorT >::end_ | |
auto gul14::accumulate | ( | ContainerT const & | container, |
OpClosure | op, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
Calculate some aggregate value from all elements of a container.
This is similar to std::accumulate, but
op
to a running sum and each element value,container | Container of the elements to examine |
op | Binary operator to aggregate two values into one value |
accessor | Helper function to access the numeric value of one container element |
ResultT | Type of the result value / accumulator |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References gul14::accumulate().
auto gul14::accumulate | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
OpClosure | op, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
op | Binary operator to aggregate two values into one value |
accessor | Helper function to access the numeric value of one container element |
Referenced by gul14::accumulate(), gul14::maximum(), gul14::mean(), gul14::min_max(), gul14::minimum(), gul14::rms(), and gul14::standard_deviation().
auto gul14::ElementAccessor | ( | ) |
Return a mock element accessor for containers.
All functions in statistics.h access the elements of the containers they work on through accessor functions. If the container is simple, i.e. contains just the types we want to work on (like double of std::vector<double>) we can automate the generation of the accessor function, so that the user does not need to specify it.
ElementT | Type of the elements in the container |
auto gul14::maximum | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> DataT |
Return the maximum element value in a container.
The value of each element is determined through the accessor function. The maximum value is returned. Its type (DataT, the return type of the accessor) must provide operator==()
and operator<=()
. If DataT supports not-a-number (NaN) values, such values are ignored. If the container is empty, the return value is NaN (if supported) or std::numeric_limits<DataT>::lowest()
.
Hint: If looking for an iterator to the maximum element instead of its value, use std::max_element()
from the STL algorithm collection.
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element. |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References gul14::accumulate().
Referenced by gul14::within_orders().
auto gul14::maximum | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> DataT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
auto gul14::mean | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
Calculate the arithmetic mean value of all elements in a container.
The mean value is calculated by dividing the sum of all elements by the number of elements: mean -> sum 0..n-1 (element i) / n
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element |
ResultT | Type of the result (this is also the type used for holding the sum of all elements and for the division by the number of elements, so make sure it can hold numbers that are big enough) |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References gul14::accumulate().
auto gul14::mean | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
Referenced by gul14::remove_outliers().
auto gul14::median | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
Find the median of all elements in a container.
The median element is the element that has an equal number of elements higher and lower in value. If the container has an even number of elements there can be no 'middle' element. In this case the two 'middlemost' elements are taken and the arithmetic mean of the two is returned.
Because all elements need to be sorted, the function works with a temporary copy of the original container.
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element |
ResultT | Type of the result value |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
auto gul14::median | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
auto gul14::min_max | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> MinMax<DataT> |
Find the minimum and maximum element values in a container.
The value of each element is determined through the accessor function. The minimum and the maximum of these values are returned. Their type (DataT, the return type of the accessor) must provide operator==(),
operator<=(), and
operator>=()`. If DataT supports not-a-number (NaN) values, such values are ignored. If the container is empty, the return values are NaN (if supported) or std::numeric_limits<DataT>::max()
for the minimum and std::numeric_limits<DataT>::lowest()
for the maximum.
This behaves like (symbolic code):
without constructing a temporary container and without the ownership problems that would arise from minmax_element usage on a temporary container.
Hint: If looking for iterators to the minimum and maximum element instead of their values, use std::minmax_element()
from the STL algorithm collection.
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References gul14::accumulate().
auto gul14::min_max | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> MinMax<DataT> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
auto gul14::minimum | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> DataT |
Return the minimum element value in a container.
The value of each element is determined through the accessor function. The minimum value is returned. Its type (DataT, the return type of the accessor) must provide operator==()
and operator>=()
. If DataT supports not-a-number (NaN) values, such values are ignored. If the container is empty, the return value is NaN (if supported) or std::numeric_limits<DataT>::max()
.
Hint: If looking for an iterator to the minimum element instead of its value, use std::min_element()
from the STL algorithm collection.
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element. |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References gul14::accumulate().
auto gul14::minimum | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> DataT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
|
inlinenoexcept |
Cast to DataT results in standard deviation value.
The conversion operator is not explicit, so any implicit conversion from DataT to the desired type is also conducted.
For example the following works:
References gul14::StandardDeviationMean< DataT, typename >::sigma_.
auto gul14::remove_outliers | ( | ContainerT && | cont, |
std::size_t | outliers, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ContainerT& |
Remove elements that are far away from other elements.
The element whose value differs the most from the arithmetic mean of all elements is removed. This process is repeated if more than one outlier is to be removed; specifically, the mean is recalculated from the remaining elements.
The original container is modified. The container needs to be modifiable and have the erase()
member function.
cont | Container of the elements to examine |
outliers | How many outliers shall be removed |
accessor | Helper function to access the numeric value of one container element |
cont
after removal of outliers.ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References gul14::abs(), and gul14::mean().
auto gul14::remove_outliers | ( | ContainerT const & | cont, |
std::size_t | outliers, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> std::vector<ElementT> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The original container is not modified.
A copy of the original container without the outlier elements is returned.
References gul14::remove_outliers().
auto gul14::remove_outliers | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
std::size_t | outliers, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> std::vector<ElementT> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The original container is not modified.
A copy of the original container with the outerlier elements removed is returned.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
outliers | How many outliers shall be removed |
accessor | Helper function to access the numeric value of one container element |
Referenced by gul14::remove_outliers().
auto gul14::rms | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
Calculate the root mean square of all elements in a container.
The rms value is calculated as the square root of the sum of all squared elements divided by the number of elements: rms -> sqrt (sum 0..n-1 (element i * element i) / n)
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element |
ResultT | Type of the result value |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References gul14::accumulate().
auto gul14::rms | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
auto gul14::standard_deviation | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> StandardDeviationMean<ResultT> |
Calculate the standard deviation of all elements in a container.
The corrected sample standard deviation is calculated: standard_deviation -> sqrt (sum 0..n-1 ((element i - mean) * (element i - mean)) / (n - 1))
The returned StandardDeviationMean object can be used like this:
If the container is empty, not-a-number is returned for both the standard deviation and the mean value. If it contains only a single element, not-a-number is returned for the standard deviation and the mean value is the value of the element.
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element |
ResultT | Type of the result value |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References gul14::accumulate().
auto gul14::standard_deviation | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> StandardDeviationMean<ResultT> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |