Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::Math Class Reference

#include <Math.h>

List of all members.


Detailed Description

A template class that holds some useful functions for calculating mathematic quantities.

Note that these operations are supposed to work with elementary types only.


Public Types

enum  VarianceType { VAR_BIASED = 0, VAR_UNBIASED = 1 }
 Possible types of variance. More...


Static Public Methods

template<class T> double variance (const List< T > &lst, VarianceType type=VAR_UNBIASED) throw (MathException&)
 Calculate the variance of all values in a list.

template<class T> double stdev (const List< T > &lst) throw (MathException&)
 Calculate the standard deviation of all values in a list.

template<class T> double mean (const List< T > &lst) throw (MathException&)
 Calculate the mean of all values in a list.

template<class T> T median (const List< T > &lst) throw (MathException&)
 Find the median in a list of values.

template<class T> void meanAndVariance (const List< T > &mat, double &mean, double &variance, VarianceType type=VAR_UNBIASED) throw (MathException&)
 Calculate the mean and variance for the values in a list.

template<class T> void minAndMax (const Matrix< T > &lst, T &min, T &max) throw (MathException&)
 Finds the min and max values from a matrix.

double factorial (unsigned int x)
 Calculate the factorial of x (i.e.

template<class T> T sum (const List< T > &lst) throw (MathException&)
 Calculate the sum of all values in a list.

template<class T> T max (const List< T > &lst) throw (MathException&)
 Finds the maximum value of the list.

template<class T> T min (const List< T > &lst) throw (MathException&)
 Finds the minimum value of the list.

template<class T> void minAndMax (const List< T > &lst, T &min, T &max) throw (MathException&)
 Finds the min and max values from a list.

template<class T> int numberOf (const List< T > &lst, const T parameter) throw (MathException&)
 Find the number of given parameters from list.

template<class T> double entropy (const List< T > &lst) throw (MathException&)
 Calculate the entropy of the elements in a list.

template<class T> double variance (const Matrix< T > &mat, VarianceType type=VAR_UNBIASED) throw (MathException&)
 Calculate the variance of all values in a matrix.

template<class T> Matrix< double > covariance (const Matrix< T > &mat) throw (MathException&,MatrixException&)
 Calculate a covariance matrix.

template<class T> double stdev (const Matrix< T > &mat) throw (MathException&)
 Calculate the standard deviation of all values in a matrix.

template<class T> double mean (const Matrix< T > &mat) throw (MathException&)
 Calculate the mean of all values in a matrix.

template<class T> T median (const Matrix< T > &mat) throw (MathException&)
 Find the median in a matrix.

template<class T> void meanAndVariance (const Matrix< T > &mat, double &mean, double &variance, VarianceType type=VAR_UNBIASED) throw (MathException&)
 Calculate mean and variance for all entries in a matrix.

template<class T> T sum (const Matrix< T > &mat) throw (MathException&)
 Calculate the sum of all values in a matrix.

template<class T> T max (const Matrix< T > &mat) throw (MathException&)
 Find the maximum value in a matrix.

template<class T> T min (const Matrix< T > &mat) throw (MathException&)
 Find the minimum value in a matrix.

template<class T> int numberOf (const Matrix< T > &mat, const T &parameter) throw (MathException&)
 Find the number of given parameters from the matrix.

template<class T> double entropy (const Matrix< T > &mat) throw (MathException&)
 Calculate the entropy of the elements in a matrix.

List< List< int > > findCombinations (int numberOfClasses, int whichCombinations) throw (MathException&)
 Calculate the combination given in whichCombinations from classes given in numberOfClasses (whis is the MAX index for class.

List< List< int > > findAllCombinations (int numberOfClasses) throw (MathException&)
 Calculate all combinations of given number of classes.


Member Enumeration Documentation

enum util::Math::VarianceType
 

Possible types of variance.

When calculating variance in VAR_BIASED mode, the result is 1/N*sumi=1..N(xi-ux)2. In VAR_UNBIASED mode the divisor 1/N is changed to 1/(N-1) to obtain an unbiased estimate of the sample variance. Stddev uses VAR_UNBIASED by default.


Member Function Documentation

template<class T>
Matrix< double > util::Math::covariance const Matrix< T > &    mat throw (MathException&,MatrixException&) [static]
 

Calculate a covariance matrix.

In the input matrix, each row is an observation and each column a variable. The diagonal of the covariance matrix contains variances for each variable. The resulting matrix will be of size NxN where N is the number of variables (dimensions) in each observation vector.

double util::Math::factorial unsigned int    x [static]
 

Calculate the factorial of x (i.e.

x!). For large values of x the returned value may not be quite accurate.

List< List< int > > util::Math::findAllCombinations int    numberOfClasses throw (MathException&) [static]
 

Calculate all combinations of given number of classes.

Parameters:
numberOfClasses  the max index of classes

List< List< int > > util::Math::findCombinations int    numberOfClasses,
int    whichCombinations
throw (MathException&) [static]
 

Calculate the combination given in whichCombinations from classes given in numberOfClasses (whis is the MAX index for class.

fl. if you have classes 0,1,2 give number 2 and function calculates combinations).

Parameters:
numberOfClasses  the max index of classes
whichCombinations  the combination wanted

template<class T>
double util::Math::variance const List< T > &    lst,
VarianceType    type = VAR_UNBIASED
throw (MathException&) [static]
 

Calculate the variance of all values in a list.

The result value is the best unbiased estimate of var(x), i.e. 1/(n-1) * sum((x-mx)^2).


The documentation for this class was generated from the following files:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.