A std::vector derived class for implementing simple statistical algorithms. More...
#include <statistics.h>
Public Member Functions | |
StatisticsVector (dof_id_type i=0) | |
StatisticsVector (dof_id_type i, T val) | |
virtual | ~StatisticsVector () |
virtual Real | l2_norm () const |
virtual T | minimum () const |
virtual T | maximum () const |
virtual Real | mean () const |
virtual Real | median () |
virtual Real | median () const |
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 () |
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) |
virtual void | histogram (std::vector< dof_id_type > &bin_members, unsigned int n_bins=10) const |
virtual std::vector< dof_id_type > | cut_below (Real cut) const |
virtual std::vector< dof_id_type > | cut_above (Real cut) const |
A std::vector derived class for implementing simple statistical algorithms.
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.
Definition at line 67 of file statistics.h.
|
inlineexplicit |
Call the std::vector constructor.
Definition at line 75 of file statistics.h.
|
inline |
Call the std::vector constructor, fill each entry with val
.
Definition at line 80 of file statistics.h.
|
inlinevirtual |
Destructor. Virtual so we can derive from the StatisticsVector
Definition at line 85 of file statistics.h.
|
virtual |
I chose not to combine these two functions since the interface is cleaner with one passed parameter instead of two.
Reimplemented in libMesh::ErrorVector.
Definition at line 349 of file statistics.C.
|
virtual |
Reimplemented in libMesh::ErrorVector.
Definition at line 325 of file statistics.C.
|
virtual |
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.
Definition at line 178 of file statistics.C.
Referenced by libMesh::StatisticsVector< ErrorVectorReal >::histogram().
|
virtual |
A const version of the histogram function.
Definition at line 313 of file statistics.C.
|
virtual |
Definition at line 36 of file statistics.C.
|
virtual |
|
virtual |
Source: GNU Scientific Library
Reimplemented in libMesh::ErrorVector.
Definition at line 74 of file statistics.C.
Referenced by libMesh::StatisticsVector< ErrorVectorReal >::variance().
|
virtual |
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.
Definition at line 95 of file statistics.C.
Referenced by libMesh::ErrorVector::median(), and libMesh::StatisticsVector< ErrorVectorReal >::median().
|
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.
Definition at line 130 of file statistics.C.
|
virtual |
Reimplemented in libMesh::ErrorVector.
Definition at line 48 of file statistics.C.
void libMesh::StatisticsVector< T >::normalize | ( | ) |
Divides all entries by the largest entry and stores the result.
Definition at line 164 of file statistics.C.
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.
Definition at line 270 of file statistics.C.
|
inlinevirtual |
Definition at line 154 of file statistics.h.
|
inlinevirtual |
This method can be used for efficiency when the mean
has already been computed.
Definition at line 164 of file statistics.h.
|
inlinevirtual |
Uses a recurrence relation to prevent data overflow for large sums.
Reimplemented in libMesh::ErrorVector.
Definition at line 134 of file statistics.h.
Referenced by libMesh::StatisticsVector< ErrorVectorReal >::stddev(), and libMesh::StatisticsVector< ErrorVectorReal >::variance().
|
virtual |
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.
Reimplemented in libMesh::ErrorVector.
Definition at line 141 of file statistics.C.