SHOGUN
v3.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
features
FactorGraphFeatures.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) 2013 Shell Hu
8
* Copyright (C) 2013 Shell Hu
9
*/
10
11
#include <
shogun/features/FactorGraphFeatures.h
>
12
13
using namespace
shogun;
14
15
CFactorGraphFeatures::CFactorGraphFeatures
()
16
{
17
init();
18
m_samples
=
new
CDynamicObjectArray
();
19
SG_REF
(
m_samples
);
20
}
21
22
CFactorGraphFeatures::CFactorGraphFeatures
(int32_t num_samples)
23
{
24
init();
25
m_samples
=
new
CDynamicObjectArray
(num_samples);
26
SG_REF
(
m_samples
);
27
}
28
29
CFactorGraphFeatures::~CFactorGraphFeatures
()
30
{
31
SG_UNREF
(
m_samples
);
32
}
33
34
CFeatures
*
CFactorGraphFeatures::duplicate
()
const
35
{
36
return
new
CFactorGraphFeatures
(*
this
);
37
}
38
39
EFeatureType
CFactorGraphFeatures::get_feature_type
()
const
40
{
41
return
F_ANY
;
42
}
43
44
EFeatureClass
CFactorGraphFeatures::get_feature_class
()
const
45
{
46
return
C_FACTOR_GRAPH
;
47
}
48
49
50
int32_t
CFactorGraphFeatures::get_num_vectors
()
const
51
{
52
if
(
m_samples
== NULL)
53
return
0;
54
else
55
return
m_samples
->
get_array_size
();
56
}
57
58
bool
CFactorGraphFeatures::add_sample
(
CFactorGraph
* example)
59
{
60
if
(
m_samples
!= NULL)
61
{
62
m_samples
->
push_back
(example);
63
return
true
;
64
}
65
else
66
return
false
;
67
}
68
69
CFactorGraph
*
CFactorGraphFeatures::get_sample
(
index_t
idx)
70
{
71
REQUIRE
(
m_samples
!= NULL,
"%s::get_sample(): m_samples is NULL!\n"
,
get_name
());
72
REQUIRE
(idx >= 0 && idx <
get_num_vectors
(),
"%s::get_sample(): out of index!\n"
,
get_name
());
73
74
return
dynamic_cast<
CFactorGraph
*
>
(
m_samples
->
get_element
(idx));
75
}
76
77
void
CFactorGraphFeatures::init()
78
{
79
SG_ADD
((
CSGObject
**) &
m_samples
,
"samples"
,
"Array of examples"
,
80
MS_NOT_AVAILABLE
);
81
}
82
83
CFactorGraphFeatures
*
CFactorGraphFeatures::obtain_from_generic
(
CFeatures
* base_feats)
84
{
85
REQUIRE
(base_feats != NULL,
"CFactorGraphFeatures::obtain_from_generic(): base_feats is NULL!\n"
);
86
87
if
(base_feats->
get_feature_class
() ==
C_FACTOR_GRAPH
)
88
return
dynamic_cast<CFactorGraphFeatures*>(base_feats);
89
else
90
SG_SERROR
(
"base_labels must be of dynamic type CFactorGraph!\n"
)
91
92
return
NULL;
93
}
94
SHOGUN
Machine Learning Toolbox - Documentation