Ignore:
Timestamp:
Mar 5, 2008, 6:56:01 PM (14 years ago)
Author:
Peter
Message:

fixes #345

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/EnsembleBuilder.h

    r1157 r1206  
    115115    SubsetGenerator<Data>* subset_;
    116116    std::vector<Classifier*> classifier_;
     117    KernelLookup test_data(const KernelLookup&, size_t k);
     118    MatrixLookup test_data(const MatrixLookup&, size_t k);
     119    MatrixLookupWeighted test_data(const MatrixLookupWeighted&, size_t k);
    117120    std::vector<std::vector<statistics::Averager> > validation_result_;
    118121
     
    169172
    170173  template <class C, class D>
    171   u_long EnsembleBuilder<C, D>::size(void) const
    172   {
    173     return classifier_.size();
    174   }
    175 
    176 
    177   template <class C, class D>
    178174  void EnsembleBuilder<C, D>::predict
    179175  (const D& data, std::vector<std::vector<statistics::Averager> >& result)
     
    187183
    188184    for(u_long k=0;k<subset_->size();++k) {       
    189       const D* sub_data =
    190         data.selected(subset_->training_features(k));
    191       assert(sub_data);
    192       classifier(k).predict(*sub_data,prediction);
    193       delete sub_data;
     185      D sub_data =  test_data(data, k);
     186      classifier(k).predict(sub_data,prediction);
    194187    }
    195188
     
    200193
    201194 
     195  template <class C, class D>
     196  u_long EnsembleBuilder<C, D>::size(void) const
     197  {
     198    return classifier_.size();
     199  }
     200
     201
     202  template <class C, class D>
     203  MatrixLookup EnsembleBuilder<C, D>::test_data(const MatrixLookup& data,
     204                                                size_t k)
     205  {
     206    return MatrixLookup(data, subset_->training_features(k), true);
     207  }
     208 
     209
     210  template <class C, class D>
     211  MatrixLookupWeighted
     212  EnsembleBuilder<C, D>::test_data(const MatrixLookupWeighted& data, size_t k)
     213  {
     214    return MatrixLookupWeighted(data, subset_->training_features(k), true);
     215  }
     216 
     217
     218  template <class C, class D>
     219  KernelLookup
     220  EnsembleBuilder<C, D>::test_data(const KernelLookup& kernel, size_t k)
     221  {
     222    // weighted case
     223    if (kernel.weighted()){
     224      assert(false);
     225      // no feature selection
     226      if (kernel.data_weighted().rows()==subset_->training_features(k).size())
     227        return KernelLookup(kernel, subset_->training_index(k), true);
     228      MatrixLookupWeighted mlw = test_data(kernel.data_weighted(), k);
     229      return subset_->training_data(k).test_kernel(mlw);
     230
     231    }
     232    // unweighted case
     233
     234    // no feature selection
     235    if (kernel.data().rows()==subset_->training_features(k).size())
     236      return KernelLookup(kernel, subset_->training_index(k), true);
     237   
     238    // feature selection
     239    return subset_->training_data(k).test_kernel(test_data(kernel.data(),k));
     240  }
     241 
     242
    202243  template <class C, class D>
    203244  const std::vector<std::vector<statistics::Averager> >&
Note: See TracChangeset for help on using the changeset viewer.