libMesh
statistics.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_STATISTICS_H
21 #define LIBMESH_STATISTICS_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/id_types.h"
26 
27 // C++ includes
28 #include <vector>
29 #include <cstdlib> // *must* precede <cmath> for proper std:abs() on PGI, Sun Studio CC
30 #include <cmath>
31 
32 namespace libMesh
33 {
34 
66 template <typename T>
67 class StatisticsVector : public std::vector<T>
68 {
69 public:
70 
74  explicit
75  StatisticsVector(dof_id_type i=0) : std::vector<T> (i) {}
76 
80  StatisticsVector(dof_id_type i, T val) : std::vector<T> (i,val) {}
81 
85  virtual ~StatisticsVector () = default;
86 
87 
91  virtual Real l2_norm() const;
92 
96  virtual T minimum() const;
97 
101  virtual T maximum() const;
102 
109  virtual Real mean() const;
110 
117  virtual Real median();
118 
123  virtual Real median() const;
124 
134  virtual Real variance() const
135  { return this->variance(this->mean()); }
136 
148  virtual Real variance(const Real known_mean) const;
149 
154  virtual Real stddev() const
155  { return std::sqrt(this->variance()); }
156 
164  virtual Real stddev(const Real known_mean) const
165  { return std::sqrt(this->variance(known_mean)); }
166 
170  void normalize();
171 
181  virtual void histogram (std::vector<dof_id_type> & bin_members,
182  unsigned int n_bins=10);
183 
191  void plot_histogram(const processor_id_type my_procid,
192  const std::string & filename,
193  unsigned int n_bins);
194 
198  virtual void histogram (std::vector<dof_id_type> & bin_members,
199  unsigned int n_bins=10) const;
200 
206  virtual std::vector<dof_id_type> cut_below(Real cut) const;
207 
216  virtual std::vector<dof_id_type> cut_above(Real cut) const;
217 };
218 
219 } // namespace libMesh
220 
221 #endif // LIBMESH_STATISTICS_H
virtual T maximum() const
Definition: statistics.C:62
virtual Real mean() const
Definition: statistics.C:75
virtual Real median()
Definition: statistics.C:96
virtual Real l2_norm() const
Definition: statistics.C:37
void normalize()
Divides all entries by the largest entry and stores the result.
Definition: statistics.C:165
The StatisticsVector class is derived from the std::vector<> and therefore has all of its useful feat...
Definition: statistics.h:67
virtual std::vector< dof_id_type > cut_above(Real cut) const
Definition: statistics.C:364
virtual Real stddev() const
Definition: statistics.h:154
StatisticsVector(dof_id_type i=0)
Call the std::vector constructor.
Definition: statistics.h:75
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:53
The libMesh namespace provides an interface to certain functionality in the library.
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 des...
Definition: statistics.C:285
uint8_t processor_id_type
Definition: id_types.h:104
virtual void histogram(std::vector< dof_id_type > &bin_members, unsigned int n_bins=10)
Definition: statistics.C:179
virtual Real stddev(const Real known_mean) const
Definition: statistics.h:164
virtual ~StatisticsVector()=default
Destructor.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
StatisticsVector(dof_id_type i, T val)
Call the std::vector constructor, fill each entry with val.
Definition: statistics.h:80
virtual std::vector< dof_id_type > cut_below(Real cut) const
Definition: statistics.C:340
virtual T minimum() const
Definition: statistics.C:49
virtual Real variance() const
Definition: statistics.h:134
uint8_t dof_id_type
Definition: id_types.h:67