Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Statistics.h File Reference
#include "Stroika/Foundation/StroikaPreComp.h"
#include "Stroika/Foundation/Common/Common.h"
#include "Statistics.inl"

Go to the source code of this file.

Classes

struct  Stroika::Foundation::Math::CommonStatistics< T >
 

Namespaces

namespace  Stroika::Foundation
 

Functions

template<typename RESULT_TYPE , input_iterator ITERATOR_OF_T, sentinel_for< ITERATOR_OF_T > ITERATOR_OF_T2>
RESULT_TYPE Stroika::Foundation::Math::Mean (const ITERATOR_OF_T &start, ITERATOR_OF_T2 &&end)
 Mean (average) of a collection of numbers computed.
 
template<typename RESULT_TYPE , input_iterator ITERATOR_OF_T, sentinel_for< ITERATOR_OF_T > ITERATOR_OF_T2, Common::IInOrderComparer< RESULT_TYPE > INORDER_COMPARE_FUNCTION = less<RESULT_TYPE>>
RESULT_TYPE Stroika::Foundation::Math::Median (const ITERATOR_OF_T &start, ITERATOR_OF_T2 &&end, INORDER_COMPARE_FUNCTION &&compare={})
 Median of a collection of numbers computed.
 
template<typename RESULT_TYPE , input_iterator ITERATOR_OF_T, sentinel_for< ITERATOR_OF_T > ITERATOR_OF_T2>
RESULT_TYPE Stroika::Foundation::Math::StandardDeviation (const ITERATOR_OF_T &start, ITERATOR_OF_T2 &&end)
 Alias: sd, standard-deviation, stddev.
 
template<typename T , input_iterator ITERATOR_OF_T, sentinel_for< ITERATOR_OF_T > ITERATOR_OF_T2>
CommonStatistics< T > Stroika::Foundation::Math::ComputeCommonStatistics (const ITERATOR_OF_T &start, ITERATOR_OF_T2 &&end)
 handy aggregation of several common random-variable statistics/measurements.
 

Detailed Description

Note
Code-Status: Alpha

TODO:

Use std::nth_element from <algorithm> which is O(N): nth_element(a, a + size / 2, a + size); median = a[size/2];

Definition in file Math/Statistics.h.

Function Documentation

◆ Mean()

template<typename RESULT_TYPE , input_iterator ITERATOR_OF_T, sentinel_for< ITERATOR_OF_T > ITERATOR_OF_T2>
RESULT_TYPE Stroika::Foundation::Math::Mean ( const ITERATOR_OF_T &  start,
ITERATOR_OF_T2 &&  end 
)

Mean (average) of a collection of numbers computed.

Precondition
not empty (or start != end)
Example Usage:
EXPECT_EQ (Mean<double> (vector<int>{1, 3, 5}), 3);
Note
O(N) time complexity

Definition at line 19 of file Math/Statistics.inl.

◆ Median()

template<typename RESULT_TYPE , input_iterator ITERATOR_OF_T, sentinel_for< ITERATOR_OF_T > ITERATOR_OF_T2, Common::IInOrderComparer< RESULT_TYPE > INORDER_COMPARE_FUNCTION = less<RESULT_TYPE>>
RESULT_TYPE Stroika::Foundation::Math::Median ( const ITERATOR_OF_T &  start,
ITERATOR_OF_T2 &&  end,
INORDER_COMPARE_FUNCTION &&  compare = {} 
)

Median of a collection of numbers computed.

First template requires explicit RESULT_TYPE argument. Second and third infer it from the iterator/container arguments.

Precondition
not empty
Note
O(N) time complexity
Example Usage:
EXPECT_EQ (Median (vector<int>{1, 3, 5}), 3);
Note
template arguments changed significantly in Stroika v3.0d10

Definition at line 49 of file Math/Statistics.inl.

◆ StandardDeviation()

template<typename RESULT_TYPE , input_iterator ITERATOR_OF_T, sentinel_for< ITERATOR_OF_T > ITERATOR_OF_T2>
RESULT_TYPE Stroika::Foundation::Math::StandardDeviation ( const ITERATOR_OF_T &  start,
ITERATOR_OF_T2 &&  end 
)

Alias: sd, standard-deviation, stddev.

Precondition
size of container >= 1

sqrt (sum(mean-di))/(n-1) - 'Bessel's correction'

Example Usage:
EXPECT_TRUE (Math::NearlyEquals (Math::StandardDeviation (vector<double> ({5, 3, 19, 1})), 8.164966, .0001));
See also
https://en.wikipedia.org/wiki/Standard_deviation

Definition at line 90 of file Math/Statistics.inl.