Changeset 581


Ignore:
Timestamp:
May 4, 2006, 5:08:42 PM (15 years ago)
Author:
Markus Ringnér
Message:

Added class for in-group-proportions score. Removed gslapi::vector dependence on DataLookup1D by adding classifier::utility functions. Added operator[] to Target and DataLookup1D

Location:
trunk/c++_tools
Files:
4 added
7 edited

Legend:

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

    r565 r581  
    6666
    6767    ///
     68    ///
     69    ///
     70    inline double operator[](const size_t i) const
     71    {
     72      return this->operator()(i);
     73    }
     74
     75
     76    ///
    6877    /// scalar product
    6978    ///
  • trunk/c++_tools/classifier/Makefile.am

    r580 r581  
    3131  EnsembleBuilder.cc \
    3232  GaussianKernelFunction.cc \
     33  IGP.cc \
    3334  InputRanker.cc \
    3435  Kernel.cc \
     
    4344  SupervisedClassifier.cc \
    4445  SVM.cc \
    45   Target.cc
    46 
     46  Target.cc \
     47  utility.cc
    4748
    4849
     
    5253  ConsensusInputRanker.h \
    5354  CrossSplitter.h \
     55  DataLookup1D.h \
    5456  DataLookup2D.h \
    5557  EnsembleBuilder.h \
    5658  GaussianKernelFunction.h \
     59  IGP.h \
    5760  InputRanker.h \
    5861  Kernel.h \
     
    6972  SVM.h \
    7073  Target.h \
    71   DataLookup1D.h
     74  utility.h
  • trunk/c++_tools/classifier/Target.cc

    r520 r581  
    9595  }
    9696
     97  const size_t Target::size(const std::string& label) const
     98  {
     99    std::map<std::string,size_t>::const_iterator i=class_map_.find(label);   
     100    if(i==class_map_.end())
     101      return 0;
     102    assert(i->first==label);
     103    return size(i->second);
     104  }
     105 
     106  const size_t Target::size(size_t cl) const
     107  {
     108    return std::count(classes_.begin(),classes_.end(),cl);
     109  }
     110
     111
    97112  std::ostream& operator<<(std::ostream& s, const Target& a)
    98113  {
  • trunk/c++_tools/classifier/Target.h

    r520 r581  
    7979   
    8080    ///
     81    /// @return vector of labels for classes
     82    ///
     83    inline const std::vector<std::string>& labels() { return labels_; }
     84
     85    ///
    8186    /// Binary target for each sample with class @a i is set to @a
    8287    /// b. Default is binary set to false for each class except class
     
    97102
    98103    ///
     104    /// @return number of samples with class @a cl
     105    ///
     106    const size_t size(size_t cl) const;
     107
     108
     109    ///
    99110    /// @return the class of @a sample
    100111    ///
    101112    inline size_t operator()(const size_t sample) const
    102113    { assert(sample<size()); return classes_[sample]; }
     114   
     115    ///
     116    /// @return the class of @a sample
     117    ///
     118    inline size_t operator[](const size_t sample) const
     119    { return this->operator()(sample); }
    103120
    104121
     
    107124    std::vector<char> binary_; // avoid using vector<bool>
    108125    std::vector<size_t> classes_; // class of sample i
    109     std::map<std::string,size_t> class_map_; 
     126    // map between class label and class index
     127    std::map<std::string,size_t> class_map_; 
    110128    std::vector<std::string> labels_; // label of class i
    111129   
  • trunk/c++_tools/gslapi/vector.cc

    r570 r581  
    3030#include <c++_tools/utility/stl_utility.h>
    3131#include <c++_tools/utility/utility.h>
    32 #include <c++_tools/classifier/DataLookup1D.h>
     32
    3333
    3434#include <iostream>
     
    165165
    166166
    167   vector::vector(const classifier::DataLookup1D& data)
    168     : view_(NULL), const_view_(NULL)
    169   {
    170     v_ = gsl_vector_alloc(data.size());
    171     for (size_t i=0; i<data.size(); i++)
    172       gsl_vector_set( v_, i, data(i) );
    173   }
    174 
    175 
    176 
    177167  vector::~vector(void)
    178168  {
  • trunk/c++_tools/gslapi/vector.h

    r570 r581  
    3939
    4040namespace theplu {
    41 namespace classifier {
    42   class DataLookup1D;
    43 }
    4441namespace gslapi {
    4542
     
    183180    explicit vector(std::istream &, char sep='\0') throw (utility::IO_error,std::exception);
    184181
    185     ///
    186     ///
    187     ///
    188     explicit vector(const classifier::DataLookup1D&);
    189182
    190183    ///
  • trunk/c++_tools/statistics/Score.h

    r536 r581  
    44#define _theplu_statistics_score_
    55
     6#include <c++_tools/classifier/utility.h>
    67#include <c++_tools/gslapi/vector.h>
    78
     
    6869    {
    6970      assert(target.size()==value.size());
    70       return score(target,gslapi::vector(value));
     71      gslapi::vector a;
     72      classifier::convert(value,a);
     73      return score(target,a);
    7174    }
    7275 
     
    9497          const classifier::DataLookup1D& value,
    9598          const classifier::DataLookup1D& weight)
    96     { return score(target, gslapi::vector(value), gslapi::vector(weight)); }
     99    {
     100      gslapi::vector a;
     101      classifier::convert(value,a);
     102      gslapi::vector b;
     103      classifier::convert(weight,a);
     104      return score(target,a,b);
     105    }
    97106
    98107  protected:
Note: See TracChangeset for help on using the changeset viewer.