Vespucci  1.0.0
normalization.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
20 
22 
23 
25 
31 arma::vec Vespucci::Math::Normalization::StandardScore(const arma::vec &X)
32 {
33  arma::vec normalized = X;
34  double mean = arma::mean(normalized);
35  double std_dev = arma::stddev(X);
36  normalized -= mean * arma::ones(normalized.n_elem);
37  normalized /= std_dev;
38  return normalized;
39 }
40 
47 {
48  arma::mat normalized = X;
49  arma::rowvec means = arma::mean(X);
50  arma::rowvec std_devs = arma::stddev(X);
51  normalized.each_row() -= means;
52  std_devs.transform( [](double val){return 1.0 / val;}); //probably faster than finding inverse of diagonal matrix?
53  return normalized * arma::diagmat(std_devs);
54 }
55 
56 
65 arma::mat Vespucci::Math::Normalization::SNVNorm(const arma::mat &X, const double offset, bool center)
66 {
67  arma::mat X_cpy = X;
68  arma::rowvec weights = arma::stddev(X, 0) + offset*arma::ones(1, X.n_cols);
69  weights.transform( [](double val){return 1.0 / val;});
70  if (center){
71  arma::rowvec means = arma::mean(X);
72  X_cpy.each_row() -= means;
73  }
74  return X_cpy * arma::diagmat(weights);
75 }
VESPUCCI_EXPORT arma::mat StandardScoreMat(const arma::mat &X)
Vespucci::Math::Normalization::StandardScore.
VESPUCCI_EXPORT arma::vec StandardScore(const arma::vec &X)
Vespucci::Math::Normalization::StandardScore.
VESPUCCI_EXPORT arma::mat SNVNorm(const arma::mat &X, const double offset, bool center)
Vespucci::Math::Normalization::SNVNorm.