Ocean
Ocean::VarianceT< T > Class Template Reference

This class allows to determine the variance in a given data set. More...

Public Member Functions

 VarianceT ()=default
 Creates a new variance object. More...
 
 VarianceT (const T *values, const size_t size)
 Creates a new variance object with several values. More...
 
void add (const T &value)
 Adds a new value. More...
 
void add (const size_t size, const T &value)
 Adds the same value several times. More...
 
void add (const T *values, const size_t size)
 Adds several values. More...
 
void remove (const T &value)
 Removes a previously added value. More...
 
variance () const
 Returns the variance of the data set. More...
 
deviation () const
 Returns the deviation of the data set. More...
 
average () const
 Returns the average of the data set. More...
 
size_t size () const
 Returns the size of the data set. More...
 
 operator bool () const
 Returns whether the data set holds at least one value. More...
 
double variance () const
 Specialization for double elements. More...
 
float variance () const
 Specialization for double elements. More...
 

Private Attributes

sum_ = T(0)
 Stores the data sum. More...
 
squaredSum_ = T(0)
 Stores the squared data sum. More...
 
size_t size_ = 0
 Size of the data set. More...
 

Detailed Description

template<typename T>
class Ocean::VarianceT< T >

This class allows to determine the variance in a given data set.

Template Parameters
TData type of the variance data
See also
Variance, VarianceF, VarianceD.

Constructor & Destructor Documentation

◆ VarianceT() [1/2]

template<typename T >
Ocean::VarianceT< T >::VarianceT ( )
default

Creates a new variance object.

◆ VarianceT() [2/2]

template<typename T >
Ocean::VarianceT< T >::VarianceT ( const T *  values,
const size_t  size 
)
inline

Creates a new variance object with several values.

Parameters
valuesThe values to be used, must be valid if size > 0
sizeThe number of values to be used, with range [0, infinity)

Member Function Documentation

◆ add() [1/3]

template<typename T >
void Ocean::VarianceT< T >::add ( const size_t  size,
const T &  value 
)
inline

Adds the same value several times.

Parameters
sizeThe number of value to add, with range [1, infinity)
valueThe value to be added

◆ add() [2/3]

template<typename T >
void Ocean::VarianceT< T >::add ( const T &  value)
inline

Adds a new value.

Parameters
valueThe value to be added

◆ add() [3/3]

template<typename T >
void Ocean::VarianceT< T >::add ( const T *  values,
const size_t  size 
)
inline

Adds several values.

Parameters
valuesThe values to be added, must be valid if size > 0
sizeThe number of values to be added, with range [0, infinity)

◆ average()

template<typename T >
T Ocean::VarianceT< T >::average
inline

Returns the average of the data set.

Returns
Data set average

◆ deviation()

template<typename T >
T Ocean::VarianceT< T >::deviation
inline

Returns the deviation of the data set.

The deviation is determined by the square root of the variance.

Returns
Data set deviation

◆ operator bool()

template<typename T >
Ocean::VarianceT< T >::operator bool
inlineexplicit

Returns whether the data set holds at least one value.

Returns
True, if so

◆ remove()

template<typename T >
void Ocean::VarianceT< T >::remove ( const T &  value)
inline

Removes a previously added value.

Parameters
valueThe value to be removed, must have been added before
See also
add().

◆ size()

template<typename T >
size_t Ocean::VarianceT< T >::size
inline

Returns the size of the data set.

Returns
Data set size

◆ variance() [1/3]

template<typename T >
T Ocean::VarianceT< T >::variance
inline

Returns the variance of the data set.

Returns
Data set variance

E[X^2] - (E[x])^2 = mean(X^2) - mean(X)^2 = sum(X^2) / size - (sum(X) / size)^2 = sum(X^2) * size / size^2 - sum(X)^2 / size^2 = (sum(X^2) * size - sum(X)^2) / size^2

◆ variance() [2/3]

double Ocean::VarianceT< double >::variance ( ) const
inline

Specialization for double elements.

Returns
Resulting variance

E[X^2] - (E[x])^2

◆ variance() [3/3]

float Ocean::VarianceT< float >::variance ( ) const
inline

Specialization for double elements.

Returns
Resulting variance

E[X^2] - (E[x])^2

Field Documentation

◆ size_

template<typename T >
size_t Ocean::VarianceT< T >::size_ = 0
private

Size of the data set.

◆ squaredSum_

template<typename T >
T Ocean::VarianceT< T >::squaredSum_ = T(0)
private

Stores the squared data sum.

◆ sum_

template<typename T >
T Ocean::VarianceT< T >::sum_ = T(0)
private

Stores the data sum.


The documentation for this class was generated from the following file: