SHOGUN
v2.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
ui
GUILabels.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) 1999-2008 Soeren Sonnenburg
8
* Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#include <
shogun/ui/GUILabels.h
>
12
#include <
shogun/ui/SGInterface.h
>
13
14
#include <
shogun/lib/config.h
>
15
#include <
shogun/io/SGIO.h
>
16
#include <
shogun/io/AsciiFile.h
>
17
#include <
shogun/labels/Labels.h
>
18
#include <
shogun/labels/BinaryLabels.h
>
19
#include <
shogun/labels/MulticlassLabels.h
>
20
#include <
shogun/labels/RegressionLabels.h
>
21
22
#include <string.h>
23
24
using namespace
shogun;
25
26
CGUILabels::CGUILabels
(CSGInterface* ui_)
27
:
CSGObject
(), ui(ui_), train_labels(NULL), test_labels(NULL)
28
{
29
}
30
31
CGUILabels::~CGUILabels
()
32
{
33
SG_UNREF
(
train_labels
);
34
SG_UNREF
(
test_labels
);
35
}
36
37
bool
CGUILabels::load
(
char
* filename,
char
* target)
38
{
39
CLabels
* labels=NULL;
40
41
if
(strncmp(target,
"TEST"
, 4)==0)
42
labels=
test_labels
;
43
else
if
(strncmp(target,
"TRAIN"
, 5)==0)
44
labels=
train_labels
;
45
else
46
SG_ERROR
(
"Invalid target %s.\n"
, target);
47
48
if
(labels)
49
{
50
SG_UNREF
(labels);
51
CAsciiFile
* file=
new
CAsciiFile
(filename);
52
labels=
new
CRegressionLabels
(file);
53
SGVector<float64_t>
labs = ((
CRegressionLabels
*) labels)->get_labels();
54
float64_t
* lab=
SGVector<float64_t>::clone_vector
(labs.
vector
, labs.
vlen
);
55
labels=
infer_labels
(lab, labs.
vlen
);
56
57
if
(labels)
58
{
59
if
(strncmp(target,
"TEST"
, 4)==0)
60
set_test_labels
(labels);
61
else
62
set_train_labels
(labels);
63
64
return
true
;
65
}
66
else
67
SG_ERROR
(
"Loading labels failed.\n"
);
68
69
SG_UNREF
(file);
70
}
71
72
return
false
;
73
}
74
75
bool
CGUILabels::save
(
char
* param)
76
{
77
bool
result=
false
;
78
return
result;
79
}
80
81
CLabels
*
CGUILabels::infer_labels
(
float64_t
* lab, int32_t len)
82
{
83
CLabels
* labels=NULL;
84
85
bool
binary=
true
;
86
bool
multiclass=
true
;
87
for
(int32_t i=0; i<len; i++)
88
{
89
if
(lab[i]!=-1 && lab[i]!=+1)
90
binary=
false
;
91
92
if
(lab[i]<0 || lab[i]!=
int
(lab[i]))
93
multiclass=
false
;
94
95
if
(binary ==
false
&& multiclass ==
false
)
96
{
97
labels=
new
CRegressionLabels
(
SGVector<float64_t>
(lab, len));
98
break
;
99
}
100
}
101
102
if
(multiclass)
103
labels=
new
CMulticlassLabels
(
SGVector<float64_t>
(lab, len));
104
if
(binary)
105
labels=
new
CBinaryLabels
(
SGVector<float64_t>
(lab, len));
106
107
return
labels;
108
}
SHOGUN
Machine Learning Toolbox - Documentation