Changeset 624 for trunk/c++_tools


Ignore:
Timestamp:
Sep 5, 2006, 4:29:39 AM (17 years ago)
Author:
Peter
Message:

fixes #109 and #110

Location:
trunk/c++_tools/classifier
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/classifier/DataLookup1D.cc

    r608 r624  
    22
    33#include <c++_tools/classifier/DataLookup1D.h>
     4#include <c++_tools/classifier/DataLookup2D.h>
    45#include <c++_tools/classifier/MatrixLookup.h>
    56
  • trunk/c++_tools/classifier/DataLookup1D.h

    r608 r624  
    1212namespace theplu {
    1313namespace classifier { 
    14 
    15   class DataLookup2D;
    1614
    1715  ///
  • trunk/c++_tools/classifier/FeatureSelector.cc

    r608 r624  
    33#include "FeatureSelector.h"
    44
    5 #include "DataLookup2D.h"
     5#include "MatrixLookup.h"
     6#include "MatrixLookupWeighted.h"
    67
    78#include <list>
     
    1920  FeatureSelector::~FeatureSelector()
    2021  {
    21     for (std::list<const DataLookup2D*>::iterator i=garbage_.begin();
     22    for (std::list<const MatrixLookup*>::iterator i=garbage_.begin();
    2223         i!=garbage_.end(); ++i)
     24      delete *i;
     25    for (std::list<const MatrixLookupWeighted*>::iterator i=
     26           garbage_weighted_.begin(); i!=garbage_weighted_.end(); ++i)
    2327      delete *i;
    2428  }
    2529
    2630
    27   const DataLookup2D& FeatureSelector::get(const DataLookup2D& data)
     31  const MatrixLookup& FeatureSelector::get(const MatrixLookup& matrix)
    2832  {
    29     garbage_.push_back(data.selected(features_));
     33    garbage_.push_back(new MatrixLookup(matrix,features_,true));
    3034    return *garbage_.back();
     35  }
     36
     37
     38  const MatrixLookupWeighted&
     39  FeatureSelector::get(const MatrixLookupWeighted& matrix)
     40  {
     41    garbage_weighted_.push_back(new MatrixLookupWeighted(matrix,features_,
     42                                                         true));
     43    return *garbage_weighted_.back();
    3144  }
    3245
  • trunk/c++_tools/classifier/FeatureSelector.h

    r608 r624  
    99namespace theplu {
    1010namespace classifier {
    11   class DataLookup2D;
     11  class MatrixLookup;
     12  class MatrixLookupWeighted;
    1213  class Target;
    1314
     
    3132
    3233    ///
    33     /// @return DataLookup containing only selected features.
     34    /// @return MatrixLookup containing only selected features.
    3435    ///
    35     const DataLookup2D& get(const DataLookup2D& data);
     36    const MatrixLookup& get(const MatrixLookup& data);
     37
     38    ///
     39    /// @return MatrixLookupWeighted containing only selected features.
     40    ///
     41    const MatrixLookupWeighted& get(const MatrixLookupWeighted& data);
    3642
    3743    ///
     
    4147
    4248    ///
    43     /// Uses @a data to select features.
     49    /// Uses @a matrix to select features.
    4450    ///
    45     virtual void update(const DataLookup2D& data, const Target& target)=0;
     51    virtual void update(const MatrixLookup& matrix, const Target& target)=0;
     52
     53    ///
     54    /// Uses @a matrix to select features.
     55    ///
     56    virtual void update(const MatrixLookupWeighted& matrix,
     57                        const Target& target)=0;
    4658
    4759  protected:
     
    5163
    5264  private:
    53     std::list<const DataLookup2D*> garbage_;
     65    std::list<const MatrixLookup*> garbage_;
     66    std::list<const MatrixLookupWeighted*> garbage_weighted_;
    5467
    5568  };
  • trunk/c++_tools/classifier/FeatureSelectorIR.cc

    r608 r624  
    3434
    3535
    36   void FeatureSelectorIR::update(const DataLookup2D& data, const Target& target)
     36  void FeatureSelectorIR::update(const MatrixLookup& data, const Target& target)
     37  {
     38    InputRanker ir = InputRanker(data, target, score_);
     39    features_.resize(N_);
     40    std::copy(ir.rank().begin()+first_, ir.rank().begin()+first_+N_,
     41              features_.begin());
     42   
     43  }
     44
     45
     46  void FeatureSelectorIR::update(const MatrixLookupWeighted& data,
     47                                 const Target& target)
    3748  {
    3849    InputRanker ir = InputRanker(data, target, score_);
  • trunk/c++_tools/classifier/FeatureSelectorIR.h

    r608 r624  
    2525    ///
    2626    ///
    27     void update(const DataLookup2D& data, const Target& target);
     27    void update(const MatrixLookup& data, const Target& target);
     28
     29    ///
     30    ///
     31    ///
     32    void update(const MatrixLookupWeighted& data, const Target& target);
    2833
    2934  private:
  • trunk/c++_tools/classifier/InputRanker.cc

    r615 r624  
    44
    55#include <c++_tools/classifier/MatrixLookup.h>
     6#include <c++_tools/classifier/MatrixLookupWeighted.h>
    67#include <c++_tools/classifier/DataLookup1D.h>
     8#include <c++_tools/classifier/DataLookupWeighted1D.h>
    79#include <c++_tools/classifier/Target.h>
    810#include <c++_tools/statistics/ROC.h>
     
    1921
    2022
    21   InputRanker::InputRanker(const DataLookup2D& data,
     23  InputRanker::InputRanker(const MatrixLookup& data,
    2224                           const Target& target,
    2325                           statistics::Score& score_object)
     
    3032    for (size_t i=0; i<nof_genes; i++) {
    3133      double area = score_object.score(target,DataLookup1D(data,i,true));
     34      // Peter, remove stupid tmp
     35      std::pair<double, size_t> tmp(area,i);
     36      score.push_back(tmp);
     37    }
     38
     39    //sort the scores and assign id_ and rank_
     40    sort(score.begin(), score.end(), std::greater<std::pair<double,size_t> >());
     41   
     42    id_.resize(nof_genes);
     43    rank_.resize(nof_genes);
     44    for (size_t i=0; i<nof_genes; i++){
     45      id_[i]=score[i].second;
     46      rank_[id_[i]]=i;           
     47    }
     48  }
     49
     50
     51
     52  InputRanker::InputRanker(const MatrixLookupWeighted& data,
     53                           const Target& target,
     54                           statistics::Score& score_object)
     55  {
     56    assert(data.columns()==target.size());
     57    size_t nof_genes = data.rows();
     58
     59    //scoring each input
     60    std::vector<std::pair<double, size_t> > score;
     61    for (size_t i=0; i<nof_genes; i++) {
     62      double area=score_object.score(target,DataLookupWeighted1D(data,i,true));
    3263      // Peter, remove stupid tmp
    3364      std::pair<double, size_t> tmp(area,i);
  • trunk/c++_tools/classifier/InputRanker.h

    r617 r624  
    1414  class DataLookup2D;
    1515  class MatrixLookup;
     16  class MatrixLookupWeighted;
    1617  class Target;
    1718
     
    2930    /// use all samples)
    3031    ///
    31     InputRanker(const DataLookup2D&, const Target&, statistics::Score&);
     32    InputRanker(const MatrixLookup&, const Target&, statistics::Score&);
     33
     34
     35    ///
     36    /// Constructor taking data, target, a Score
     37    /// object and vector defining what samples to use (default is to
     38    /// use all samples)
     39    ///
     40    InputRanker(const MatrixLookupWeighted&, const Target&,
     41                statistics::Score&);
    3242
    3343
     
    3747    /// use all samples)
    3848    ///
     49    /// @nore this constructor will be removed
    3950    InputRanker(const DataLookup2D&, const Target&, statistics::Score&,
    4051                const MatrixLookup&);
  • trunk/c++_tools/classifier/MatrixLookupWeighted.cc

    r616 r624  
    134134  MatrixLookupWeighted::MatrixLookupWeighted(const size_t rows,
    135135                                             const size_t columns,
    136                                              const double value)
     136                                             const double value,
     137                                             const double weight)
    137138    : DataLookup2D(rows,columns, true)
    138139  {
    139140    data_ = new utility::matrix(1,1,value);
    140     weights_ = new utility::matrix(1,1,1.0);
     141    weights_ = new utility::matrix(1,1,weight);
    141142  }
    142143
  • trunk/c++_tools/classifier/MatrixLookupWeighted.h

    r616 r624  
    158158    ///
    159159    MatrixLookupWeighted(const size_t rows, const size_t columns,
    160                          const double value=0);
     160                         const double value=0, const double weight=1);
    161161
    162162    ///
     
    176176    ///
    177177    virtual ~MatrixLookupWeighted();
     178
     179    ///
     180    /// @return data value of element (@a row, @a column)
     181    ///
     182    inline double data(size_t row, size_t column) const
     183    { return (*data_)(row_index_[row], column_index_[column]); }
    178184
    179185    ///
     
    247253
    248254    ///
     255    /// @return weight value of element (@a row, @a column)
     256    ///
     257    inline double weight(size_t row, size_t column) const
     258    { return (*weights_)(row_index_[row], column_index_[column]); }
     259
     260    ///
    249261    /// Access operator
    250262    ///
     
    253265    inline double operator()(const size_t row, const size_t column) const
    254266    {
    255       assert(row<rows());
    256       assert(column<columns());
    257       return (*data_)(row_index_[row], column_index_[column])*
    258         (*weights_)(row_index_[row], column_index_[column]);
     267      return data(row,column)*weight(row,column);
    259268    }
    260269
Note: See TracChangeset for help on using the changeset viewer.