lib/MolecularFeaturizer.cpp
// normalize mf_traj by column: divide each column by its median
normalize mf_traj by column: divide each column by its median
normalize mf_traj by column : divide each column by its median
bool normalize(std::vector<std::vector<double> >& mf_traj){
  unsigned int i, j;
  double median;
  int numcols, veclen;
  numcols = mf_traj[0].size();
  veclen = mf_traj.size();
  vector<vector<double> > trans_mf(mf_traj[0].size(),
                                        vector<double>(mf_traj.size()));
  for (i = 0; i < mf_traj.size(); ++i){
    for (j = 0; j < mf_traj[0].size(); ++j){
      trans_mf[j][i] = mf_traj[i][j];
    }
  }
  for (i = 0; i < numcols; ++i){
    sort(trans_mf[i].begin(), trans_mf[i].end());
    if (veclen % 2 == 0){
      median = (trans_mf[i][veclen / 2 - 1] + trans_mf[i][veclen / 2]) / 2;
    }
    else{
      median = trans_mf[i][veclen / 2];
    }
    if (median != 0){
      for (j = 0; j < veclen; ++j){
        mf_traj[j][i] = mf_traj[j][i] / median;
      }
    }
  }
  return 1;
}
bool normalize ( std :: vector < std :: vector < double > > & mf_traj ) { unsigned int i , j ; double median ; int numcols , veclen ; numcols = mf_traj [ 0 ] . size ( ) ; veclen = mf_traj . size ( ) ; vector < vector < double > > trans_mf ( mf_traj [ 0 ] . size ( ) , vector < double > ( mf_traj . size ( ) ) ) ; for ( i = 0 ; i < mf_traj . size ( ) ; ++ i ) { for ( j = 0 ; j < mf_traj [ 0 ] . size ( ) ; ++ j ) { trans_mf [ j ] [ i ] = mf_traj [ i ] [ j ] ; } } for ( i = 0 ; i < numcols ; ++ i ) { sort ( trans_mf [ i ] . begin ( ) , trans_mf [ i ] . end ( ) ) ; if ( veclen % 2 == 0 ) { median = ( trans_mf [ i ] [ veclen / 2 - 1 ] + trans_mf [ i ] [ veclen / 2 ] ) / 2 ; } else { median = trans_mf [ i ] [ veclen / 2 ] ; } if ( median != 0 ) { for ( j = 0 ; j < veclen ; ++ j ) { mf_traj [ j ] [ i ] = mf_traj [ j ] [ i ] / median ; } } } return 1 ; }
normalize mf_traj by column: divide each column by its median
normalize mf_traj by column : divide each column by its median
// transpose features // find median // divide the whole column in the original vector matrix by column median