SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
CrossValidationSplitting.cpp
浏览该文件的文档.
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  CMath::permute(indices, 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 }
void range_fill(T start=0)
Definition: SGVector.cpp:173
static void permute(SGVector< T > v, CRandom *rand=NULL)
Definition: Math.h:1144
int32_t index_t
Definition: common.h:62
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual int32_t get_num_labels() const =0
Abstract base class for all splitting types. Takes a CLabels instance and generates a desired number ...
CRandom * sg_rand
Definition: init.cpp:39
Template Dynamic array class that creates an array that can be used like a list or an array...
Definition: DynArray.h:22
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CDynamicObjectArray * m_subset_indices
CSGObject * get_element(int32_t index) const

SHOGUN 机器学习工具包 - 项目文档