Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ckstatistics.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Illinois Open Source License *
3  * *
4  * University of Illinois/NCSA *
5  * Open Source License *
6  * *
7  * Copyright@2008, University of Illinois. All rights reserved. *
8  * *
9  * Developed by: *
10  * *
11  * Center for Simulation of Advanced Rockets *
12  * *
13  * University of Illinois *
14  * *
15  * www.csar.uiuc.edu *
16  * *
17  * Permission is hereby granted, free of charge, to any person *
18  * obtaining a copy of this software and associated documentation *
19  * files (the "Software"), to deal with the Software without *
20  * restriction, including without limitation the rights to use, *
21  * copy, modify, merge, publish, distribute, sublicense, and/or *
22  * sell copies of the Software, and to permit persons to whom the *
23  * Software is furnished to do so, subject to the following *
24  * conditions: *
25  * *
26  * *
27  * @ Redistributions of source code must retain the above copyright *
28  * notice, this list of conditions and the following disclaimers. *
29  * *
30  * @ Redistributions in binary form must reproduce the above *
31  * copyright notice, this list of conditions and the following *
32  * disclaimers in the documentation and/or other materials *
33  * provided with the distribution. *
34  * *
35  * @ Neither the names of the Center for Simulation of Advanced *
36  * Rockets, the University of Illinois, nor the names of its *
37  * contributors may be used to endorse or promote products derived *
38  * from this Software without specific prior written permission. *
39  * *
40  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
41  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
42  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
43  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
44  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
45  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
46  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
47  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
48  *********************************************************************
49  * Please acknowledge The University of Illinois Center for *
50  * Simulation of Advanced Rockets in works and publications *
51  * resulting from this software or its derivatives. *
52  *********************************************************************/
53 /*
54 (Copied out of) Orion's Standard Library
55 written by
56 Orion Sky Lawlor, olawlor@acm.org, 11/25/2002
57 */
58 #ifndef __UIUC_OSL_STATISTICS_H
59 #define __UIUC_OSL_STATISTICS_H
60 
61 #include "math.h" //for sqrt
62 #include "stdio.h" //for fprintf
63 
78 template<class real,class ret>
79 class CkSampleT {
80  real lo,hi; //smallest and largest values
81  ret sum; //sum of values
82  ret sq; //sum of squares of values
83  int n; //number of values
84 public:
85  CkSampleT(void) {
86  lo=(real)1.0e20; hi=(real)-1.0e20;
87  sum=sq=(ret)0;
88  n=0;
89  }
95  inline void add(real r) {
96  if (r<lo) lo=r;
97  if (r>hi) hi=r;
98  sum+=(ret)r;
99  sq+=(ret)(r*r);
100  n++;
101  }
103  inline void operator+=(real r) { add(r); }
104 
109  ret getMean(void) const {
110  return sum/n;
111  }
117  ret getVariance(void) const {
118  return (sq-sum*sum/n)/(n-1);
119  }
124  ret getStddev(void) const {
125  return (ret)sqrt(getVariance());
126  }
130  real getMin(void) const {return lo;}
134  real getMax(void) const {return hi;}
138  int getCount(void) const {return n;}
139 
145  void print(FILE *dest) {
146  fprintf(dest,"ave= %g stddev= %g min= %g max= %g n= %d\n",
147  (double)getMean(), (double)getStddev(), (double)getMin(), (double)getMax(), (int)getCount());
148  }
149 
153  void printMinAveMax(FILE *dest) {
154  fprintf(dest,"min= %g ave= %g max= %g \n",
155  (double)getMin(), (double)getMean(), (double)getMax());
156  }
157 
161  void print(void) {print(stdout);}
162 
163 };
165 
166 #endif
167 
CkSampleT represents a statistical &quot;sample&quot; of some data values.
Definition: ckstatistics.h:79
float real
Definition: gridutil.h:70
CkSampleT(void)
Definition: ckstatistics.h:85
double sqrt(double d)
Definition: double.h:73
void printMinAveMax(FILE *dest)
Print a terse textual description of this sample to this FILE.
Definition: ckstatistics.h:153
ret getStddev(void) const
Return the standard deviation of this sample, in (value) units.
Definition: ckstatistics.h:124
ret getVariance(void) const
Return the variance of this sample, in (value^2) units.
Definition: ckstatistics.h:117
real getMin(void) const
Return the smallest value encountered.
Definition: ckstatistics.h:130
real getMax(void) const
Return the largest value encountered.
Definition: ckstatistics.h:134
void add(real r)
Add this value to the sample set.
Definition: ckstatistics.h:95
CkSampleT< double, double > CkSample
Definition: ckstatistics.h:164
void operator+=(real r)
Shorthand for add function.
Definition: ckstatistics.h:103
ret getMean(void) const
Return the mean value of this sample–the &quot;average&quot; value, in (value) units.
Definition: ckstatistics.h:109
void print(FILE *dest)
Print a textual description of this sample to this FILE.
Definition: ckstatistics.h:145
int getCount(void) const
Return the number of values in this sample.
Definition: ckstatistics.h:138
void print(void)
Print a textual description of this sample to stdout.
Definition: ckstatistics.h:161