Changeset 1521 for trunk/yat


Ignore:
Timestamp:
Sep 21, 2008, 7:54:19 PM (13 years ago)
Author:
Peter
Message:

Adding a Zscore normalizer

Location:
trunk/yat/normalizer
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/yat/normalizer/Makefile.am

    r1520 r1521  
    2626
    2727include_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_
    33
    44/*
     
    2121*/
    2222
    23 #include "yat/statistics/Average.h"
    24 
    25 #include <algorithm>
    26 #include <functional>
     23#include "yat/statistics/Averager.h"
    2724
    2825namespace theplu {
     
    3128
    3229  /**
    33      \brief Centralize a range
     30     \brief Zero mean and unity variance
    3431
    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
    3933
    4034     \since New in yat 0.5
    4135   */
    42   template<class UnaryFunction = statistics::Average>
    43   class Centralizer
     36  class Zscore
    4437  {
    4538  public:
    4639    /**
    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).
    6444
    6545       It is possible to centralize a range "in place"; it is
     
    7353                              OutputIterator result) const
    7454    {
    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;
    7865    }
    7966
    80   private:
    81     UnaryFunction func_;
    8267  };
    8368
Note: See TracChangeset for help on using the changeset viewer.