Changeset 625


Ignore:
Timestamp:
Sep 5, 2006, 4:37:21 AM (15 years ago)
Author:
Peter
Message:

fixes #115 and ref #113 removed feature selection from SVM

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

Legend:

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

    r616 r625  
    5454  }
    5555
    56   SVM::SVM(const KernelLookup& kernel, const Target& target,
    57            statistics::Score& score, const size_t nof_inputs)
    58     : SupervisedClassifier(target, &score, nof_inputs),
    59       alpha_(target.size(),0),
    60       bias_(0),
    61       C_inverse_(0),
    62       margin_(0),
    63       max_epochs_(10000000),
    64       output_(target.size(),0),
    65       sample_(target.size()),
    66       trained_(false),
    67       tolerance_(0.00000001)
    68   {
    69 
    70     if (kernel.weighted()){
    71       const MatrixLookup* data = kernel.data();
    72       const MatrixLookup* weights = kernel.weights();
    73       ranker_ = new InputRanker(*data, target, score, *weights);
    74       delete data;
    75       delete weights;
    76     }
    77     else{
    78       const MatrixLookup* data = kernel.data();
    79       ranker_ = new InputRanker(*data, target, score);
    80       delete data;
    81     }
    82 
    83     std::vector<size_t> index;
    84     index.reserve(nof_inputs);
    85     for (size_t i=0; i<nof_inputs; i++)
    86       index.push_back(ranker_->id()[i]);
    87     kernel_ = kernel.selected(index);
    88     assert(kernel_->rows()==kernel.rows());
    89     assert(kernel_->columns()==kernel.columns());
    90     owner_ = true;
    91    
    92   }
    93 
    94  
    95 
    9656  SVM::~SVM()
    9757  {
     
    12282    assert(data.columns()==target.size());
    12383    SVM* sc;
    124     if (ranker_)
    125       sc = new SVM(data,target,*score_,nof_inputs_);
    126     else
    127       sc = new SVM(data,target);
     84    sc = new SVM(data,target);
    12885
    12986
     
    13996
    14097    const KernelLookup* kernel_pointer;
    141     if (ranker_) {// feature selection
    142       std::vector<size_t> index;
    143       index.reserve(nof_inputs_);
    144       for (size_t i=0; i<nof_inputs_; i++)
    145         index.push_back(ranker_->id()[i]);
    146       kernel_pointer = input_kernel.selected(index);
    147     }
    148     else
    149       kernel_pointer = &input_kernel;
     98    kernel_pointer = &input_kernel;
    15099
    151100    assert(input.rows()==alpha_.size());
     
    162111      prediction(1,i) = -prediction(0,i);
    163112   
    164     if (ranker_)
    165       delete kernel_pointer;
    166113    assert(prediction(0,0));
    167114  }
  • trunk/c++_tools/classifier/SVM.h

    r616 r625  
    118118    SVM(const KernelLookup& kernel, const Target& target);
    119119
    120     ///
    121     /// Constructor taking the kernel, the target vector, the score
    122     /// used to rank data inputs, and the number of top ranked data
    123     /// inputs to use in the classification.
    124     ///
    125     /// @note if the @a target or @a kernel
    126     /// is destroyed the behaviour is undefined.
    127     ///
    128     /// @note make no effect yet
    129     SVM(const KernelLookup& kernel, const Target& target,
    130         statistics::Score&, const size_t);
    131 
    132120    ///
    133121    /// Destructor
Note: See TracChangeset for help on using the changeset viewer.