Changeset 568


Ignore:
Timestamp:
Mar 22, 2006, 6:43:23 PM (16 years ago)
Author:
Peter
Message:

minor change in SVM

Location:
trunk/lib/classifier
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/classifier/KernelLookup.cc

    r566 r568  
    9999  {
    100100    const Kernel* kernel = kernel_->selected(inputs);
    101     std::cout << rows() << "x" << columns() << std::endl;
    102     std::cout << kernel->rows() << "x" << kernel->columns() << std::endl;
    103101    return new KernelLookup(*kernel, row_index_, column_index_, true);
    104102  }
  • trunk/lib/classifier/SVM.cc

    r565 r568  
    2828      C_inverse_(0),
    2929      kernel_(&kernel),
    30       max_epochs_(10000000),
     30      max_epochs_(100000),
    3131      output_(target.size(),0),
    3232      owner_(false),
     
    181181    }
    182182    assert(target_.size()==E.size());
    183     assert(target_.size()==sample_.n());
     183    assert(target_.size()==sample_.size());
    184184
    185185    unsigned long int epochs = 0;
     
    246246      if (epochs>max_epochs_){
    247247        std::cerr << "WARNING: SVM: maximal number of epochs reached.\n";
     248        calculate_bias();
    248249        return false;
    249250      }
     
    286287      // If no violation check among non-support vectors
    287288      sample_.shuffle();
    288       for (size_t i=sample_.nof_sv(); i<sample_.n();i++){
     289      for (size_t i=sample_.nof_sv(); i<sample_.size();i++){
    289290        if (target_.binary(sample_(i))){
    290291          if(E(sample_(i)) < E(sample_.value_first()) - 2*tolerance_){
     
    306307      // to avoid getting stuck we shuffle
    307308      sample_.shuffle();
    308       for (size_t i=0; i<sample_.n(); i++) {
    309         if (target_.binary(sample_(i))){
    310           for (size_t j=0; j<sample_.n(); j++) {
    311             if ( !target_.binary(sample_(j)) &&
     309      for (size_t i=0; i<sample_.size(); i++) {
     310        if (target(sample_(i))==1){
     311          for (size_t j=0; j<sample_.size(); j++) {
     312            if ( target(sample_(j))==-1 &&
    312313                 E(sample_(i)) < E(sample_(j))+2*tolerance_ ){
    313314              sample_.update_first(i);
     
    487488  void Index::update_first(const size_t i)
    488489  {
    489     assert(i<n());
     490    assert(i<size());
    490491    index_first_=i;
    491492    value_first_=vec_[i];
     
    494495  void Index::update_second(const size_t i)
    495496  {
    496     assert(i<n());
     497    assert(i<size());
    497498    index_second_=i;
    498499    value_second_=vec_[i];
  • trunk/lib/classifier/SVM.h

    r547 r568  
    3434    // @return index_first
    3535    inline size_t index_first(void) const
    36     { assert(index_first_<n()); return index_first_; }
     36    { assert(index_first_<size()); return index_first_; }
    3737
    3838    // @return index_second
    3939    inline size_t index_second(void) const
    40     { assert(index_second_<n()); return index_second_; }
     40    { assert(index_second_<size()); return index_second_; }
    4141
    4242    // synch the object against alpha
     
    4444
    4545    // @return nof samples
    46     inline size_t n(void) const { return vec_.size(); }
     46    inline size_t size(void) const { return vec_.size(); }
    4747
    4848    // @return nof support vectors
     
    5252    void nsv_first(void);
    5353
    54     // making first to an nsv. If already sv, nothing happens.
     54    // making second to an nsv. If already sv, nothing happens.
    5555    void nsv_second(void);   
    5656
     
    6262    void sv_first(void);
    6363
    64     // making first to a sv. If already sv, nothing happens.
     64    // making second to a sv. If already sv, nothing happens.
    6565    void sv_second(void);
    6666
     
    7373    // @return value_first
    7474    inline size_t value_first(void) const
    75     { assert(value_first_<n()); return value_first_; }
     75    { assert(value_first_<size()); return value_first_; }
    7676
    7777    // @return const ref value_second
    7878    inline size_t value_second(void) const
    79     { assert(value_first_<n()); return value_second_; }
     79    { assert(value_first_<size()); return value_second_; }
    8080
    8181    inline size_t operator()(size_t i) const {
    82       assert(i<n()); assert(vec_[i]<n()); return vec_[i]; }
     82      assert(i<size()); assert(vec_[i]<size()); return vec_[i]; }
    8383
    8484  private:
Note: See TracChangeset for help on using the changeset viewer.