Ignore:
Timestamp:
Aug 31, 2006, 10:52:02 AM (16 years ago)
Author:
Jari Häkkinen
Message:

Removed gslapi namespace and put the code into utility namespace.
Move #ifndef _header_ idiom to top of touched header files.
Removed unneccesary #includes, and added needed #includes.

Location:
trunk/c++_tools/utility
Files:
15 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/utility/Alignment.cc

    r301 r616  
    22
    33#include <c++_tools/utility/Alignment.h>
    4 #include <c++_tools/gslapi/matrix.h>
     4#include <c++_tools/utility/matrix.h>
    55
    66#include <utility>
     
    1111namespace alignment {
    1212
    13   double NeedlemanWunsch(const gslapi::matrix& s,
     13  double NeedlemanWunsch(const utility::matrix& s,
    1414                         std::vector<std::pair<size_t, size_t> >& path,
    1515                         const double gap)
    1616  {
    17     gslapi::matrix m(s.rows()+1,s.columns()+1);
     17    utility::matrix m(s.rows()+1,s.columns()+1);
    1818    // Init upper and left border of matrix
    1919    for (size_t i=1; i<m.rows(); i++)
     
    2323    // choice(i,j) tells us how we came to s(i,j). 1 is diagonal, 2
    2424    // vertical, and 3 horizontal,
    25     gslapi::matrix choice(m.rows(),m.columns());
     25    utility::matrix choice(m.rows(),m.columns());
    2626
    2727    // Calculating NeedlemanWunsch matrix
  • trunk/c++_tools/utility/Alignment.h

    r304 r616  
    1 // $Id$
    2 
    31#ifndef _theplu_utility_alignment_
    42#define _theplu_utility_alignment_
     3
     4// $Id$
    55
    66#include <utility>
     
    99namespace theplu {
    1010
    11 namespace gslapi {
     11namespace utility {
    1212  class matrix;
    1313}
     
    3636  /// @return the global maximum alignment score.
    3737  ///
    38   double NeedlemanWunsch(const gslapi::matrix& s,
     38  double NeedlemanWunsch(const utility::matrix& s,
    3939                         std::vector<std::pair<size_t, size_t> >& path,
    4040                         const double gap);
  • trunk/c++_tools/utility/Makefile.am

    r594 r616  
    2626noinst_LTLIBRARIES = libutility.la
    2727libutility_la_SOURCES = \
    28   Alignment.cc CommandLine.cc FileIO.cc kNNI.cc NNI.cc Option.cc PCA.cc \
    29   stl_utility.cc SVD.cc utility.cc WeNNI.cc
     28  Alignment.cc CommandLine.cc FileIO.cc kNNI.cc matrix.cc NNI.cc        \
     29  Option.cc PCA.cc stl_utility.cc SVD.cc utility.cc vector.cc WeNNI.cc
     30
    3031
    3132include_utilitydir = $(includedir)/c++_tools/utility
    3233
    3334include_utility_HEADERS = \
    34   Alignment.h CommandLine.h Exception.h FileIO.h kNNI.h NNI.h Option.h PCA.h \
    35   stl_utility.h SVD.h utility.h WeNNI.h
     35  Alignment.h CommandLine.h Exception.h FileIO.h kNNI.h matrix.h NNI.h  \
     36  Option.h PCA.h stl_utility.h SVD.h utility.h vector.h WeNNI.h
  • trunk/c++_tools/utility/NNI.cc

    r570 r616  
    3737namespace utility {
    3838
    39   using namespace std;
    40 
    4139  // For a discussion and motivation for various algorithm
    4240  // implementations here see the paper cited in the class definition
    4341  // documentation.
    44   NNI::NNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,
     42  NNI::NNI(const utility::matrix& matrix,const utility::matrix& weight,
    4543           const u_int neighbours)
    4644    : data_(matrix), imputed_data_(matrix), neighbours_(neighbours),
     
    5351  //                {\sum_{k=l,C} w_{ik} w_{jk} }
    5452  // where C is the number of columns
    55   vector<pair<u_int,double> > NNI::calculate_distances(const u_int row) const
     53  std::vector<std::pair<u_int,double> >
     54  NNI::calculate_distances(const u_int row) const
    5655  {
    57     vector<pair<u_int,double> > distance;
     56    std::vector<std::pair<u_int,double> > distance;
    5857    for (size_t i=0; i<data_.rows(); i++)
    5958      if (i!=row) {
    6059        double contribs=0;
    61         pair<u_int,double> this_distance(i,0.0);
     60        std::pair<u_int,double> this_distance(i,0.0);
    6261        for (size_t j=0; j<data_.columns(); j++)
    6362          // 0 contribution for missing values
     
    8281  // number, and neighbours are disqualified if their element (column)
    8382  // weight is zero
    84   vector<u_int>
     83  std::vector<u_int>
    8584  NNI::nearest_neighbours(const u_int column,
    86                           const vector<pair<u_int,double> >& d) const
     85                          const std::vector<std::pair<u_int,double> >& d) const
    8786  {
    88     vector<u_int> index;
     87    std::vector<u_int> index;
    8988    double contribs=0;
    9089    for (u_int i=0; ((i<d.size()) &&
  • trunk/c++_tools/utility/NNI.h

    r570 r616  
     1#ifndef _theplu_utility_nni_
     2#define _theplu_utility_nni_
     3
    14// $Id$
    25
     
    2528*/
    2629
    27 #ifndef _theplu_utility_nni_
    28 #define _theplu_utility_nni_
    29 
    3030#include <iostream>
    3131#include <utility>
    3232#include <vector>
    3333
    34 #include <c++_tools/gslapi/matrix.h>
     34#include <c++_tools/utility/matrix.h>
    3535
    3636namespace theplu {
     
    8888    /// algorithms.
    8989    ///
    90     NNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,
     90    NNI(const utility::matrix& matrix,const utility::matrix& weight,
    9191        const u_int neighbours);
    9292
     
    103103    /// @return A const reference to the modified data.
    104104    ///
    105     const gslapi::matrix& imputed_data(void) const { return imputed_data_; }
     105    const utility::matrix& imputed_data(void) const { return imputed_data_; }
    106106
    107107    ///
     
    115115                             const std::vector<std::pair<u_int,double> >&) const;
    116116
    117     const gslapi::matrix& data_;
    118     gslapi::matrix imputed_data_;
     117    const utility::matrix& data_;
     118    utility::matrix imputed_data_;
    119119    u_int neighbours_;
    120120    std::vector<size_t> not_imputed_;
    121     const gslapi::matrix& weight_;
     121    const utility::matrix& weight_;
    122122  };
    123123
  • trunk/c++_tools/utility/PCA.cc

    r420 r616  
    1010
    1111namespace theplu {
    12 namespace utility { 
     12namespace utility {
    1313
    1414
    15 void PCA::process()
    16 {
    17   process_ = true;
    18   // Row-center the data matrix
    19   gslapi::matrix A_center( A_.rows(), A_.columns() );
    20   this->row_center( A_center );
    21  
     15  void PCA::process(void)
     16  {
     17    process_ = true;
     18    // Row-center the data matrix
     19    utility::matrix A_center( A_.rows(), A_.columns() );
     20    this->row_center( A_center );
    2221
    23   // Single value decompose the data matrix
    24   std::auto_ptr<SVD> pSVD( new SVD( A_center ) );
    25   pSVD->decompose();
    26   gslapi::matrix U = pSVD->U();
    27   gslapi::matrix V = pSVD->V();
     22    // Single value decompose the data matrix
     23    std::auto_ptr<SVD> pSVD( new SVD( A_center ) );
     24    pSVD->decompose();
     25    utility::matrix U = pSVD->U();
     26    utility::matrix V = pSVD->V();
    2827
    29   // Read the eigenvectors and eigenvalues
    30   eigenvectors_ = U;
    31   eigenvectors_ .transpose();
    32   eigenvalues_ = pSVD->s();
     28    // Read the eigenvectors and eigenvalues
     29    eigenvectors_ = U;
     30    eigenvectors_ .transpose();
     31    eigenvalues_ = pSVD->s();
    3332
    34   // T
    35   for( size_t i = 0; i < eigenvalues_.size(); ++i )
    36     {
    37      eigenvalues_[ i ] = eigenvalues_[ i ]*eigenvalues_[ i ];
    38     }
     33    // T
     34    for( size_t i = 0; i < eigenvalues_.size(); ++i )
     35      eigenvalues_[ i ] = eigenvalues_[ i ]*eigenvalues_[ i ];
     36    eigenvalues_ *= 1.0/A_center.rows();
    3937
    40   eigenvalues_ *= 1.0/A_center.rows(); 
    41  
    42   // Sort the eigenvectors in order of eigenvalues
    43   // Simple (not efficient) algorithm that always
    44   // make sure that the i:th element is in its correct
    45   // position (N element --> Ordo( N*N ))
    46   for ( size_t i = 0; i < eigenvalues_.size(); ++i )
    47     for ( size_t j = i + 1; j < eigenvalues_.size(); ++j )
    48       if ( eigenvalues_[ j ] > eigenvalues_[ i ] ) {
    49         std::swap( eigenvalues_[ i ], eigenvalues_[ j ] );
    50         eigenvectors_.swap_rows(i,j);
    51       }
    52 }
     38    // Sort the eigenvectors in order of eigenvalues
     39    // Simple (not efficient) algorithm that always
     40    // make sure that the i:th element is in its correct
     41    // position (N element --> Ordo( N*N ))
     42    for ( size_t i = 0; i < eigenvalues_.size(); ++i )
     43      for ( size_t j = i + 1; j < eigenvalues_.size(); ++j )
     44        if ( eigenvalues_[ j ] > eigenvalues_[ i ] ) {
     45          std::swap( eigenvalues_[ i ], eigenvalues_[ j ] );
     46          eigenvectors_.swap_rows(i,j);
     47        }
     48  }
    5349
    5450
     51  void PCA::process_transposed_problem(void)
     52  {
     53    process_ = true;
     54    // Row-center the data matrix
     55    utility::matrix A_center( A_.rows(), A_.columns() );
     56    this->row_center( A_center );
    5557
    56 void PCA::process_transposed_problem()
    57 {
    58   process_ = true;
    59   // Row-center the data matrix
    60   gslapi::matrix A_center( A_.rows(), A_.columns() );
    61   this->row_center( A_center );
     58    // Transform into SVD friendly dimension
     59    A_.transpose();
     60    A_center.transpose();
    6261
    63   // Transform into SVD friendly dimension
    64   ////////////////////////////////////////
    65   A_.transpose();
    66   A_center.transpose();
     62    // Single value decompose the data matrix
     63    std::auto_ptr<SVD> pSVD( new SVD( A_center ) );
     64    pSVD->decompose();
     65    utility::matrix U = pSVD->U();
     66    utility::matrix V = pSVD->V();
    6767
    68   // Single value decompose the data matrix
    69   std::auto_ptr<SVD> pSVD( new SVD( A_center ) );
    70   pSVD->decompose();
    71   gslapi::matrix U = pSVD->U();
    72   gslapi::matrix V = pSVD->V();
     68    // Read the eigenvectors and eigenvalues
     69    eigenvectors_=V;
     70    eigenvectors_.transpose();
     71    eigenvalues_ = pSVD->s();
    7372
    74   // Read the eigenvectors and eigenvalues
    75   eigenvectors_=V;
    76   eigenvectors_.transpose();
    77   eigenvalues_ = pSVD->s();
     73    // Transform back when done with SVD!
     74    // (used V insted of U now for eigenvectors)
     75    A_.transpose();
     76    A_center.transpose();
    7877
    79   // Transform back when done with SVD!
    80   // (used V insted of U now for eigenvectors)
    81   ////////////////////////////////////////////
    82   A_.transpose();
    83   A_center.transpose();
     78    // T
     79    for( size_t i = 0; i < eigenvalues_.size(); ++i )
     80      eigenvalues_[ i ] = eigenvalues_[ i ]*eigenvalues_[ i ];
     81    eigenvalues_ *= 1.0/A_center.rows();
    8482
    85   // T
    86   for( size_t i = 0; i < eigenvalues_.size(); ++i )
    87     {
    88      eigenvalues_[ i ] = eigenvalues_[ i ]*eigenvalues_[ i ];
    89     }
    90 
    91   eigenvalues_ *= 1.0/A_center.rows(); 
    92  
    93   // Sort the eigenvectors in order of eigenvalues
    94   // Simple (not efficient) algorithm that always
    95   // make sure that the i:th element is in its correct
    96   // position (N element --> Ordo( N*N ))
    97   for ( size_t i = 0; i < eigenvalues_.size(); ++i )
    98     for ( size_t j = i + 1; j < eigenvalues_.size(); ++j )
    99       if ( eigenvalues_[ j ] > eigenvalues_[ i ] ) {
    100         std::swap( eigenvalues_[ i ], eigenvalues_[ j ] );
    101         eigenvectors_.swap_rows(i,j);
    102       }
    103 }
     83    // Sort the eigenvectors in order of eigenvalues
     84    // Simple (not efficient) algorithm that always
     85    // make sure that the i:th element is in its correct
     86    // position (N element --> Ordo( N*N ))
     87    for ( size_t i = 0; i < eigenvalues_.size(); ++i )
     88      for ( size_t j = i + 1; j < eigenvalues_.size(); ++j )
     89        if ( eigenvalues_[ j ] > eigenvalues_[ i ] ) {
     90          std::swap( eigenvalues_[ i ], eigenvalues_[ j ] );
     91          eigenvectors_.swap_rows(i,j);
     92        }
     93  }
    10494
    10595
    106 
    107 // This function will row-center the matrix A_,
    108 // that is, A_ = A_ - M, where M is a matrix
    109 // with the meanvalues of each row
    110 void PCA::row_center( gslapi::matrix& A_center )
    111 {
    112   meanvalues_ = gslapi::vector( A_.rows() );
    113   gslapi::vector A_row_sum(A_.rows());
    114   for (size_t i=0; i<A_row_sum.size(); ++i)
    115     A_row_sum(i)=gslapi::vector(A_,i).sum();
    116   for( size_t i = 0; i < A_center.rows(); ++i )
    117     {
    118      meanvalues_[i] = A_row_sum(i) / static_cast<double>(A_.columns());
    119      for( size_t j = 0; j < A_center.columns(); ++j )
    120        A_center(i,j) = A_(i,j) - meanvalues_(i);
    121     }
    122 }
     96  // This function will row-center the matrix A_,
     97  // that is, A_ = A_ - M, where M is a matrix
     98  // with the meanvalues of each row
     99  void PCA::row_center(utility::matrix& A_center)
     100  {
     101    meanvalues_ = utility::vector( A_.rows() );
     102    utility::vector A_row_sum(A_.rows());
     103    for (size_t i=0; i<A_row_sum.size(); ++i)
     104      A_row_sum(i)=utility::vector(A_,i).sum();
     105    for( size_t i = 0; i < A_center.rows(); ++i ) {
     106      meanvalues_[i] = A_row_sum(i) / static_cast<double>(A_.columns());
     107      for( size_t j = 0; j < A_center.columns(); ++j )
     108        A_center(i,j) = A_(i,j) - meanvalues_(i);
     109    }
     110  }
    123111
    124112
     113  utility::matrix PCA::projection(const utility::matrix& samples ) const
     114  {
     115    const size_t Ncol = samples.columns();
     116    const size_t Nrow = samples.rows();
     117    utility::matrix projs( Ncol, Ncol );
    125118
    126 gslapi::matrix PCA::projection( const gslapi::matrix&
    127               samples ) const
    128 {
    129   const size_t Ncol = samples.columns();
    130   const size_t Nrow = samples.rows();
    131   gslapi::matrix projs( Ncol, Ncol );
    132  
    133   gslapi::vector temp(samples.rows());
    134   for( size_t j = 0; j < Ncol; ++j )
    135     {
     119    utility::vector temp(samples.rows());
     120    for( size_t j = 0; j < Ncol; ++j ) {
    136121      for (size_t i=0; i<Ncol; ++i )
    137         temp(i) = samples(i,j);   
    138      gslapi::vector centered( Nrow );
    139 
    140      for( size_t i = 0; i < Nrow; ++i )
    141        centered(i) = temp(i) - meanvalues_(i);
    142 
    143      gslapi::vector proj( eigenvectors_ * centered );
    144       for( size_t i = 0; i < Ncol; ++i )
     122        temp(i) = samples(i,j);
     123      utility::vector centered( Nrow );
     124      for( size_t i = 0; i < Nrow; ++i )
     125        centered(i) = temp(i) - meanvalues_(i);
     126      utility::vector proj( eigenvectors_ * centered );
     127      for( size_t i = 0; i < Ncol; ++i )
    145128        projs(i,j)=proj(i);
    146     } 
    147   return projs;
    148 }
     129    }
     130    return projs;
     131  }
    149132
    150133
     134  utility::matrix
     135  PCA::projection_transposed(const utility::matrix& samples) const
     136  {
     137    const size_t Ncol = samples.columns();
     138    const size_t Nrow = samples.rows();
     139    utility::matrix projs( Nrow, Ncol );
    151140
    152 gslapi::matrix PCA::projection_transposed( const gslapi::matrix&
    153              samples ) const
    154 {
    155   const size_t Ncol = samples.columns();
    156   const size_t Nrow = samples.rows();
    157   gslapi::matrix projs( Nrow, Ncol );
    158  
    159   gslapi::vector temp(samples.rows());
    160   for( size_t j = 0; j < Ncol; ++j )
    161     {
     141    utility::vector temp(samples.rows());
     142    for( size_t j = 0; j < Ncol; ++j ) {
    162143      for (size_t i=0; i<Ncol; ++i )
    163         temp(i) = samples(i,j);   
    164      gslapi::vector centered( Nrow );
    165 
    166      for( size_t i = 0; i < Nrow; ++i )
    167        centered(i)=temp(i)-meanvalues_(i);
    168 
    169      gslapi::vector proj( eigenvectors_ * centered );
    170      for( size_t i = 0; i < Nrow; ++i )
    171        projs(i,j)=proj(i);
    172     }
    173   return projs;
    174 }
     144        temp(i) = samples(i,j);
     145      utility::vector centered( Nrow );
     146      for( size_t i = 0; i < Nrow; ++i )
     147        centered(i)=temp(i)-meanvalues_(i);
     148      utility::vector proj( eigenvectors_ * centered );
     149      for( size_t i = 0; i < Nrow; ++i )
     150        projs(i,j)=proj(i);
     151    }
     152    return projs;
     153  }
    175154
    176155
    177 
    178 void PCA::calculate_explained_intensity()
    179 {
    180   size_t DIM = eigenvalues_.size();
    181   explained_intensity_ = gslapi::vector( DIM );
    182   double sum = 0;
    183   for( size_t i = 0; i < DIM; ++i )
    184     {
    185      sum += eigenvalues_[ i ];
    186     }
    187   double exp_sum = 0;
    188   for( size_t i = 0; i < DIM; ++i )
    189     {
    190      exp_sum += eigenvalues_[ i ];
    191      explained_intensity_[ i ] = exp_sum / sum ;
    192     } 
    193 }
     156  void PCA::calculate_explained_intensity(void)
     157  {
     158    size_t DIM = eigenvalues_.size();
     159    explained_intensity_ = utility::vector( DIM );
     160    double sum = 0;
     161    for( size_t i = 0; i < DIM; ++i )
     162      sum += eigenvalues_[ i ];
     163    double exp_sum = 0;
     164    for( size_t i = 0; i < DIM; ++i ) {
     165      exp_sum += eigenvalues_[ i ];
     166      explained_intensity_[ i ] = exp_sum / sum ;
     167    }
     168  }
    194169
    195170
    196 
    197 double PCA::get_explained_intensity( const size_t& k )
    198 {
    199   if( !explained_calc_ )
    200     {
    201      this->calculate_explained_intensity();
    202      explained_calc_ = true;
    203     }
    204   return explained_intensity_[ k ];
    205 }
     171  double PCA::get_explained_intensity( const size_t& k )
     172  {
     173    if( !explained_calc_ ) {
     174      this->calculate_explained_intensity();
     175      explained_calc_ = true;
     176    }
     177    return explained_intensity_[ k ];
     178  }
    206179
    207180
  • trunk/c++_tools/utility/PCA.h

    r420 r616  
    1 // $Id$
    2 
    31#ifndef _theplu_utility_pca_
    42#define _theplu_utility_pca_
    53
    6 #include <c++_tools/gslapi/matrix.h>
    7 #include <c++_tools/gslapi/vector.h>
     4// $Id$
     5
     6#include <c++_tools/utility/matrix.h>
     7#include <c++_tools/utility/vector.h>
    88
    99
     
    3434       should have been performed and no products.
    3535     */
    36     inline explicit PCA(const gslapi::matrix& A)
     36    inline explicit PCA(const utility::matrix& A)
    3737      : A_(A), process_(false), explained_calc_(false) {}
    3838
     
    5959       @return Eigenvector \a i.
    6060    */
    61     inline gslapi::vector get_eigenvector(const size_t& i) const
    62       { return gslapi::vector(eigenvectors_,i); }
     61    inline utility::vector get_eigenvector(const size_t& i) const
     62      { return utility::vector(eigenvectors_,i); }
    6363
    6464    /**
     
    8383       spanned by the eigenvectors.
    8484    */
    85     gslapi::matrix projection( const gslapi::matrix& ) const;
     85    utility::matrix projection( const utility::matrix& ) const;
    8686
    8787    /**
     
    8989       process_transposed_problem().
    9090    */
    91     gslapi::matrix projection_transposed( const gslapi::matrix& ) const;
     91    utility::matrix projection_transposed( const utility::matrix& ) const;
    9292
    9393
    9494  private:
    95     gslapi::matrix  A_;
    96     gslapi::matrix  eigenvectors_;
    97     gslapi::vector  eigenvalues_;
    98     gslapi::vector  explained_intensity_;
    99     gslapi::vector  meanvalues_;
     95    utility::matrix A_;
     96    utility::matrix eigenvectors_;
     97    utility::vector eigenvalues_;
     98    utility::vector explained_intensity_;
     99    utility::vector meanvalues_;
    100100    bool process_, explained_calc_;
    101101   
     
    105105       with the meanvalues of each row
    106106    */
    107     void row_center( gslapi::matrix& A_center );
     107    void row_center( utility::matrix& A_center );
    108108
    109109    /**
  • trunk/c++_tools/utility/SVD.cc

    r420 r616  
    1717        case Jacobi:
    1818          return jacobi();
    19     }
     19    }
    2020    // the program should never end up here, return values should be
    2121    // something different from normal GSL return values, or maybe
     
    2828  int SVD::golub_reinsch(void)
    2929  {
    30     gslapi::vector w(U_.columns());
     30    utility::vector w(U_.columns());
    3131    return gsl_linalg_SV_decomp(U_.gsl_matrix_p(), V_.gsl_matrix_p(),
    3232                                s_.gsl_vector_p(), w.gsl_vector_p());
     
    3737  int SVD::modified_golub_reinsch(void)
    3838  {
    39     gslapi::vector w(U_.columns());
    40     gslapi::matrix X(U_.columns(),U_.columns());
     39    utility::vector w(U_.columns());
     40    utility::matrix X(U_.columns(),U_.columns());
    4141    return gsl_linalg_SV_decomp_mod(U_.gsl_matrix_p(), X.gsl_matrix_p(),
    4242                                    V_.gsl_matrix_p(), s_.gsl_vector_p(),
  • trunk/c++_tools/utility/SVD.h

    r597 r616  
    1 // $Id$
    2 
    31#ifndef _theplu_utility_svd_
    42#define _theplu_utility_svd_
    53
    6 #include <c++_tools/gslapi/matrix.h>
    7 #include <c++_tools/gslapi/vector.h>
     4// $Id$
     5
     6#include <c++_tools/utility/matrix.h>
     7#include <c++_tools/utility/vector.h>
    88
    99#include <gsl/gsl_linalg.h>
     
    5252    /// input matrix is copied for further use in the object.
    5353    ///
    54     inline SVD(const gslapi::matrix& Ain)
     54    inline SVD(const utility::matrix& Ain)
    5555      : U_(Ain), V_(Ain.columns(),Ain.columns()), s_(Ain.columns()) {}
    5656
     
    7373    /// is undefined.
    7474    ///
    75     inline const gslapi::vector& s(void) const { return s_; }
     75    inline const utility::vector& s(void) const { return s_; }
    7676
    7777    ///
     
    8383    /// @return Whatever GSL returns.
    8484    ///
    85     inline int solve(gslapi::vector b, gslapi::vector x)
     85    inline int solve(utility::vector b, utility::vector x)
    8686      { return gsl_linalg_SV_solve(U_.gsl_matrix_p(), V_.gsl_matrix_p(),
    8787                                   s_.gsl_vector_p(), b.gsl_vector_p(),
     
    9696    /// is undefined.
    9797    ///
    98     inline const gslapi::matrix& U(void) const { return U_; }
     98    inline const utility::matrix& U(void) const { return U_; }
    9999
    100100    ///
     
    106106    /// is undefined.
    107107    ///
    108     inline const gslapi::matrix& V(void) const { return V_; }
     108    inline const utility::matrix& V(void) const { return V_; }
    109109
    110110  private:
     
    115115    int modified_golub_reinsch(void);
    116116
    117     gslapi::matrix U_, V_;
    118     gslapi::vector s_;
     117    utility::matrix U_, V_;
     118    utility::vector s_;
    119119  }; 
    120120
  • trunk/c++_tools/utility/WeNNI.cc

    r570 r616  
    2727#include <c++_tools/utility/WeNNI.h>
    2828
     29#include <c++_tools/utility/matrix.h>
    2930#include <c++_tools/utility/stl_utility.h>
    3031
     
    3738
    3839
    39   WeNNI::WeNNI(const gslapi::matrix& matrix,const gslapi::matrix& flag,
     40  WeNNI::WeNNI(const utility::matrix& matrix,const utility::matrix& flag,
    4041               const u_int neighbours)
    4142    : NNI(matrix,flag,neighbours), imputed_data_raw_(matrix)
     
    5253  u_int WeNNI::estimate(void)
    5354  {
    54     using namespace std;
    5555    for (unsigned int i=0; i<data_.rows(); i++) {
    5656      // Jari, avoid copying in next line
    57       vector<pair<u_int,double> > distance=calculate_distances(i);
    58       sort(distance.begin(),distance.end(),
     57      std::vector<std::pair<u_int,double> > distance=calculate_distances(i);
     58      std::sort(distance.begin(),distance.end(),
    5959                pair_value_compare<u_int,double>());
    6060      bool row_imputed=true;
    6161      for (unsigned int j=0; j<data_.columns(); j++) {
    62         vector<u_int> knn=nearest_neighbours(j,distance);
     62        std::vector<u_int> knn=nearest_neighbours(j,distance);
    6363        double new_value=0.0;
    6464        double norm=0.0;
    65         for (vector<u_int>::const_iterator k=knn.begin(); k!=knn.end(); k++) {
     65        for (std::vector<u_int>::const_iterator k=knn.begin(); k!=knn.end();
     66             ++k) {
    6667          // Jari, a small number needed here, use something standardized.
    6768          // Avoid division with zero (perfect match vectors)
  • trunk/c++_tools/utility/WeNNI.h

    r570 r616  
     1#ifndef _theplu_utility_wenni_
     2#define _theplu_utility_wenni_
     3
    14// $Id$
    25
     
    2528*/
    2629
    27 #ifndef _theplu_utility_wenni_
    28 #define _theplu_utility_wenni_
    29 
    3030#include <c++_tools/utility/NNI.h>
    3131
    32 #include <c++_tools/gslapi/matrix.h>
     32#include <c++_tools/utility/matrix.h>
    3333
    3434#include <iostream>
     
    5454    /// Constructor
    5555    ///
    56     WeNNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,
     56    WeNNI(const utility::matrix& matrix,const utility::matrix& weight,
    5757          const u_int neighbours);
    5858
     
    6767    /// @return A const reference to imputed_data_raw.
    6868    ///
    69     const gslapi::matrix& imputed_data_raw(void) const
     69    const utility::matrix& imputed_data_raw(void) const
    7070    { return imputed_data_raw_; }
    7171
     
    7474  private:
    7575
    76     gslapi::matrix imputed_data_raw_;
     76    utility::matrix imputed_data_raw_;
    7777  };
    7878
  • trunk/c++_tools/utility/kNNI.cc

    r570 r616  
    3737namespace utility {
    3838
    39   kNNI::kNNI(const gslapi::matrix& matrix,const gslapi::matrix& flag,
     39  kNNI::kNNI(const utility::matrix& matrix,const utility::matrix& flag,
    4040             const u_int neighbours)
    4141    : NNI(matrix,flag,neighbours)
     
    5858  u_int kNNI::estimate(void)
    5959  {
    60     using namespace std;
    6160    for (unsigned int i=0; i<mv_rows_.size(); i++) {
    6261      // Jari, avoid copying in next line
    63       vector<pair<u_int,double> > distance=calculate_distances(mv_rows_[i]);
    64       sort(distance.begin(),distance.end(),
     62      std::vector<std::pair<u_int,double> > distance=
     63        calculate_distances(mv_rows_[i]);
     64      std::sort(distance.begin(),distance.end(),
    6565                pair_value_compare<u_int,double>());
    6666      for (unsigned int j=0; j<data_.columns(); j++)
    6767        if (!weight_(mv_rows_[i],j)) {
    68           vector<u_int> knn=nearest_neighbours(j,distance);
     68          std::vector<u_int> knn=nearest_neighbours(j,distance);
    6969          double new_value=0.0;
    7070          double norm=0.0;
    71           for (vector<u_int>::const_iterator k=knn.begin(); k!=knn.end(); k++){
     71          for (std::vector<u_int>::const_iterator k=knn.begin(); k!=knn.end();
     72               ++k) {
    7273            // Jari, a small number needed here, use something standardized.
    7374            // Avoid division with zero (perfect match vectors)
  • trunk/c++_tools/utility/kNNI.h

    r570 r616  
     1#ifndef _theplu_utility_knni_
     2#define _theplu_utility_knni_
     3
    14// $Id$
    25
     
    2528*/
    2629
    27 #ifndef _theplu_utility_knni_
    28 #define _theplu_utility_knni_
    29 
    3030#include <c++_tools/utility/NNI.h>
    3131
     
    5252    /// Constructor
    5353    ///
    54     kNNI(const gslapi::matrix& matrix,const gslapi::matrix& weight,
     54    kNNI(const utility::matrix& matrix,const utility::matrix& weight,
    5555         const u_int neighbours);
    5656
  • trunk/c++_tools/utility/matrix.cc

    r613 r616  
    2525*/
    2626
    27 #include <c++_tools/gslapi/matrix.h>
    28 
    29 #include <c++_tools/gslapi/vector.h>
     27#include <c++_tools/utility/matrix.h>
     28
     29#include <c++_tools/utility/vector.h>
    3030#include <c++_tools/utility/stl_utility.h>
    3131#include <c++_tools/utility/utility.h>
     
    3939
    4040namespace theplu {
    41 namespace gslapi {
     41namespace utility {
    4242
    4343
     
    242242
    243243
    244 }} // of namespace gslapi and namespace thep
     244}} // of namespace utility and namespace thep
  • trunk/c++_tools/utility/matrix.h

    r614 r616  
     1#ifndef _theplu_utility_matrix_
     2#define _theplu_utility_matrix_
     3
    14// $Id$
    25
     
    2629*/
    2730
    28 #ifndef _theplu_gslapi_matrix_
    29 #define _theplu_gslapi_matrix_
    30 
    31 #include <c++_tools/gslapi/vector.h>
     31#include <c++_tools/utility/vector.h>
    3232#include <c++_tools/utility/Exception.h>
    3333
     
    3636
    3737namespace theplu {
    38 namespace gslapi {
     38namespace utility {
    3939
    4040  class vector;
     
    5151  ///
    5252  /// \par[Matrix views] GSL matrix views are supported and these are
    53   /// disguised as ordinary gslapi::matrix'es. A support function is
    54   /// added, gslapi::matrix::isview(), that can be used to check if a
     53  /// disguised as ordinary utility::matrix'es. A support function is
     54  /// added, utility::matrix::isview(), that can be used to check if a
    5555  /// matrix object is a view. Note that view matricess do not own the
    5656  /// undelying data, and a view is not valid if the matrix owning the
     
    6161  /// this interface class. Most notable GSL functionality not
    6262  /// supported are no binary file support and views on arrays,
    63   /// gslapi::vectors, gsl_vectors, diagonals, subdiagonals, and
     63  /// utility::vectors, gsl_vectors, diagonals, subdiagonals, and
    6464  /// superdiagonals. If there is an interest from the user community,
    6565  /// the omitted functionality could be included.
     
    464464
    465465
    466 }} // of namespace gslapi and namespace theplu
     466}} // of namespace utility and namespace theplu
    467467
    468468#endif
  • trunk/c++_tools/utility/utility.cc

    r609 r616  
    2626#include <c++_tools/utility/utility.h>
    2727
     28#include <c++_tools/random/random.h>
    2829#include <c++_tools/utility/stl_utility.h>
     30#include <c++_tools/utility/vector.h>
    2931
    3032#include <sstream>
     
    8890  }
    8991
     92
     93  std::pair<size_t, size_t> minmax_index(const vector& vec,
     94                                         const std::vector<size_t>& subset)
     95  {
     96    size_t min_index = subset[0];
     97    size_t max_index = subset[0];
     98    for (unsigned int i=1; i<subset.size(); i++)
     99      if (vec[subset[i]] < vec[min_index])
     100        min_index = subset[i];
     101      else if (vec[subset[i]] > vec[max_index])
     102        max_index = subset[i];
     103    return std::pair<size_t,size_t>(min_index, max_index);
     104  }
     105
     106
     107  void shuffle(vector& invec)
     108  {
     109    vector vec(invec);
     110    random::DiscreteUniform rnd;
     111    for (size_t i=0; i<vec.size(); i++){
     112      size_t index = rnd(vec.size()-i);
     113      invec[i]=vec(index);
     114      vec(index)=vec(vec.size()-i-1);
     115    }
     116  }
     117
     118
    90119}} // end of namespace utility and namespace thep
  • trunk/c++_tools/utility/utility.h

    r570 r616  
     1#ifndef _theplu_utility_utility_
     2#define _theplu_utility_utility_
     3
    14// $Id$
    25
     
    2427*/
    2528
    26 #ifndef _theplu_utility_utility_
    27 #define _theplu_utility_utility_
    28 
    2929///
    3030/// @file utility/utility.h
     
    3434
    3535#include <string>
     36#include <utility>
     37#include <vector>
    3638
    3739namespace theplu {
    3840namespace utility {
    3941
     42  class vector;
    4043
    4144  ///
     
    6063  bool is_nan(const std::string& s);
    6164
     65  /**
     66     This function returns the indices of the minimum and maximum
     67     values in the sub-vector (defined by \a subset), storing them in
     68     imin and imax. When there are several equal minimum or maximum
     69     elements then the lowest indices are returned. The returned index
     70     is the index from the complete vector (not the sub-vector)
     71
     72     @return Index corresponding to the smallest and largest value.
     73
     74     @note If \a subset is emtpy, the result is undefined.
     75  */
     76  std::pair<size_t,size_t> minmax_index(const vector& vec,
     77                                        const std::vector<size_t>& subset);
     78
     79  /**
     80     Randomly shuffles the elements in vector \a invec
     81  */
     82  void shuffle(vector& invec);
     83
     84
    6285}} // of namespace utility and namespace theplu
    6386
  • trunk/c++_tools/utility/vector.cc

    r613 r616  
    2626*/
    2727
    28 #include <c++_tools/gslapi/vector.h>
    29 #include <c++_tools/gslapi/matrix.h>
     28#include <c++_tools/utility/vector.h>
     29#include <c++_tools/utility/matrix.h>
    3030#include <c++_tools/utility/stl_utility.h>
    3131#include <c++_tools/utility/utility.h>
     
    3939
    4040namespace theplu {
    41 namespace gslapi {
     41namespace utility {
    4242
    4343
     
    265265
    266266
    267 }} // of namespace gslapi and namespace thep
     267}} // of namespace utility and namespace thep
  • trunk/c++_tools/utility/vector.h

    r613 r616  
     1#ifndef _theplu_utility_vector_
     2#define _theplu_utility_vector_
     3
    14// $Id$
    25
     
    2629*/
    2730
    28 #ifndef _theplu_gslapi_vector_
    29 #define _theplu_gslapi_vector_
    30 
    3131#include <c++_tools/utility/Exception.h>
    3232
     
    3939
    4040namespace theplu {
    41 namespace gslapi {
     41namespace utility {
    4242
    4343  class matrix;
     
    5454  ///
    5555  /// \par[Vector views] GSL vector views are supported and these are
    56   /// disguised as ordinary gslapi::vectors. A support function is
    57   /// added, gslapi::vector::isview(), that can be used to check if a
     56  /// disguised as ordinary utility::vectors. A support function is
     57  /// added, utility::vector::isview(), that can be used to check if a
    5858  /// vector object is a view. Note that view vectors do not own the
    5959  /// undelying data, and a view is not valid if the vector owning the
     
    491491
    492492
    493 }} // of namespace gslapi and namespace theplu
     493}} // of namespace utility and namespace theplu
    494494
    495495#endif
Note: See TracChangeset for help on using the changeset viewer.