RcppNormalizeRowwise

C++ Function Reference

1 Signature

Eigen::MatrixXd BigDataStatMeth::RcppNormalizeRowwise(M X, bool bc, bool bs)

2 Parameters

  • X (M)
  • bc (bool)
  • bs (bool)

3 Returns

Type: typename M

4 Caller Graph

Function dependencies

5 Source Code

File: inst/include/hdf5Algebra/matrixNormalization.hppLines 173-199

inline Eigen::MatrixXd RcppNormalizeRowwise ( M  X, bool bc, bool bs )
    {
        
        static_assert(std::is_same<M, Eigen::MatrixXd >::value || 
                      std::is_same<M, Eigen::Map< Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> >::value || 
                      std::is_same<M, Eigen::Map< Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>> >::value,
                      "Error - type not allowed");
        
        Eigen::MatrixXd rX = X;
        
        Eigen::VectorXd mean = X.rowwise().mean();
        if( bc==true && bs==true )  {

            Eigen::VectorXd std = ((X.colwise() - mean).array().square().rowwise().sum() / (X.cols() - 1)).sqrt();
            rX = (X.colwise() - mean).array().colwise() / std.array();
            
        }   else if (bc == true  && bs==false)   {
            rX = (X.colwise() - mean);
            
        }  else if ( bc == false && bs == true)   {
            
            Eigen::VectorXd std = ((X.colwise() - mean).array().square().rowwise().sum() / (X.cols() - 1)).sqrt();
            rX = X.array().colwise() / std.array();
        }
        
        return(rX);
    }

6 Usage Example

#include "BigDataStatMeth.hpp"

// Example usage
auto result = RcppNormalizeRowwise(...);