libMesh
|
The StatisticsVector class is derived from the std::vector<> and therefore has all of its useful features. More...
#include <statistics.h>
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 ()=default |
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_type > | cut_below (Real cut) const |
virtual std::vector< dof_id_type > | cut_above (Real cut) const |
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.
|
virtualdefault |
Destructor.
Virtual so we can derive from the StatisticsVector
|
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 364 of file statistics.C.
|
virtual |
Reimplemented in libMesh::ErrorVector.
Definition at line 340 of file statistics.C.
Referenced by main().
|
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 179 of file statistics.C.
Referenced by libMesh::StatisticsVector< ErrorVectorReal >::histogram(), and main().
|
virtual |
A const version of the histogram function.
Definition at line 328 of file statistics.C.
|
virtual |
Definition at line 37 of file statistics.C.
Referenced by assemble_and_solve(), and main().
|
virtual |
Definition at line 62 of file statistics.C.
Referenced by assemble_and_solve(), and main().
|
virtual |
Source: GNU Scientific Library
Reimplemented in libMesh::ErrorVector.
Definition at line 75 of file statistics.C.
Referenced by main(), and 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 96 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 131 of file statistics.C.
|
virtual |
Reimplemented in libMesh::ErrorVector.
Definition at line 49 of file statistics.C.
void libMesh::StatisticsVector< T >::normalize | ( | ) |
Divides all entries by the largest entry and stores the result.
Definition at line 165 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 285 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 142 of file statistics.C.