SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CrossValidationSplitting.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2012 Heiko Strathmann
8  * Copyright (C) 2012 Berlin Institute of Technology and Max-Planck-Society
9  */
10 
12 #include <shogun/labels/Labels.h>
13 
14 using namespace shogun;
15 
18 {
19  m_rng = sg_rand;
20 }
21 
23  CLabels* labels, index_t num_subsets) :
24  CSplittingStrategy(labels, num_subsets)
25 {
26  m_rng = sg_rand;
27 }
28 
30 {
31  /* ensure that subsets are empty and set flag to filled */
32  reset_subsets();
33  m_is_filled=true;
34 
35  /* permute indices */
37  indices.range_fill();
38  indices.permute(m_rng);
39 
41 
42  /* distribute indices to subsets */
43  index_t current_subset=0;
44  for (index_t i=0; i<indices.vlen; ++i)
45  {
46  /* fill current subset */
48  m_subset_indices->get_element(current_subset);
49 
50  /* add element of current index */
51  current->append_element(indices.vector[i]);
52 
53  /* unref */
54  SG_UNREF(current);
55 
56  /* iterate over subsets */
57  current_subset=(current_subset+1) % num_subsets;
58  }
59 
60  /* finally shuffle to avoid that subsets with low indices have more
61  * elements, which happens if the number of class labels is not equal to
62  * the number of subsets (external random state important for threads) */
64 }

SHOGUN Machine Learning Toolbox - Documentation