![]() |
Object-oriented Scientific Computing Library: Version 0.910
|
00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2011-2012 Andrew W. Steiner 00005 00006 This file is part of O2scl. 00007 00008 O2scl is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 O2scl is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with O2scl. If not, see <http://www.gnu.org/licenses/>. 00020 00021 ------------------------------------------------------------------- 00022 */ 00023 #ifndef HIST_EV_H 00024 #define HIST_EV_H 00025 00026 #include <o2scl/tensor.h> 00027 #include <o2scl/expect_val.h> 00028 #include <o2scl/uniform_grid.h> 00029 #include <o2scl/hist.h> 00030 #include <o2scl/hist_2d.h> 00031 00032 #ifndef DOXYGENP 00033 namespace o2scl { 00034 #endif 00035 00036 /** \brief A set expectation values for histogram bins 00037 00038 See \ref expect_val for some general notes on this and related 00039 classes. 00040 00041 This class is experimental. 00042 00043 This class computes expectation values of bins in a histogram. 00044 It is most useful in cases where one does not know a priori how 00045 many measurements one is going to get for each bin. The class 00046 automatically arranges each bin into blocks, so that the 00047 standard deviation and error and the average can be computed 00048 even when not all bins have been filled with the same number of 00049 measurements. 00050 00051 \note This class always assumes that <tt>n_per_block</tt> 00052 is zero. See \ref expect_val for more details. 00053 00054 \todo Test set_grid_blocks() function. 00055 00056 \todo Create copy constructors as in the scalar_ev class. 00057 */ 00058 class hist_ev : public expect_val { 00059 00060 protected: 00061 00062 /// Last measurement for each block and each bin 00063 umatrix last; 00064 00065 /// Running average for each block and each bin 00066 umatrix vals; 00067 00068 /// The value of \c iblock for each bin 00069 uvector_int iblock_bins; 00070 00071 /// The value of \c i for each bin 00072 uvector_int i_bins; 00073 00074 /** \brief This should always be the same as the size as the 00075 histogram 00076 */ 00077 size_t hsize; 00078 00079 /** \brief The associated histogram 00080 00081 This object is only currently used internally for binning. No 00082 data is added to it. 00083 */ 00084 hist h; 00085 00086 public: 00087 00088 hist_ev(); 00089 00090 /// Create a histogram expectation value 00091 hist_ev(uniform_grid<double> g, size_t n_blocks); 00092 00093 /// Remove all currently stored data, but keep same block size 00094 void reset(); 00095 00096 /// Set the histogram grid and the number of blocks 00097 void set_grid_blocks(uniform_grid<double> g, size_t n_blocks); 00098 00099 /// Add measurement of value \c val at location \c x 00100 virtual void add(double x, double val); 00101 00102 /** \brief Report current average, standard deviation, and 00103 the error in the average 00104 00105 This function deallocates any space already allocated for the 00106 vector parameters and reallocates space as needed. Information 00107 previously stored in these vectors will be lost. 00108 */ 00109 virtual void current_avg_stats(uvector &reps, uvector &avg, 00110 uvector &std_dev, uvector &avg_err, 00111 uvector_int &m_block, 00112 uvector_int &m_per_block); 00113 00114 /** \brief Report current average, standard deviation, and 00115 the error in the average 00116 00117 This function deallocates any space already allocated for the 00118 vector parameters and reallocates space as needed. Information 00119 previously stored in these vectors will be lost. 00120 */ 00121 virtual void current_avg(uvector &reps, uvector &avg, uvector &std_dev, 00122 uvector &avg_err); 00123 00124 }; 00125 00126 #ifdef O2SCL_NEVER_DEFINED 00127 00128 /** \brief A two-dimensional histogram of expectation values 00129 00130 See \ref expect_val for some general notes on 00131 this and related classes. 00132 00133 This class is experimental. 00134 */ 00135 class hist_2d_ev : public expect_val, public hist_2d { 00136 00137 protected: 00138 00139 /// Last measurement for each block and each bin 00140 tensor3 last; 00141 00142 /// Running average for each block and each bin 00143 tensor3 vals; 00144 00145 /// The value of \c iblock for each bin 00146 umatrix_int iblock_bins; 00147 00148 /// The value of \c i for each bin 00149 umatrix_int i_bins; 00150 00151 public: 00152 00153 /// Create a histogram expectation value 00154 hist_2d_ev(uniform_grid hxg, uniform_grid hyg, size_t n_blocks); 00155 00156 /// Add measurement of value \c val at location \c x 00157 virtual void add(double x, double y, double val); 00158 00159 /** \brief Report current average, standard deviation, and 00160 the error in the average 00161 */ 00162 virtual void current_avg_stats(umatrix &avg, umatrix &std_dev, 00163 umatrix &avg_err, umatrix_int &m_block, 00164 umatrix_int &m_per_block); 00165 }; 00166 00167 #endif 00168 00169 } 00170 00171 #endif
Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).