source: trunk/src/CrossValidation.cc @ 115

Last change on this file since 115 was 115, checked in by Peter, 19 years ago

added

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 947 bytes
Line 
1// $Id: CrossValidation.cc 115 2004-07-19 14:38:43Z peter $
2
3// System includes
4#include <vector>
5
6// Thep C++ Tools
7#include "random_singleton.h"
8#include "CrossValidation.h"
9
10namespace theplu {
11namespace cpptools { 
12
13  CrossValidation::CrossValidation(const size_t nof_samples, const size_t k)
14    :count_(0),index_(std::vector<size_t>()), k_(k)
15 
16  { 
17    index_.resize(nof_samples);
18    for (size_t i=0; i<nof_samples; i++)
19      index_[i]=i;
20    my_uniform_rng a;
21    random_shuffle(index_.begin(), index_.end(), a);
22  }
23
24  std::vector<size_t> CrossValidation::next()
25  {
26    if (count_==k_){
27      count_=0;
28      my_uniform_rng a;
29      random_shuffle(index_.begin(), index_.end(), a);
30    }
31   
32    size_t begin = int(index_.size()*count_/k_);
33    count_++;
34    size_t end = int(index_.size()*count_/k_);
35    std::vector<size_t> training_set;
36    for (size_t i=0; i<index_.size(); i++)
37      if (i<begin || i>=end)
38        training_set.push_back(index_[i]);
39    return training_set ;
40   
41  }
42 
43}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.