SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
evaluation
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
11
#include <
shogun/evaluation/CrossValidationSplitting.h
>
12
#include <
shogun/labels/Labels.h
>
13
14
using namespace
shogun;
15
16
CCrossValidationSplitting::CCrossValidationSplitting
() :
17
CSplittingStrategy
()
18
{
19
m_rng
=
sg_rand
;
20
}
21
22
CCrossValidationSplitting::CCrossValidationSplitting
(
23
CLabels
* labels,
index_t
num_subsets) :
24
CSplittingStrategy
(labels, num_subsets)
25
{
26
m_rng
=
sg_rand
;
27
}
28
29
void
CCrossValidationSplitting::build_subsets
()
30
{
31
/* ensure that subsets are empty and set flag to filled */
32
reset_subsets
();
33
m_is_filled
=
true
;
34
35
/* permute indices */
36
SGVector<index_t>
indices(
m_labels
->
get_num_labels
());
37
indices.
range_fill
();
38
indices.permute(
m_rng
);
39
40
index_t
num_subsets=
m_subset_indices
->
get_num_elements
();
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 */
47
CDynamicArray<index_t>
* current=(
CDynamicArray<index_t>
*)
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) */
63
m_subset_indices
->
shuffle
(
m_rng
);
64
}
SHOGUN
机器学习工具包 - 项目文档