General Utility Library for C++14  2.11
Classes | Typedefs | Functions | Variables
gul14/statistics.h

Detailed Description

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_
 

Function Documentation

◆ accumulate() [1/2]

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.

This is similar to std::accumulate, but

  • works on a whole container,
  • accesses the container elements through an accessor function,
  • applies the binary operator op to a running sum and each element value,
  • the sum's type is in the first template parameter, and
  • the initial value of the sum is its default constructed value.
Parameters
containerContainer of the elements to examine
opBinary operator to aggregate two values into one value
accessorHelper function to access the numeric value of one container element
Returns
the aggregate value.
Template Parameters
ResultTType of the result value / accumulator
ContainerTType of the container to examine
ElementTType of an element in the container, i.e. ContainerT::value_type
AccessorType of the accessor function
DataTType returned by the accessor, i.e. numeric value of ElementT
See also
accumulate(IteratorT const&, IteratorT const&, OpClosure, Accessor) accepts two iterators instead of a container.

References gul14::accumulate().

◆ accumulate() [2/2]

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.

Parameters
beginIterator to first elements to examine in the container
endIterator past the last element to examine in the container
opBinary operator to aggregate two values into one value
accessorHelper function to access the numeric value of one container element
See also
accumulate(ContainerT const&, OpClosure, Accessor) accepts a container instead of iterators.

Referenced by gul14::accumulate(), gul14::maximum(), gul14::mean(), gul14::min_max(), gul14::minimum(), gul14::rms(), and gul14::standard_deviation().

◆ ElementAccessor()

template<typename ElementT >
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.

Template Parameters
ElementTType of the elements in the container
Returns
Pointer to accessor function

◆ maximum() [1/2]

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.

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.

Parameters
containerContainer of the elements to examine
accessorHelper function to access the numeric value of one container element.
Returns
the maximum value.
Template Parameters
ContainerTType of the container to examine
ElementTType of an element in the container, i.e. ContainerT::value_type
AccessorType of the accessor function
DataTType returned by the accessor, i.e. numeric value of ElementT
See also
maximum(IteratorT const&, IteratorT const&, Accessor) accepts two iterators instead of a container.
minimum() returns the minimum value, min_max() returns both the minimum and the maximum.
Since
GUL version 2.2

References gul14::accumulate().

Referenced by gul14::within_orders().

◆ maximum() [2/2]

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.

Parameters
beginIterator to first elements to examine in the container
endIterator past the last element to examine in the container
accessorHelper function to access the numeric value of one container element
See also
max(ContainerT const&, Accessor) accepts a container instead of iterators.

◆ mean() [1/2]

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.

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

Parameters
containerContainer of the elements to examine
accessorHelper function to access the numeric value of one container element
Returns
the arithmetic mean value.
Template Parameters
ResultTType 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)
ContainerTType of the container to examine
ElementTType of an element in the container, i.e. ContainerT::value_type
AccessorType of the accessor function
DataTType returned by the accessor, i.e. numeric value of ElementT
See also
mean(IteratorT const&, IteratorT const&, Accessor) accepts two iterators instead of a container.

References gul14::accumulate().

◆ mean() [2/2]

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.

Parameters
beginIterator to first elements to examine in the container
endIterator past the last element to examine in the container
accessorHelper function to access the numeric value of one container element
See also
mean(ContainerT const&, Accessor) accepts a container instead of iterators.

Referenced by gul14::remove_outliers().

◆ median() [1/2]

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.

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.

Parameters
containerContainer of the elements to examine
accessorHelper function to access the numeric value of one container element
Returns
the median value.
Template Parameters
ResultTType of the result value
ContainerTType of the container to examine
ElementTType of an element in the container, i.e. ContainerT::value_type
AccessorType of the accessor function
DataTType returned by the accessor, i.e. numeric value of ElementT
See also
median(IteratorT const&, IteratorT const&, Accessor) accepts two iterators instead of a container.

◆ median() [2/2]

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.

Parameters
beginIterator to first elements to examine in the container
endIterator past the last element to examine in the container
accessorHelper function to access the numeric value of one container element
See also
median(ContainerT const&, Accessor) accepts a container instead of iterators.

