Changeset 1521 for trunk/yat/normalizer/Zscore.h
- Timestamp:
- Sep 21, 2008, 7:54:19 PM (15 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/normalizer/Zscore.h
r1517 r1521 1 #ifndef _theplu_yat_normalizer_ centralizer_2 #define _theplu_yat_normalizer_ centralizer_1 #ifndef _theplu_yat_normalizer_z_score_ 2 #define _theplu_yat_normalizer_z_score_ 3 3 4 4 /* … … 21 21 */ 22 22 23 #include "yat/statistics/Average.h" 24 25 #include <algorithm> 26 #include <functional> 23 #include "yat/statistics/Averager.h" 27 24 28 25 namespace theplu { … … 31 28 32 29 /** 33 \brief Centralize a range30 \brief Zero mean and unity variance 34 31 35 The center is calculated and then that value is subtracted from 36 each element. By default the center is defined as the arithmetic 37 mean, but this can be changed by providing a suitable 38 UnaryFunction. 32 Create a range that has zero mean and unity variance 39 33 40 34 \since New in yat 0.5 41 35 */ 42 template<class UnaryFunction = statistics::Average> 43 class Centralizer 36 class Zscore 44 37 { 45 38 public: 46 39 /** 47 \brief default constructor 48 49 Creates a UnaryFunction using default constructor. 50 */ 51 Centralizer(void){} 52 53 /** 54 \param uf unary function defining the center. 55 */ 56 Centralizer(const UnaryFunction& uf) 57 : func_(uf) {} 58 59 /** 60 Calculates the center \a c of the range [first, last) using 61 UnaryFunction. This value, \a c, is then subtracted from each 62 element in the range [first, last) and assigned to the 63 corresponding element in range [result, result + (last-first) ). 40 The element in range [result, result + (last-first)) is 41 calculated as result[i] = (first[i] - m) / std where m and std 42 are the mean and standard deviation, respectively, of the range 43 [first, last). 64 44 65 45 It is possible to centralize a range "in place"; it is … … 73 53 OutputIterator result) const 74 54 { 75 return std::transform(first, last, 76 result, std::bind2nd(std::minus<double>(), 77 func_(first, last))); 55 statistics::Averager a; 56 add(a, first, last); 57 double m = a.mean(); 58 double std = a.std(); 59 while (first!=last) { 60 *result = (*first - m) / std; 61 ++first; 62 ++result; 63 } 64 return result; 78 65 } 79 66 80 private:81 UnaryFunction func_;82 67 }; 83 68
Note: See TracChangeset
for help on using the changeset viewer.