-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
splitting_LOO_crossvalidation.cpp
75 lines (53 loc) · 1.72 KB
/
splitting_LOO_crossvalidation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* This software is distributed under BSD 3-clause license (see LICENSE file).
*
* Authors: Saurabh Mahindre, Bjoern Esser
*/
#include <shogun/base/init.h>
#include <shogun/evaluation/LOOCrossValidationSplitting.h>
#include <shogun/labels/RegressionLabels.h>
using namespace shogun;
int main(int argc, char **argv)
{
init_shogun_with_defaults();
index_t num_labels;
index_t runs=10;
while (runs-->0)
{
num_labels=CMath::random(10, 50);
//SG_SPRINT("num_labels=%d\n\n", num_labels);
/* build labels */
CRegressionLabels* labels=new CRegressionLabels(num_labels);
for (index_t i=0; i<num_labels; ++i)
{
labels->set_label(i, CMath::random(-10.0, 10.0));
// SG_SPRINT("label(%d)=%.18g\n", i, labels->get_label(i));
}
//SG_SPRINT("\n");
/* build Leave one out splitting strategy */
CLOOCrossValidationSplitting* splitting=
new CLOOCrossValidationSplitting(labels);
splitting->build_subsets();
for (index_t i=0; i<num_labels; ++i)
{
//SG_SPRINT("subset %d\n", i);
SGVector<index_t> subset=splitting->generate_subset_indices(i);
SGVector<index_t> inverse=splitting->generate_subset_inverse(i);
SGVector<index_t>::display_vector(subset.vector, subset.vlen, "subset indices");
SGVector<index_t>::display_vector(inverse.vector, inverse.vlen, "inverse indices");
/*for (index_t j=0; j<subset.vlen; ++j)
SG_SPRINT("%d:(%f),", subset.vector[j], labels->get_label(subset.vector[j]));
SG_SPRINT("\n");
SG_SPRINT("inverse %d\n", i);
for (index_t j=0; j<inverse.vlen; ++j)
SG_SPRINT("%d(%d),", inverse.vector[j],
(int32_t)labels->get_label(inverse.vector[j]));
SG_SPRINT("\n\n");
*/
}
/* clean up */
SG_UNREF(splitting);
}
exit_shogun();
return 0;
}