Changeset 1521
 Timestamp:
 Sep 21, 2008, 7:54:19 PM (15 years ago)
 Location:
 trunk
 Files:

 2 edited
 1 copied
Legend:
 Unmodified
 Added
 Removed

trunk/test/normalization_test.cc
r1520 r1521 28 28 #include "yat/normalizer/RowNormalizer.h" 29 29 #include "yat/normalizer/Spearman.h" 30 #include "yat/normalizer/Zscore.h" 30 31 31 32 #include "yat/utility/DataIterator.h" … … 44 45 void test_spearman(test::Suite&); 45 46 void test_spearman_weighted(test::Suite&); 47 void test_z_score(test::Suite&); 46 48 47 49 int main(int argc, char* argv[]) … … 55 57 test_row_normalize(suite); 56 58 test_spearman(suite); 59 test_z_score(suite); 57 60 58 61 return suite.return_value(); … … 220 223 suite.add(suite.equal(res(0,3).data(), 0.5/3)); 221 224 } 225 226 void test_z_score(test::Suite& suite) 227 { 228 suite.err() << "Testing Zscore\n"; 229 std::vector<double> vec; 230 vec.push_back(0); 231 vec.push_back(3.14); 232 normalizer::Zscore zscore; 233 zscore(vec.begin(), vec.end(), vec.begin()); 234 for (size_t i=0; i<vec.size(); ++i) 235 suite.add(suite.equal(vec[i], 2.0*i1.0)); 236 } 237 238 
trunk/yat/normalizer/Makefile.am
r1520 r1521 26 26 27 27 include_normalizer_HEADERS = Centralizer.h ColumnNormalizer.h \ 28 QuantileNormalizer.h RowNormalizer.h Spearman.h 28 QuantileNormalizer.h RowNormalizer.h Spearman.h Zscore.h 
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 + (lastfirst) ). 40 The element in range [result, result + (lastfirst)) 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.