$extrastylesheet
statistics.h
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 #ifndef LIBMESH_STATISTICS_H
00021 #define LIBMESH_STATISTICS_H
00022 
00023 // Local includes
00024 #include "libmesh/libmesh_common.h"
00025 #include "libmesh/id_types.h"
00026 
00027 // C++ includes
00028 #include <vector>
00029 #include <cstdlib> // *must* precede <cmath> for proper std:abs() on PGI, Sun Studio CC
00030 #include <cmath>
00031 
00032 namespace libMesh
00033 {
00034 
00074 // ------------------------------------------------------------
00075 // StatisticsVector class definition
00076 template <typename T>
00077 class StatisticsVector : public std::vector<T>
00078 {
00079 public:
00080 
00084   explicit
00085   StatisticsVector(dof_id_type i=0) : std::vector<T> (i) {}
00086 
00090   StatisticsVector(dof_id_type i, T val) : std::vector<T> (i,val) {}
00091 
00095   virtual ~StatisticsVector () {}
00096 
00097 
00101   virtual Real l2_norm() const;
00102 
00106   virtual T minimum() const;
00107 
00111   virtual T maximum() const;
00112 
00118   virtual Real mean() const;
00119 
00128   virtual Real median();
00129 
00135   virtual Real median() const;
00136 
00145   virtual Real variance() const
00146   { return this->variance(this->mean()); }
00147 
00158   virtual Real variance(const Real known_mean) const;
00159 
00165   virtual Real stddev() const
00166   { return std::sqrt(this->variance()); }
00167 
00174   virtual Real stddev(const Real known_mean) const
00175   { return std::sqrt(this->variance(known_mean)); }
00176 
00181   void normalize();
00182 
00192   virtual void histogram (std::vector<dof_id_type>& bin_members,
00193                           unsigned int n_bins=10);
00194 
00202   void plot_histogram(const processor_id_type my_procid,
00203                       const std::string& filename,
00204                       unsigned int n_bins);
00205 
00209   virtual void histogram (std::vector<dof_id_type>& bin_members,
00210                           unsigned int n_bins=10) const;
00211 
00217   virtual std::vector<dof_id_type> cut_below(Real cut) const;
00218 
00226   virtual std::vector<dof_id_type> cut_above(Real cut) const;
00227 
00228 
00229 private:
00230 
00231 };
00232 
00233 } // namespace libMesh
00234 
00235 #endif // LIBMESH_STATISTICS_H