Changeset 1121 for trunk/yat/classifier


Ignore:
Timestamp:
Feb 22, 2008, 4:29:56 PM (13 years ago)
Author:
Peter
Message:

fixes #308

Location:
trunk/yat/classifier
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/DataLookup1D.cc

    r1120 r1121  
    2828#include "MatrixLookup.h"
    2929
    30 #include "yat/utility/matrix.h"
     30#include "yat/utility/Matrix.h"
    3131#include "yat/utility/Vector.h"
    3232
     
    6666    : column_vector_(true), index_(0), owner_(true)
    6767  {
    68     utility::matrix* m = new utility::matrix(1,index.size());
     68    utility::Matrix* m = new utility::Matrix(1,index.size());
    6969    for (size_t i=0; i<index.size(); ++i){
    7070      assert(index[i]<v.size());
     
    7878    : column_vector_(false), index_(0), owner_(true)
    7979  {
    80     utility::matrix* m = new utility::matrix(1,v.size());
     80    utility::Matrix* m = new utility::Matrix(1,v.size());
    8181    for (size_t i=0; i<v.size(); ++i){
    8282      (*m)(0,i)=v(i);
  • trunk/yat/classifier/EnsembleBuilder.h

    r1088 r1121  
    3131#include "SubsetGenerator.h"
    3232#include "yat/statistics/Averager.h"
     33#include "yat/utility/Matrix.h"
    3334
    3435#include <vector>
     
    177178      result.push_back(std::vector<statistics::Averager>(data.columns()));
    178179   
    179     utility::matrix prediction; 
     180    utility::Matrix prediction; 
    180181
    181182    for(u_long k=0;k<subset_->size();++k) {       
     
    203204      validation_result_.push_back(std::vector<statistics::Averager>(subset_->target().size()));
    204205   
    205     utility::matrix prediction; 
     206    utility::Matrix prediction; 
    206207    for(u_long k=0;k<subset_->size();k++) {
    207208      classifier(k).predict(subset_->validation_data(k),prediction);
  • trunk/yat/classifier/KNN.h

    r1115 r1121  
    3232#include "SupervisedClassifier.h"
    3333#include "Target.h"
    34 #include "yat/utility/matrix.h"
     34#include "yat/utility/Matrix.h"
    3535#include "yat/utility/yat_assert.h"
    3636
     
    107107    ///
    108108    ///
    109     void predict(const DataLookup2D&, utility::matrix&) const;
     109    void predict(const DataLookup2D&, utility::Matrix&) const;
    110110
    111111
     
    129129    /// generated and needs to be deleted by the caller.
    130130    ///
    131     utility::matrix* calculate_distances(const DataLookup2D&) const;
     131    utility::Matrix* calculate_distances(const DataLookup2D&) const;
    132132
    133133    void calculate_unweighted(const MatrixLookup&,
    134134                              const MatrixLookup&,
    135                               utility::matrix*) const;
     135                              utility::Matrix*) const;
    136136    void calculate_weighted(const MatrixLookupWeighted&,
    137137                            const MatrixLookupWeighted&,
    138                             utility::matrix*) const;
     138                            utility::Matrix*) const;
    139139  };
    140140 
     
    162162 
    163163  template <typename Distance, typename NeighborWeighting>
    164   utility::matrix* KNN<Distance, NeighborWeighting>::calculate_distances
     164  utility::Matrix* KNN<Distance, NeighborWeighting>::calculate_distances
    165165  (const DataLookup2D& test) const
    166166  {
    167167    // matrix with training samples as rows and test samples as columns
    168     utility::matrix* distances =
    169       new utility::matrix(data_.columns(),test.columns());
     168    utility::Matrix* distances =
     169      new utility::Matrix(data_.columns(),test.columns());
    170170   
    171171   
     
    210210  void  KNN<Distance, NeighborWeighting>::calculate_unweighted
    211211  (const MatrixLookup& training, const MatrixLookup& test,
    212    utility::matrix* distances) const
     212   utility::Matrix* distances) const
    213213  {
    214214    for(size_t i=0; i<training.columns(); i++) {
     
    226226  KNN<Distance, NeighborWeighting>::calculate_weighted
    227227  (const MatrixLookupWeighted& training, const MatrixLookupWeighted& test,
    228    utility::matrix* distances) const
     228   utility::Matrix* distances) const
    229229  {
    230230    for(size_t i=0; i<training.columns(); i++) {
     
    295295  template <typename Distance, typename NeighborWeighting>
    296296  void KNN<Distance, NeighborWeighting>::predict(const DataLookup2D& test,
    297                                                  utility::matrix& prediction) const
     297                                                 utility::Matrix& prediction) const
    298298  {   
    299299    utility::yat_assert<std::runtime_error>(data_.rows()==test.rows());
    300300
    301     utility::matrix* distances=calculate_distances(test);
     301    utility::Matrix* distances=calculate_distances(test);
    302302   
    303303    prediction.resize(target_.nof_classes(),test.columns(),0.0);
  • trunk/yat/classifier/KernelLookup.cc

    r1105 r1121  
    2626#include "MatrixLookup.h"
    2727#include "MatrixLookupWeighted.h"
    28 #include "../utility/matrix.h"
     28#include "yat/utility/Matrix.h"
    2929
    3030#include <cassert>
     
    205205    assert(data.rows()==kernel_->data().rows());
    206206    if (!weighted()){
    207       utility::matrix* data_all =
    208         new utility::matrix(data.rows(), row_index_.size()+data.columns());
     207      utility::Matrix* data_all =
     208        new utility::Matrix(data.rows(), row_index_.size()+data.columns());
    209209
    210210      for (size_t i=0; i<data_all->rows(); ++i) {
     
    240240    // kernel_ holds MatrixLookupWeighted, hence new Kernel also
    241241    // should hold a MatrixLookupweighted.
    242     utility::matrix* data_all =
    243       new utility::matrix(data.rows(), rows()+data.columns());
    244     utility::matrix* weight_all =
    245       new utility::matrix(data.rows(), rows()+data.columns(), 1.0);
     242    utility::Matrix* data_all =
     243      new utility::Matrix(data.rows(), rows()+data.columns());
     244    utility::Matrix* weight_all =
     245      new utility::Matrix(data.rows(), rows()+data.columns(), 1.0);
    246246    const MatrixLookupWeighted& kernel_data =
    247247      dynamic_cast<const MatrixLookupWeighted&>(kernel_->data());
     
    281281  KernelLookup::test_kernel(const MatrixLookupWeighted& data) const
    282282  {
    283     utility::matrix* data_all =
    284       new utility::matrix(data.rows(), rows()+data.columns());
    285     utility::matrix* weight_all =
    286       new utility::matrix(data.rows(), rows()+data.columns(), 1.0);
     283    utility::Matrix* data_all =
     284      new utility::Matrix(data.rows(), rows()+data.columns());
     285    utility::Matrix* weight_all =
     286      new utility::Matrix(data.rows(), rows()+data.columns(), 1.0);
    287287
    288288    if (weighted()){
  • trunk/yat/classifier/Kernel_SEV.cc

    r1098 r1121  
    2828#include "KernelFunction.h"
    2929#include "MatrixLookup.h"
    30 #include "yat/utility/matrix.h"
     30#include "yat/utility/Matrix.h"
    3131
    3232namespace theplu {
  • trunk/yat/classifier/Kernel_SEV.h

    r1000 r1121  
    2828
    2929#include "Kernel.h"
    30 #include "yat/utility/matrix.h"
     30#include "yat/utility/Matrix.h"
    3131
    3232namespace theplu {
     
    113113    void build_kernel(void);
    114114
    115     utility::matrix kernel_matrix_;
     115    utility::Matrix kernel_matrix_;
    116116
    117117  }; // class Kernel_SEV
  • trunk/yat/classifier/MatrixLookup.cc

    r1105 r1121  
    2525
    2626#include "MatrixLookup.h"
    27 #include "yat/utility/matrix.h"
     27#include "yat/utility/Matrix.h"
    2828
    2929#include <algorithm>
     
    3535namespace classifier {
    3636
    37   MatrixLookup::MatrixLookup(const utility::matrix& data, const bool own)
     37  MatrixLookup::MatrixLookup(const utility::Matrix& data, const bool own)
    3838    : DataLookup2D(own), data_(&data)
    3939  {
     
    4848
    4949
    50   MatrixLookup::MatrixLookup(const utility::matrix& data,
     50  MatrixLookup::MatrixLookup(const utility::Matrix& data,
    5151                             const std::vector<size_t>& row,
    5252                             const std::vector<size_t>& col)
     
    6363
    6464
    65   MatrixLookup::MatrixLookup(const utility::matrix& data,
     65  MatrixLookup::MatrixLookup(const utility::Matrix& data,
    6666                             const std::vector<size_t>& index,
    6767                             const bool row)
     
    136136    : DataLookup2D(rows,columns)
    137137  {
    138     data_ = new utility::matrix(1,1,value);
     138    data_ = new utility::Matrix(1,1,value);
    139139    ref_count_= new u_int(1);
    140140  }
     
    144144    : DataLookup2D()
    145145  {
    146     data_ = new utility::matrix(is,sep);
     146    data_ = new utility::Matrix(is,sep);
    147147    ref_count_= new u_int(1);
    148148    for(size_t i=0;i<(*data_).rows();i++)
  • trunk/yat/classifier/MatrixLookup.h

    r1110 r1121  
    3939
    4040namespace utility {
    41   class matrix;
     41  class Matrix;
    4242}
    4343
     
    9696    /// undefined.
    9797    ///
    98     MatrixLookup(const utility::matrix& matrix, const bool own=false);
     98    MatrixLookup(const utility::Matrix& matrix, const bool own=false);
    9999
    100100    ///
     
    111111    /// undefined.
    112112    ///
    113     MatrixLookup(const utility::matrix& matrix, const std::vector<size_t>& row,
     113    MatrixLookup(const utility::Matrix& matrix, const std::vector<size_t>& row,
    114114                 const std::vector<size_t>& column);
    115115
     
    131131    /// undefined.
    132132    ///
    133     MatrixLookup(const utility::matrix& matrix,
     133    MatrixLookup(const utility::Matrix& matrix,
    134134                 const std::vector<size_t>& index,
    135135                 const bool row_vectors);
     
    330330    friend class MatrixLookupWeighted;
    331331
    332     const utility::matrix* data_;
     332    const utility::Matrix* data_;
    333333  }; 
    334334 
  • trunk/yat/classifier/MatrixLookupWeighted.cc

    r1105 r1121  
    2525#include "MatrixLookupWeighted.h"
    2626#include "MatrixLookup.h"
    27 #include "yat/utility/matrix.h"
     27#include "yat/utility/Matrix.h"
    2828
    2929#include <algorithm>
     
    3535namespace classifier {
    3636
    37   MatrixLookupWeighted::MatrixLookupWeighted(const utility::matrix& data,
    38                                              const utility::matrix& weights,
     37  MatrixLookupWeighted::MatrixLookupWeighted(const utility::Matrix& data,
     38                                             const utility::Matrix& weights,
    3939                                             const bool own)
    4040    : DataLookup2D(own), data_(&data), weights_(&weights),
     
    5050
    5151
    52   MatrixLookupWeighted::MatrixLookupWeighted(const utility::matrix& data)
     52  MatrixLookupWeighted::MatrixLookupWeighted(const utility::Matrix& data)
    5353    : DataLookup2D(), data_(&data)
    5454  {
    55     utility::matrix weights;
     55    utility::Matrix weights;
    5656    utility::nan(*data_,weights);
    57     weights_= new utility::matrix(weights);
     57    weights_= new utility::Matrix(weights);
    5858    ref_count_weights_=new u_int(1);
    5959    for(size_t i=0;i<(*data_).rows();i++)
     
    6767    : DataLookup2D(ml), data_(ml.data_)
    6868  {
    69     weights_= new utility::matrix(data_->rows(), data_->columns(), 1.0);
     69    weights_= new utility::Matrix(data_->rows(), data_->columns(), 1.0);
    7070    ref_count_weights_=new u_int(1);
    7171    ref_count_=ml.ref_count_;
     
    7676 
    7777
    78   MatrixLookupWeighted::MatrixLookupWeighted(const utility::matrix& data,
    79                                              const utility::matrix& weights,
     78  MatrixLookupWeighted::MatrixLookupWeighted(const utility::Matrix& data,
     79                                             const utility::Matrix& weights,
    8080                                             const std::vector<size_t>& row,
    8181                                             const std::vector<size_t>& col)
     
    9999
    100100
    101   MatrixLookupWeighted::MatrixLookupWeighted(const utility::matrix& data,
    102                                              const utility::matrix& weights,
     101  MatrixLookupWeighted::MatrixLookupWeighted(const utility::Matrix& data,
     102                                             const utility::Matrix& weights,
    103103                                             const std::vector<size_t>& index,
    104104                                             const bool row)
     
    209209    : DataLookup2D(rows,columns)
    210210  {
    211     data_ = new utility::matrix(1,1,value);
     211    data_ = new utility::Matrix(1,1,value);
    212212    ref_count_=new u_int(1);
    213     weights_ = new utility::matrix(1,1,weight);
     213    weights_ = new utility::Matrix(1,1,weight);
    214214    ref_count_weights_=new u_int(1);
    215215  }
     
    219219    : DataLookup2D()
    220220  {
    221     data_ = new utility::matrix(is,sep);
     221    data_ = new utility::Matrix(is,sep);
    222222    ref_count_=new u_int(1);
    223223    for(size_t i=0;i<(*data_).rows();i++)
     
    225225    for(size_t i=0;i<(*data_).columns();i++)
    226226      column_index_.push_back(i);
    227     utility::matrix weights;
     227    utility::Matrix weights;
    228228    utility::nan(*data_,weights);
    229     weights_= new utility::matrix(weights);
     229    weights_= new utility::Matrix(weights);
    230230    ref_count_weights_=new u_int(1);
    231231  }
  • trunk/yat/classifier/MatrixLookupWeighted.h

    r1110 r1121  
    3939
    4040namespace utility {
    41   class matrix;
     41  class Matrix;
    4242}
    4343
     
    9191    /// result of further use is undefined.
    9292    ///
    93     MatrixLookupWeighted(const utility::matrix& matrix,
    94                          const utility::matrix& weights,
     93    MatrixLookupWeighted(const utility::Matrix& matrix,
     94                         const utility::Matrix& weights,
    9595                         const bool owner=false);
    9696
     
    107107    /// result of further use is undefined.
    108108    ///
    109     MatrixLookupWeighted(const utility::matrix& matrix);
     109    MatrixLookupWeighted(const utility::Matrix& matrix);
    110110
    111111
     
    140140    /// undefined.
    141141    ///
    142     MatrixLookupWeighted(const utility::matrix& matrix,
    143                          const utility::matrix& weights,
     142    MatrixLookupWeighted(const utility::Matrix& matrix,
     143                         const utility::Matrix& weights,
    144144                         const std::vector<size_t>& row,
    145145                         const std::vector<size_t>& column);
     
    163163    /// result of further use is undefined.
    164164    ///
    165     MatrixLookupWeighted(const utility::matrix& matrix,
    166                          const utility::matrix& weights,
     165    MatrixLookupWeighted(const utility::Matrix& matrix,
     166                         const utility::Matrix& weights,
    167167                         const std::vector<size_t>& index,
    168168                         const bool row_vectors);
     
    368368   
    369369  private:
    370     const utility::matrix* data_;
    371     const utility::matrix* weights_;
     370    const utility::Matrix* data_;
     371    const utility::Matrix* weights_;
    372372    u_int* ref_count_weights_;
    373373  }; 
  • trunk/yat/classifier/NBC.cc

    r1120 r1121  
    2929#include "Target.h"
    3030#include "yat/statistics/AveragerWeighted.h"
    31 #include "yat/utility/matrix.h"
     31#include "yat/utility/Matrix.h"
    3232
    3333#include <cassert>
     
    8686    sigma2_.resize(data_.rows(), target_.nof_classes());
    8787    centroids_.resize(data_.rows(), target_.nof_classes());
    88     utility::matrix nof_in_class(data_.rows(), target_.nof_classes());
     88    utility::Matrix nof_in_class(data_.rows(), target_.nof_classes());
    8989   
    9090    // unweighted
     
    144144
    145145  void NBC::predict(const DataLookup2D& x,                   
    146                     utility::matrix& prediction) const
     146                    utility::Matrix& prediction) const
    147147  {   
    148148    assert(data_.rows()==x.rows());
  • trunk/yat/classifier/NBC.h

    r1042 r1121  
    2727
    2828#include "SupervisedClassifier.h"
    29 #include "yat/utility/matrix.h"
     29#include "yat/utility/Matrix.h"
    3030
    3131namespace theplu {
     
    9999       using all weight equal to unity.
    100100    */
    101     void predict(const DataLookup2D& data, utility::matrix& res) const;
     101    void predict(const DataLookup2D& data, utility::Matrix& res) const;
    102102
    103103
    104104  private:
    105     utility::matrix centroids_;
    106     utility::matrix sigma2_;
     105    utility::Matrix centroids_;
     106    utility::Matrix sigma2_;
    107107    const DataLookup2D& data_;
    108108
  • trunk/yat/classifier/NCC.h

    r1120 r1121  
    3737#include "yat/statistics/Averager.h"
    3838#include "yat/statistics/AveragerWeighted.h"
    39 #include "yat/utility/matrix.h"
     39#include "yat/utility/Matrix.h"
    4040#include "yat/utility/Vector.h"
    4141#include "yat/utility/stl_utility.h"
     
    8181    /// @return the centroids for each class as columns in a matrix.
    8282    ///
    83     const utility::matrix& centroids(void) const;
     83    const utility::Matrix& centroids(void) const;
    8484
    8585    const DataLookup2D& data(void) const;
     
    100100    /// Calculate the distance to each centroid for test samples
    101101    ///
    102     void predict(const DataLookup2D&, utility::matrix&) const;
     102    void predict(const DataLookup2D&, utility::Matrix&) const;
    103103   
    104104   
    105105  private:
    106106
    107     void predict_unweighted(const MatrixLookup&, utility::matrix&) const;
    108     void predict_weighted(const MatrixLookupWeighted&, utility::matrix&) const;   
    109 
    110     utility::matrix* centroids_;
     107    void predict_unweighted(const MatrixLookup&, utility::Matrix&) const;
     108    void predict_weighted(const MatrixLookupWeighted&, utility::Matrix&) const;   
     109
     110    utility::Matrix* centroids_;
    111111    bool centroids_nan_;
    112112    Distance distance_;
     
    145145
    146146  template <typename Distance>
    147   const utility::matrix& NCC<Distance>::centroids(void) const
     147  const utility::Matrix& NCC<Distance>::centroids(void) const
    148148  {
    149149    return *centroids_;
     
    185185    if(centroids_)
    186186      delete centroids_;
    187     centroids_= new utility::matrix(data_.rows(), target_.nof_classes());
     187    centroids_= new utility::Matrix(data_.rows(), target_.nof_classes());
    188188    // data_ is a MatrixLookup or a MatrixLookupWeighted
    189189    if(data_.weighted()) {
     
    226226  template <typename Distance>
    227227  void NCC<Distance>::predict(const DataLookup2D& test,                     
    228                               utility::matrix& prediction) const
     228                              utility::Matrix& prediction) const
    229229  {   
    230230    utility::yat_assert<std::runtime_error>
     
    262262  template <typename Distance>
    263263  void NCC<Distance>::predict_unweighted(const MatrixLookup& test,
    264                                          utility::matrix& prediction) const
     264                                         utility::Matrix& prediction) const
    265265  {
    266266    MatrixLookup unweighted_centroids(*centroids_);
     
    277277  template <typename Distance>
    278278  void NCC<Distance>::predict_weighted(const MatrixLookupWeighted& test,
    279                                           utility::matrix& prediction) const
     279                                          utility::Matrix& prediction) const
    280280  {
    281281    MatrixLookupWeighted weighted_centroids(*centroids_);
  • trunk/yat/classifier/SVM.cc

    r1120 r1121  
    2929#include "yat/random/random.h"
    3030#include "yat/statistics/Averager.h"
    31 #include "yat/utility/matrix.h"
     31#include "yat/utility/Matrix.h"
    3232#include "yat/utility/Vector.h"
    3333
     
    139139  }
    140140
    141   void SVM::predict(const KernelLookup& input, utility::matrix& prediction) const
     141  void SVM::predict(const KernelLookup& input, utility::Matrix& prediction) const
    142142  {
    143143    assert(input.rows()==alpha_.size());
  • trunk/yat/classifier/SVM.h

    r1120 r1121  
    3636namespace theplu {
    3737namespace yat {
     38namespace utility{
     39  class Matrix;
     40}
     41
    3842namespace classifier { 
    3943
     
    133137       for training.
    134138    */
    135     void predict(const KernelLookup& input, utility::matrix& predict) const;
     139    void predict(const KernelLookup& input, utility::Matrix& predict) const;
    136140
    137141    ///
  • trunk/yat/classifier/SVindex.cc

    r1120 r1121  
    2626#include "yat/random/random.h"
    2727#include "yat/statistics/Averager.h"
    28 #include "yat/utility/matrix.h"
    2928#include "yat/utility/Vector.h"
    3029
  • trunk/yat/classifier/SupervisedClassifier.h

    r1042 r1121  
    3333
    3434  namespace utility {
    35     class matrix;
     35    class Matrix;
    3636  }
    3737
     
    8282    /// Generate output values for a data set
    8383    ///
    84     virtual void predict(const DataLookup2D&, utility::matrix&) const =0;   
     84    virtual void predict(const DataLookup2D&, utility::Matrix&) const =0;   
    8585
    8686
Note: See TracChangeset for help on using the changeset viewer.