◆ min_max() [1/2]

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.

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<=(), andoperator>=()`. 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):

std::minmax_element(std::transform(mycontainer, accessor))

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.

Parameters
containerContainer of the elements to examine
accessorHelper function to access the numeric value of one container element
Returns
the minimum and maximum values stored in a MinMax<DataT> object.
Template Parameters
ContainerTType of the container to examine
ElementTType of an element in the container, i.e. ContainerT::value_type
AccessorType of the accessor function
DataTType returned by the accessor, i.e. numeric value of ElementT
See also
min_max(IteratorT const&, IteratorT const&, Accessor) accepts two iterators instead of a container.
minimum() returns only the minimum value, maximum() only the maximum value.

References gul14::accumulate().

◆ min_max() [2/2]

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.

Parameters
beginIterator to first elements to examine in the container
endIterator past the last element to examine in the container
accessorHelper function to access the numeric value of one container element
See also
min_max(ContainerT const&, Accessor) accepts a container instead of iterators.

◆ minimum() [1/2]

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.

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.

Parameters
containerContainer of the elements to examine
accessorHelper function to access the numeric value of one container element.
Returns
the minimum value.
Template Parameters
ContainerTType of the container to examine
ElementTType of an element in the container, i.e. ContainerT::value_type
AccessorType of the accessor function
DataTType returned by the accessor, i.e. numeric value of ElementT
See also
minimum(IteratorT const&, IteratorT const&, Accessor) accepts two iterators instead of a container.
maximum() returns the maximum value, min_max() returns both the minimum and the maximum.
Since
GUL version 2.2

References gul14::accumulate().

◆ minimum() [2/2]

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.

Parameters
beginIterator to first elements to examine in the container
endIterator past the last element to examine in the container
accessorHelper function to access the numeric value of one container element
See also
max(ContainerT const&, Accessor) accepts a container instead of iterators.

◆ operator DataT()

template<typename DataT , typename = std::enable_if_t<std::is_floating_point<DataT>::value>>
gul14::StandardDeviationMean< DataT, typename >::operator DataT ( ) const
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:

auto sdm = StandardDeviationMean<float>{ 3.0, 4.0 };
long double sigma = sdm; // implicit conversion from float to long double
auto sigma() const noexcept -> DataT
Get the standard deviation value.
Definition: statistics.h:126

References gul14::StandardDeviationMean< DataT, typename >::sigma_.

◆ remove_outliers() [1/3]

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.

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.

Parameters
contContainer of the elements to examine
outliersHow many outliers shall be removed
accessorHelper function to access the numeric value of one container element
Returns
the container passed in as cont after removal of outliers.
Template Parameters
ContainerTType of the container to examine
ElementTType of an element in the container, i.e. ContainerT::value_type
AccessorType of the accessor function
DataTType returned by the accessor, i.e. numeric value of ElementT

References gul14::abs(), and gul14::mean().

◆ remove_outliers() [2/3]

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.

A copy of the original container without the outlier elements is returned.

References gul14::remove_outliers().

◆ remove_outliers() [3/3]

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.

A copy of the original container with the outerlier elements removed is returned.

Parameters
beginIterator to first elements to examine in the container
endIterator past the last element to examine in the container
outliersHow many outliers shall be removed
accessorHelper function to access the numeric value of one container element

Referenced by gul14::remove_outliers().

◆ rms() [1/2]

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.

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)

Parameters
containerContainer of the elements to examine
accessorHelper function to access the numeric value of one container element
Returns
the rms value.
Template Parameters
ResultTType of the result value
ContainerTType of the container to examine
ElementTType of an element in the container, i.e. ContainerT::value_type
AccessorType of the accessor function
DataTType returned by the accessor, i.e. numeric value of ElementT
See also
rms(IteratorT const&, IteratorT const&, Accessor) accepts two iterators instead of a container.

References gul14::accumulate().

◆ rms() [2/2]

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.

Parameters
beginIterator to first elements to examine in the container
endIterator past the last element to examine in the container
accessorHelper function to access the numeric value of one container element
See also
rms(ContainerT const&, Accessor) accepts a container instead of iterators.

◆ standard_deviation() [1/2]

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.

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:

const StandardDeviationMean std_and_mean = standard_deviation(something);
const double std = std_and_mean.sigma();
const double mean = std_and_mean.mean();
// The cast operator is for people that want to ignore the complicated stuff like this
const double std = standard_deviation(something);
const float std = standard_deviation(something); // implicit conversions possible
// Structured binding (C++17)
const auto [std, mean] = standard_deviation(something);
auto mean(ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT
Calculate the arithmetic mean value of all elements in a container.
Definition: statistics.h:167
auto standard_deviation(ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> StandardDeviationMean< ResultT >
Calculate the standard deviation of all elements in a container.
Definition: statistics.h:552

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.

Parameters
containerContainer of the elements to examine
accessorHelper function to access the numeric value of one container element
Returns
the standard deviation and mean values as a StandardDeviationMean object.
Template Parameters
ResultTType of the result value
ContainerTType of the container to examine
ElementTType of an element in the container, i.e. ContainerT::value_type
AccessorType of the accessor function
DataTType returned by the accessor, i.e. numeric value of ElementT
See also
standard_deviation(IteratorT const&, IteratorT const&, Accessor) accepts two iterators instead of a container.

References gul14::accumulate().

◆ standard_deviation() [2/2]

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.

Parameters
beginIterator to first elements to examine in the container
endIterator past the last element to examine in the container
accessorHelper function to access the numeric value of one container element
See also
standard_deviation(ContainerT const&, Accessor) accepts a container instead of iterators.