libMesh
Public Member Functions | List of all members
libMesh::StatisticsVector< T > Class Template Reference

The StatisticsVector class is derived from the std::vector<> and therefore has all of its useful features. More...

#include <statistics.h>

Inheritance diagram for libMesh::StatisticsVector< T >:
[legend]

Public Member Functions

 StatisticsVector (dof_id_type i=0)
 Call the std::vector constructor. More...
 
 StatisticsVector (dof_id_type i, T val)
 Call the std::vector constructor, fill each entry with val. More...
 
virtual ~StatisticsVector ()
 Destructor. More...
 
virtual Real l2_norm () const
 
virtual T minimum () const
 
virtual T maximum () const
 
virtual Real mean () const
 
virtual Real median ()
 
virtual Real median () const
 A const version of the median function. More...
 
virtual Real variance () const
 
virtual Real variance (const Real known_mean) const
 
virtual Real stddev () const
 
virtual Real stddev (const Real known_mean) const
 
void normalize ()
 Divides all entries by the largest entry and stores the result. More...
 
virtual void histogram (std::vector< dof_id_type > &bin_members, unsigned int n_bins=10)
 
void plot_histogram (const processor_id_type my_procid, const std::string &filename, unsigned int n_bins)
 Generates a Matlab/Octave style file which can be used to make a plot of the histogram having the desired number of bins. More...
 
virtual void histogram (std::vector< dof_id_type > &bin_members, unsigned int n_bins=10) const
 A const version of the histogram function. More...
 
virtual std::vector< dof_id_typecut_below (Real cut) const
 
virtual std::vector< dof_id_typecut_above (Real cut) const
 

Detailed Description

template<typename T>
class libMesh::StatisticsVector< T >

The StatisticsVector class is derived from the std::vector<> and therefore has all of its useful features.

It was designed to not have any internal state, i.e. no public or private data members. Also, it was only designed for classes and types for which the operators +,*,/ have meaning, specifically floats, doubles, ints, etc. The main reason for this design decision was to allow a std::vector<> to be successfully cast to a StatisticsVector, thereby enabling its additional functionality. We do not anticipate any problems with deriving from an stl container which lacks a virtual destructor in this case.

Where manipulation of the data set was necessary (for example sorting) two versions of member functions have been implemented. The non-const versions perform sorting directly in the data set, invalidating pointers and changing the entries. const versions of the same functions are generally available, and will be automatically invoked on const StatisticsVector objects. A draw-back to the const versions is that they simply make a copy of the original object and therefore double the original memory requirement for the data set.

Most of the actual code was copied or adapted from the GNU Scientific Library (GSL). More precisely, the recursion relations for computing the mean were implemented in order to avoid possible problems with buffer overruns.

Author
John W. Peterson
Date
2002 A std::vector derived class for implementing simple statistical algorithms.

Definition at line 67 of file statistics.h.

Constructor & Destructor Documentation

◆ StatisticsVector() [1/2]

template<typename T>
libMesh::StatisticsVector< T >::StatisticsVector ( dof_id_type  i = 0)
explicit

Call the std::vector constructor.

Definition at line 75 of file statistics.h.

75 : std::vector<T> (i) {}

◆ StatisticsVector() [2/2]

template<typename T>
libMesh::StatisticsVector< T >::StatisticsVector ( dof_id_type  i,
val 
)

Call the std::vector constructor, fill each entry with val.

Definition at line 80 of file statistics.h.

80 : std::vector<T> (i,val) {}

◆ ~StatisticsVector()

template<typename T>
virtual libMesh::StatisticsVector< T >::~StatisticsVector ( )
virtual

Destructor.

Virtual so we can derive from the StatisticsVector

Definition at line 85 of file statistics.h.

85 {}

Member Function Documentation

◆ cut_above()

template<typename T>
virtual std::vector<dof_id_type> libMesh::StatisticsVector< T >::cut_above ( Real  cut) const
virtual
Returns
A vector of dof_id_types which corresponds to the indices of every member of the data set above the cutoff value cut.

I chose not to combine these two functions since the interface is cleaner with one passed parameter instead of two.

Reimplemented in libMesh::ErrorVector.

◆ cut_below()

template<typename T>
virtual std::vector<dof_id_type> libMesh::StatisticsVector< T >::cut_below ( Real  cut) const
virtual
Returns
A vector of dof_id_types which corresponds to the indices of every member of the data set below the cutoff value "cut".

Reimplemented in libMesh::ErrorVector.

◆ histogram() [1/2]

