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