Branch data Line data Source code
1 : : /* *****************************************************************
2 : : MESQUITE -- The Mesh Quality Improvement Toolkit
3 : :
4 : : Copyright 2010 Sandia National Laboratories. Developed at the
5 : : University of Wisconsin--Madison under SNL contract number
6 : : 624796. The U.S. Government and the University of Wisconsin
7 : : retain certain rights to this software.
8 : :
9 : : This library is free software; you can redistribute it and/or
10 : : modify it under the terms of the GNU Lesser General Public
11 : : License as published by the Free Software Foundation; either
12 : : version 2.1 of the License, or (at your option) any later version.
13 : :
14 : : This library is distributed in the hope that it will be useful,
15 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : Lesser General Public License for more details.
18 : :
19 : : You should have received a copy of the GNU Lesser General Public License
20 : : (lgpl.txt) along with this library; if not, write to the Free Software
21 : : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 : :
23 : : (2010) [email protected]
24 : :
25 : : ***************************************************************** */
26 : :
27 : : /** \file SimpleStats.hpp
28 : : * \brief
29 : : * \author Jason Kraftcheck
30 : : */
31 : :
32 : : #ifndef MSQ_SIMPLE_STATS_HPP
33 : : #define MSQ_SIMPLE_STATS_HPP
34 : :
35 : : #include "Mesquite.hpp"
36 : :
37 : : namespace MBMesquite
38 : : {
39 : :
40 : : /**\brief Accumulate various statistics for a list of discrete values */
41 : : class SimpleStats
42 : : {
43 : : private:
44 : : double valueSum, valueSqrSum, valueMin, valueMax;
45 : : unsigned long valueCount;
46 : :
47 : : public:
48 : : SimpleStats();
49 : :
50 : : /**\brief minimum value */
51 : : double minimum() const
52 : : {
53 : : return valueMin;
54 : : }
55 : : /**\brief maximum value */
56 : : double maximum() const
57 : : {
58 : : return valueMax;
59 : : }
60 : : /**\brief algebraic mean of values */
61 : 127 : double average() const
62 : : {
63 : 127 : return valueSum / valueCount;
64 : : }
65 : : /**\brief root mean squared of values */
66 : : double rms() const
67 : : {
68 : : return sqrt( valueSqrSum / valueCount );
69 : : }
70 : : /**\brief variance of values */
71 : 30 : double variance() const
72 : : {
73 : 30 : return valueSqrSum / valueCount - average() * average();
74 : : }
75 : : /**\brief standard deviation of values */
76 : 30 : double standard_deviation() const
77 : : {
78 : 30 : return sqrt( fabs( variance() ) );
79 : : }
80 : :
81 : : /**\brief incorporate another value into statistics */
82 : 73776 : void add_value( double value )
83 : : {
84 : 73776 : valueSum += value;
85 : 73776 : valueSqrSum += value * value;
86 [ + + ]: 73776 : if( value < valueMin ) valueMin = value;
87 [ + + ]: 73776 : if( value > valueMax ) valueMax = value;
88 : 73776 : ++valueCount;
89 : 73776 : }
90 : :
91 : : /**\brief incorporate another value into statistics */
92 : 58369 : void add_squared( double value_squared )
93 : : {
94 : 58369 : double value = sqrt( value_squared );
95 : 58369 : valueSum += value;
96 : 58369 : valueSqrSum += value_squared;
97 [ + + ]: 58369 : if( value < valueMin ) valueMin = value;
98 [ + + ]: 58369 : if( value > valueMax ) valueMax = value;
99 : 58369 : ++valueCount;
100 : 58369 : }
101 : :
102 : : void clear();
103 : :
104 : 53 : bool empty()
105 : : {
106 : 53 : return 0ul == valueCount;
107 : : }
108 : : };
109 : :
110 : : } // namespace MBMesquite
111 : :
112 : : #endif
|