SHOGUN
v1.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
shogun
features
CombinedFeatures.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-2009 Soeren Sonnenburg
8
* Written (W) 1999-2008 Gunnar Raetsch
9
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10
*/
11
12
#include <
shogun/features/CombinedFeatures.h
>
13
#include <
shogun/io/SGIO.h
>
14
15
using namespace
shogun;
16
17
CCombinedFeatures::CCombinedFeatures
()
18
:
CFeatures
(0)
19
{
20
init();
21
22
feature_list
=
new
CList
(
true
);
23
num_vec
=0;
24
}
25
26
CCombinedFeatures::CCombinedFeatures
(
const
CCombinedFeatures
& orig)
27
:
CFeatures
(0)
28
{
29
init();
30
31
feature_list
=
new
CList
(
true
);
32
//todo copy features
33
num_vec
=orig.
num_vec
;
34
}
35
36
CFeatures
*
CCombinedFeatures::duplicate
()
const
37
{
38
return
new
CCombinedFeatures
(*
this
);
39
}
40
41
CCombinedFeatures::~CCombinedFeatures
()
42
{
43
SG_UNREF
(
feature_list
);
44
}
45
46
int32_t
CCombinedFeatures::get_size
()
47
{
48
CFeatures
* f=(
CFeatures
*)
feature_list
49
->get_current_element();
50
if
(f)
51
{
52
int32_t s=f->
get_size
();
53
SG_UNREF
(f)
54
return
s;
55
}
56
else
57
return
0;
58
}
59
60
void
CCombinedFeatures::list_feature_objs
()
61
{
62
SG_INFO
(
"BEGIN COMBINED FEATURES LIST - "
);
63
this->
list_feature_obj
();
64
65
CListElement
* current = NULL ;
66
CFeatures
* f=
get_first_feature_obj
(current);
67
68
while
(f)
69
{
70
f->
list_feature_obj
();
71
SG_UNREF
(f);
72
f=
get_next_feature_obj
(current);
73
}
74
75
SG_INFO
(
"END COMBINED FEATURES LIST - "
);
76
}
77
78
bool
CCombinedFeatures::check_feature_obj_compatibility
(
CCombinedFeatures
* comb_feat)
79
{
80
bool
result=
false
;
81
82
if
(comb_feat && (this->
get_num_feature_obj
() == comb_feat->
get_num_feature_obj
()) )
83
{
84
CFeatures
* f1=this->
get_first_feature_obj
();
85
CFeatures
* f2=comb_feat->
get_first_feature_obj
();
86
87
if
(f1 && f2 && f1->
check_feature_compatibility
(f2))
88
{
89
SG_UNREF
(f1);
90
SG_UNREF
(f2);
91
while
( ( (f1=this->
get_next_feature_obj
()) != NULL ) &&
92
( (f2=comb_feat->
get_next_feature_obj
()) != NULL) )
93
{
94
if
(!f1->
check_feature_compatibility
(f2))
95
{
96
SG_UNREF
(f1);
97
SG_UNREF
(f2);
98
SG_INFO
(
"not compatible, combfeat\n"
);
99
comb_feat->
list_feature_objs
();
100
SG_INFO
(
"vs this\n"
);
101
this->
list_feature_objs
();
102
return
false
;
103
}
104
SG_UNREF
(f1);
105
SG_UNREF
(f2);
106
}
107
108
SG_DEBUG
(
"features are compatible\n"
);
109
result=
true
;
110
}
111
else
112
SG_WARNING
(
"first 2 features not compatible\n"
);
113
}
114
else
115
{
116
SG_WARNING
(
"number of features in combined feature objects differs (%d != %d)\n"
, this->
get_num_feature_obj
(), comb_feat->
get_num_feature_obj
());
117
SG_INFO
(
"compare\n"
);
118
comb_feat->
list_feature_objs
();
119
SG_INFO
(
"vs this\n"
);
120
this->
list_feature_objs
();
121
}
122
123
return
result;
124
}
125
126
CFeatures
*
CCombinedFeatures::get_first_feature_obj
()
127
{
128
return
(
CFeatures
*)
feature_list
->
get_first_element
();
129
}
130
131
CFeatures
*
CCombinedFeatures::get_first_feature_obj
(
CListElement
*& current)
132
{
133
return
(
CFeatures
*)
feature_list
->
get_first_element
(current);
134
}
135
136
CFeatures
*
CCombinedFeatures::get_next_feature_obj
()
137
{
138
return
(
CFeatures
*)
feature_list
->
get_next_element
();
139
}
140
141
CFeatures
*
CCombinedFeatures::get_next_feature_obj
(
CListElement
*& current)
142
{
143
return
(
CFeatures
*)
feature_list
->
get_next_element
(current);
144
}
145
146
CFeatures
*
CCombinedFeatures::get_last_feature_obj
()
147
{
148
return
(
CFeatures
*)
feature_list
->
get_last_element
();
149
}
150
151
bool
CCombinedFeatures::insert_feature_obj
(
CFeatures
* obj)
152
{
153
ASSERT
(obj);
154
int32_t n=obj->
get_num_vectors
();
155
156
if
(
num_vec
>0 && n!=
num_vec
)
157
SG_ERROR
(
"Number of feature vectors does not match (expected %d, obj has %d)\n"
,
num_vec
, n);
158
159
num_vec
=n;
160
return
feature_list
->
insert_element
(obj);
161
}
162
163
bool
CCombinedFeatures::append_feature_obj
(
CFeatures
* obj)
164
{
165
ASSERT
(obj);
166
int32_t n=obj->
get_num_vectors
();
167
168
if
(
num_vec
>0 && n!=
num_vec
)
169
SG_ERROR
(
"Number of feature vectors does not match (expected %d, obj has %d)\n"
,
num_vec
, n);
170
171
num_vec
=n;
172
return
feature_list
->
append_element
(obj);
173
}
174
175
bool
CCombinedFeatures::delete_feature_obj
()
176
{
177
CFeatures
* f=(
CFeatures
*)
feature_list
->
delete_element
();
178
if
(f)
179
{
180
SG_UNREF
(f);
181
return
true
;
182
}
183
else
184
return
false
;
185
}
186
187
int32_t
CCombinedFeatures::get_num_feature_obj
()
188
{
189
return
feature_list
->
get_num_elements
();
190
}
191
192
void
CCombinedFeatures::init()
193
{
194
m_parameters
->
add
(&
num_vec
,
"num_vec"
,
195
"Number of vectors."
);
196
m_parameters
->
add
((
CSGObject
**) &
feature_list
,
197
"feature_list"
,
"Feature list."
);
198
}
SHOGUN
Machine Learning Toolbox - Documentation