template<typename T>
virtual void libMesh::StatisticsVector< T >::histogram ( std::vector< dof_id_type > &  bin_members,
unsigned int  n_bins = 10 
)
virtual
Returns
A histogram with n_bins bins for the data set.

For simplicity, the bins are assumed to be of uniform size. Upon return, the bin_members vector will contain unsigned integers which give the number of members in each bin. WARNING: This non-const function sorts the vector, changing its order. Source: GNU Scientific Library.

◆ histogram() [2/2]

template<typename T>
virtual void libMesh::StatisticsVector< T >::histogram ( std::vector< dof_id_type > &  bin_members,
unsigned int  n_bins = 10 
) const
virtual

A const version of the histogram function.

◆ l2_norm()

template<typename T>
virtual Real libMesh::StatisticsVector< T >::l2_norm ( ) const
virtual
Returns
The l2 norm of the data set.

◆ maximum()

template<typename T>
virtual T libMesh::StatisticsVector< T >::maximum ( ) const
virtual
Returns
The maximum value in the data set.

◆ mean()

template<typename T>
virtual Real libMesh::StatisticsVector< T >::mean ( ) const
virtual
Returns
The mean value of the data set using a recurrence relation.

Source: GNU Scientific Library

Reimplemented in libMesh::ErrorVector.

Referenced by libMesh::StatisticsVector< ErrorVectorReal >::variance().

◆ median() [1/2]

template<typename T>
virtual Real libMesh::StatisticsVector< T >::median ( )
virtual
Returns
The median (e.g. the middle) value of the data set.

This function modifies the original data by sorting, so it can't be called on const objects. Source: GNU Scientific Library.

Reimplemented in libMesh::ErrorVector.

◆ median() [2/2]

template<typename T>
virtual Real libMesh::StatisticsVector< T >::median ( ) const
virtual

A const version of the median function.

Requires twice the memory of original data set but does not change the original.

Reimplemented in libMesh::ErrorVector.

◆ minimum()

template<typename T>
virtual T libMesh::StatisticsVector< T >::minimum ( ) const
virtual
Returns
The minimum value in the data set.

Reimplemented in libMesh::ErrorVector.

◆ normalize()

template<typename T>
void libMesh::StatisticsVector< T >::normalize ( )

Divides all entries by the largest entry and stores the result.

◆ plot_histogram()

template<typename T>
void libMesh::StatisticsVector< T >::plot_histogram ( const processor_id_type  my_procid,
const std::string &  filename,
unsigned int  n_bins 
)

Generates a Matlab/Octave style file which can be used to make a plot of the histogram having the desired number of bins.

Uses the histogram(...) function in this class WARNING: The histogram(...) function is non-const, and changes the order of the vector.

◆ stddev() [1/2]

template<typename T>
virtual Real libMesh::StatisticsVector< T >::stddev ( ) const
virtual
Returns
The standard deviation of the data set, which is simply the square-root of the variance.

Definition at line 154 of file statistics.h.

155  { return std::sqrt(this->variance()); }
virtual Real variance() const
Definition: statistics.h:134

◆ stddev() [2/2]

template<typename T>
virtual Real libMesh::StatisticsVector< T >::stddev ( const Real  known_mean) const
virtual
Returns
Computes the standard deviation of the data set, which is simply the square-root of the variance.

This method can be used for efficiency when the mean has already been computed.

Definition at line 164 of file statistics.h.

165  { return std::sqrt(this->variance(known_mean)); }
virtual Real variance() const
Definition: statistics.h:134

◆ variance() [1/2]

template<typename T>
virtual Real libMesh::StatisticsVector< T >::variance ( ) const
virtual
Returns
The variance of the data set.

Uses a recurrence relation to prevent data overflow for large sums.

Note
The variance is equal to the standard deviation squared. Source: GNU Scientific Library.

Reimplemented in libMesh::ErrorVector.

Definition at line 134 of file statistics.h.

Referenced by libMesh::StatisticsVector< ErrorVectorReal >::stddev(), and libMesh::StatisticsVector< ErrorVectorReal >::variance().

135  { return this->variance(this->mean()); }
virtual Real mean() const
virtual Real variance() const
Definition: statistics.h:134

◆ variance() [2/2]

template<typename T>
virtual Real libMesh::StatisticsVector< T >::variance ( const Real  known_mean) const
virtual
Returns
The variance of the data set where the mean is provided.

This is useful for efficiency when you have already calculated the mean. Uses a recurrence relation to prevent data overflow for large sums.

Note
The variance is equal to the standard deviation squared. Source: GNU Scientific Library.

Reimplemented in libMesh::ErrorVector.


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