# Changeset 4048 for trunk/yat/normalizer/Zscore.h

Ignore:
Timestamp:
Mar 3, 2021, 1:39:31 PM (2 years ago)
Message:

add parameter allowing scaling to other than unity variance.

File:
1 edited

### Legend:

Unmodified
 r3550 Shift and scale the values in a range as: \f$y_i = \frac{x_i-m}{s} \f$ where \a m is the mean and \a s is the standard deviation. After normalization, the range will have zero mean and unity variance. \frac{x_i-m}{k*s} \f$where \a m is the mean, \a s is the standard deviation, and \a k is set in constructor (default: 1.0). After normalization, the range will have zero mean and variance = \f$ 1/k^2 \f\$. Type Requirements: { public: /** \param k In the scaling step elements are divided by \c k times the standard deviation \since New in yat 0.19 */ Zscore(double k=1.0); /** \return the k-factor set in constructor \since new in yat 0.19 */ double k(void) const; /** The element in range [result, result + (last-first)) is private: double k_; template void normalize(ForwardIterator first, ForwardIterator last, add(a, first, last); double m = a.mean(); double std = a.std(); double factor = 1.0 / (a.std() * k_); while (first!=last) { *result = (*first - m) / std; *result = (*first - m) * factor; ++first; ++result; add(a, first, last); double m = a.mean(); double std = a.std(); double factor = 1.0 / (a.std() * k_); utility::iterator_traits in_trait; utility::iterator_traits out_trait; while (first!=last) { out_trait.data(result) = (in_trait.data(first) - m) / std; out_trait.data(result) = (in_trait.data(first) - m) * factor; ++first; ++result;