Ignore:
Timestamp:
Mar 3, 2021, 1:39:31 PM (9 months ago)
Author:
Peter
Message:

add parameter allowing scaling to other than unity variance.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/normalizer/Zscore.h

    r3550 r4048  
    4242
    4343     Shift and scale the values in a range as: \f$ y_i =
    44      \frac{x_i-m}{s} \f$ where \a m is the mean and \a s is the
    45      standard deviation. After normalization, the range will have zero
    46      mean and unity variance.
     44     \frac{x_i-m}{k*s} \f$ where \a m is the mean, \a s is the
     45     standard deviation, and \a k is set in constructor (default:
     46     1.0). After normalization, the range will have zero mean and
     47     variance = \f$ 1/k^2 \f$.
    4748
    4849       Type Requirements:
     
    5758  {
    5859  public:
     60    /**
     61       \param k In the scaling step elements are divided by \c k times
     62       the standard deviation
     63
     64       \since New in yat 0.19
     65     */
     66    Zscore(double k=1.0);
     67
     68    /**
     69       \return the k-factor set in constructor
     70
     71       \since new in yat 0.19
     72     */
     73    double k(void) const;
     74
    5975    /**
    6076       The element in range [result, result + (last-first)) is
     
    8096
    8197  private:
     98    double k_;
     99
     100
    82101    template<class ForwardIterator, class OutputIterator>
    83102    void normalize(ForwardIterator first, ForwardIterator last,
     
    95114      add(a, first, last);
    96115      double m = a.mean();
    97       double std = a.std();
     116      double factor = 1.0 / (a.std() * k_);
    98117      while (first!=last) {
    99         *result = (*first - m) / std;
     118        *result = (*first - m) * factor;
    100119        ++first;
    101120        ++result;
     
    120139      add(a, first, last);
    121140      double m = a.mean();
    122       double std = a.std();
     141      double factor = 1.0 / (a.std() * k_);
    123142      utility::iterator_traits<ForwardIterator> in_trait;
    124143      utility::iterator_traits<OutputIterator> out_trait;
    125144      while (first!=last) {
    126         out_trait.data(result) = (in_trait.data(first) - m) / std;
     145        out_trait.data(result) = (in_trait.data(first) - m) * factor;
    127146        ++first;
    128147        ++result;
Note: See TracChangeset for help on using the changeset viewer.