SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
lib
JLCoverTreePoint.h
浏览该文件的文档.
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 Fernando José Iglesias García
8
* Written (W) John Langford and Dinoj Surendran, v_array and its templatization
9
* Copyright (C) 2012 Fernando José Iglesias García
10
*/
11
12
#ifndef _JLCTPOINT_H__
13
#define _JLCTPOINT_H__
14
15
#include <
shogun/lib/config.h
>
16
#include <
shogun/distance/Distance.h
>
17
#include <
shogun/features/Features.h
>
18
19
namespace
shogun
20
{
21
23
template
<
class
T>
24
class
v_array
{
25
26
public
:
29
T
last
() {
return
elements
[
index
-1];}
30
32
void
decr
() {
index
--;}
33
35
v_array
() {
index
= 0;
length
=0;
elements
= NULL;}
36
40
T&
operator[]
(
unsigned
int
i) {
return
elements
[i]; }
41
42
public
:
44
int
index
;
45
47
int
length
;
48
50
T*
elements
;
51
52
};
53
60
template
<
class
T>
61
void
push
(
v_array<T>
& v,
const
T &new_ele)
62
{
63
while
(v.
index
>= v.
length
)
64
{
65
v.
length
= 2*v.
length
+ 3;
66
v.
elements
= (T *)realloc(v.
elements
,
sizeof
(T) * v.
length
);
67
}
68
v[v.
index
++] = new_ele;
69
}
70
77
template
<
class
T>
78
void
alloc
(
v_array<T>
& v,
int
length)
79
{
80
v.
elements
= (T *)realloc(v.
elements
,
sizeof
(T) * length);
81
v.
length
= length;
82
}
83
93
template
<
class
T>
94
v_array<T>
pop
(
v_array
<
v_array<T>
> &stack)
95
{
96
if
(stack.index > 0)
97
return
stack[--stack.index];
98
else
99
return
v_array<T>
();
100
}
101
107
enum
EFeaturesContainer
108
{
109
FC_LHS
= 0,
110
FC_RHS
= 1,
111
};
112
118
class
CJLCoverTreePoint
119
{
120
121
public
:
122
125
CDistance
*
m_distance
;
126
128
int32_t
m_index
;
129
131
EFeaturesContainer
m_features_container
;
132
133
};
/* class JLCoverTreePoint */
134
138
float
distance
(
CJLCoverTreePoint
p1,
CJLCoverTreePoint
p2,
float64_t
upper_bound)
139
{
143
if
( p1.
m_features_container
== p2.
m_features_container
)
144
{
145
if
( ! p1.
m_distance
->
lhs_equals_rhs
() )
146
{
147
SG_SERROR
(
"lhs != rhs but the distance of two points "
148
"from the same container has been requested\n"
);
149
}
150
else
151
{
152
return
p1.
m_distance
->
distance_upper_bounded
(p1.
m_index
,
153
p2.
m_index
, upper_bound);
154
}
155
}
156
else
157
{
158
if
( p1.
m_distance
->
lhs_equals_rhs
() )
159
{
160
SG_SERROR
(
"lhs == rhs but the distance of two points "
161
"from different containers has been requested\n"
);
162
}
163
else
164
{
165
if
( p1.
m_features_container
==
FC_LHS
)
166
{
167
return
p1.
m_distance
->
distance_upper_bounded
(p1.
m_index
,
168
p2.
m_index
, upper_bound);
169
}
170
else
171
{
172
return
p1.
m_distance
->
distance_upper_bounded
(p2.
m_index
,
173
p1.
m_index
, upper_bound);
174
}
175
}
176
}
177
178
SG_SERROR
(
"Something has gone wrong, case not handled\n"
)
179
return
-1;
180
}
181
183
v_array< CJLCoverTreePoint >
parse_points
(
CDistance
*
distance
,
EFeaturesContainer
fc)
184
{
185
CFeatures
* features;
186
if
( fc ==
FC_LHS
)
187
features = distance->
get_lhs
();
188
else
189
features = distance->
get_rhs
();
190
191
v_array< CJLCoverTreePoint >
parsed;
192
for
( int32_t i = 0 ; i < features->
get_num_vectors
() ; ++i )
193
{
194
CJLCoverTreePoint
new_point;
195
196
new_point.
m_distance
=
distance
;
197
new_point.
m_index
= i;
198
new_point.
m_features_container
= fc;
199
200
push
(parsed, new_point);
201
}
202
203
return
parsed;
204
}
205
207
void
print
(
CJLCoverTreePoint
&p)
208
{
209
SG_SERROR
(
"Print JLCoverTreePoint not implemented\n"
)
210
}
211
212
}
/* namespace shogun */
213
214
#endif
/* _JLCTPOINT_H__*/
SHOGUN
机器学习工具包 - 项目文档