Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __cmtkValueSequence_h_included_
00034 #define __cmtkValueSequence_h_included_
00035
00036 #include <cmtkconfig.h>
00037
00038 #include <math.h>
00039
00040 namespace
00041 cmtk
00042 {
00043
00046
00058 template<class T=float>
00059 class ValueSequence
00060 {
00061 public:
00063 typedef ValueSequence<T> Self;
00064
00066 ValueSequence()
00067 {
00068 this->Reset();
00069 }
00070
00072 void Reset()
00073 {
00074 NValues = 0; Sum = 0; SumAbs = 0; SumOfSquares = 0;
00075 Minimum = Maximum = MinimumAbs = MaximumAbs = 0;
00076 }
00077
00079 void Proceed( const T v )
00080 {
00081 if ( ! NValues )
00082 {
00083 Minimum = Maximum = v;
00084 MinimumAbs = MaximumAbs = fabs( v );
00085 }
00086 else
00087 {
00088 if ( v < Minimum ) Minimum = v;
00089 if ( v > Maximum ) Maximum = v;
00090 if ( fabs( v ) < MinimumAbs ) MinimumAbs = fabs( v );
00091 if ( fabs( v ) > MaximumAbs ) MaximumAbs = fabs( v );
00092 }
00093 ++NValues; Sum += v; SumAbs += fabs( v ); SumOfSquares += v*v;
00094 }
00095
00097 double GetMinimum() const { return Minimum; }
00098
00100 double GetMaximum() const { return Maximum; }
00101
00103 double GetMinimumAbs() const { return MinimumAbs; }
00104
00106 double GetMaximumAbs() const { return MaximumAbs; }
00107
00109 int GetNValues() const { return NValues; }
00110
00112 double GetVariance( const bool unbiased = true ) const
00113 {
00114 const double mu = this->GetAverage();
00115 return ( NValues * mu * mu - 2 * mu * Sum + SumOfSquares ) / ( unbiased ? (NValues-1) : NValues );
00116 }
00117
00119 double GetSum() const { return static_cast<double>( Sum ); }
00120
00122 double GetSumOfSquares() const { return static_cast<double>( SumOfSquares ); }
00123
00125 double GetAverage() const { return static_cast<double>( Sum / NValues ); }
00126
00128 double GetAverageAbs() const { return static_cast<double>( SumAbs / NValues ); }
00129
00131 ValueSequence<T>& operator=( const ValueSequence<T>& other );
00132
00133 private:
00135 T Sum;
00136
00138 T SumAbs;
00139
00141 T SumOfSquares;
00142
00144 int NValues;
00145
00147 T Minimum;
00148
00150 T Maximum;
00151
00153 T MinimumAbs;
00154
00156 T MaximumAbs;
00157
00159 template<class TT>
00160 friend ValueSequence<TT> operator+( const ValueSequence<TT>& a, const ValueSequence<TT>& b );
00161 };
00162
00164
00165 }
00166
00167 #include "cmtkValueSequence.txx"
00168
00169 #endif // #ifndef __cmtkValueSequence_h_included_