SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
structure
Plif.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) 1999-2008 Gunnar Raetsch
8
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#ifndef __PLIF_H__
12
#define __PLIF_H__
13
14
#include <
shogun/lib/common.h
>
15
#include <
shogun/lib/SGVector.h
>
16
#include <
shogun/mathematics/Math.h
>
17
#include <
shogun/structure/PlifBase.h
>
18
19
namespace
shogun
20
{
21
23
enum
ETransformType
24
{
26
T_LINEAR
,
28
T_LOG
,
30
T_LOG_PLUS1
,
32
T_LOG_PLUS3
,
34
T_LINEAR_PLUS3
35
};
36
38
class
CPlif
:
public
CPlifBase
39
{
40
public
:
45
CPlif
(int32_t
len
=0);
46
virtual
~CPlif
();
47
49
void
init_penalty_struct_cache
();
50
57
float64_t
lookup_penalty_svm
(
58
float64_t
p_value,
float64_t
*d_values)
const
;
59
66
float64_t
lookup_penalty
(
67
float64_t
p_value,
float64_t
* svm_values)
const
;
68
75
float64_t
lookup_penalty
(int32_t p_value,
float64_t
* svm_values)
const
;
76
82
inline
float64_t
lookup
(
float64_t
p_value)
83
{
84
ASSERT
(
use_svm
== 0)
85
return
lookup_penalty
(p_value, NULL);
86
}
87
89
void
penalty_clear_derivative
();
90
97
void
penalty_add_derivative_svm
(
98
float64_t
p_value,
float64_t
* svm_values,
float64_t
factor) ;
99
106
void
penalty_add_derivative
(
float64_t
p_value,
float64_t
* svm_values,
float64_t
factor);
107
113
const
float64_t
*
get_cum_derivative
(int32_t & p_len)
const
114
{
115
p_len =
len
;
116
return
cum_derivatives
.
vector
;
117
}
118
124
bool
set_transform_type
(
const
char
*type_str);
125
130
const
char
*
get_transform_type
()
131
{
132
if
(
transform
==
T_LINEAR
)
133
return
"linear"
;
134
else
if
(
transform
==
T_LOG
)
135
return
"log"
;
136
else
if
(
transform
==
T_LOG_PLUS1
)
137
return
"log(+1)"
;
138
else
if
(
transform
==
T_LOG_PLUS3
)
139
return
"log(+3)"
;
140
else
if
(
transform
==
T_LINEAR_PLUS3
)
141
return
"(+3)"
;
142
else
143
SG_ERROR
(
"wrong type"
)
144
return
""
;
145
}
146
147
152
void
set_id
(int32_t p_id)
153
{
154
id
=p_id;
155
}
156
161
int32_t
get_id
()
const
162
{
163
return
id
;
164
}
165
170
int32_t
get_max_id
()
const
171
{
172
return
get_id
();
173
}
174
179
void
set_use_svm
(int32_t p_use_svm)
180
{
181
invalidate_cache
();
182
use_svm
=p_use_svm;
183
}
184
189
int32_t
get_use_svm
()
const
190
{
191
return
use_svm
;
192
}
193
198
virtual
bool
uses_svm_values
()
const
199
{
200
return
(
get_use_svm
()!=0);
201
}
202
207
void
set_use_cache
(int32_t p_use_cache)
208
{
209
invalidate_cache
();
210
use_cache
=p_use_cache;
211
}
212
215
void
invalidate_cache
()
216
{
217
SG_FREE(
cache
);
218
cache
=NULL;
219
}
220
225
int32_t
get_use_cache
()
226
{
227
return
use_cache
;
228
}
229
236
void
set_plif
(
237
int32_t p_len,
float64_t
*p_limits,
float64_t
* p_penalties)
238
{
239
ASSERT
(
len
==p_len)
240
241
for
(int32_t i=0; i<
len
; i++)
242
{
243
limits
[i]=p_limits[i];
244
penalties
[i]=p_penalties[i];
245
}
246
247
invalidate_cache
();
248
penalty_clear_derivative
();
249
}
250
255
void
set_plif_limits
(
SGVector<float64_t>
p_limits)
256
{
257
ASSERT
(
len
==p_limits.
vlen
)
258
259
limits
= p_limits;
260
261
invalidate_cache
();
262
penalty_clear_derivative
();
263
}
264
265
270
void
set_plif_penalty
(
SGVector<float64_t>
p_penalties)
271
{
272
ASSERT
(
len
==p_penalties.
vlen
)
273
274
penalties
= p_penalties;
275
276
invalidate_cache
();
277
penalty_clear_derivative
();
278
}
279
284
void
set_plif_length
(int32_t p_len)
285
{
286
if
(
len
!=p_len)
287
{
288
len
=p_len;
289
290
SG_DEBUG
(
"set_plif len=%i\n"
, p_len)
291
limits
=
SGVector<float64_t>
(
len
);
292
penalties
=
SGVector<float64_t>
(
len
);
293
cum_derivatives
=
SGVector<float64_t>
(
len
);
294
}
295
296
for
(int32_t i=0; i<
len
; i++)
297
{
298
limits
[i]=0.0;
299
penalties
[i]=0.0;
300
cum_derivatives
[i]=0.0;
301
}
302
303
invalidate_cache
();
304
penalty_clear_derivative
();
305
}
306
311
SGVector<float64_t>
get_plif_limits
()
312
{
313
return
limits
;
314
}
315
320
SGVector<float64_t>
get_plif_penalties
()
321
{
322
return
penalties
;
323
}
324
329
inline
void
set_max_value
(
float64_t
p_max_value)
330
{
331
max_value
=p_max_value;
332
invalidate_cache
();
333
}
334
339
virtual
float64_t
get_max_value
()
const
340
{
341
return
max_value
;
342
}
343
348
inline
void
set_min_value
(
float64_t
p_min_value)
349
{
350
min_value
=p_min_value;
351
invalidate_cache
();
352
}
353
358
virtual
float64_t
get_min_value
()
const
359
{
360
return
min_value
;
361
}
362
367
void
set_plif_name
(
char
*p_name);
368
373
char
*
get_plif_name
()
const
;
374
379
bool
get_do_calc
();
380
385
void
set_do_calc
(
bool
b);
386
390
void
get_used_svms
(int32_t* num_svms, int32_t* svm_ids);
391
396
inline
int32_t
get_plif_len
()
397
{
398
return
len
;
399
}
400
405
virtual
void
list_plif
()
const
406
{
407
SG_PRINT
(
"CPlif(min_value=%1.2f, max_value=%1.2f, use_svm=%i)\n"
,
min_value
,
max_value
,
use_svm
)
408
}
409
415
static
void
delete_penalty_struct
(
CPlif
** PEN, int32_t P);
416
418
virtual
const
char
*
get_name
()
const
{
return
"Plif"
; }
419
420
protected
:
422
int32_t
len
;
424
SGVector<float64_t>
limits
;
426
SGVector<float64_t>
penalties
;
428
SGVector<float64_t>
cum_derivatives
;
430
float64_t
max_value
;
432
float64_t
min_value
;
434
float64_t
*
cache
;
436
enum
ETransformType
transform
;
438
int32_t
id
;
440
char
*
name
;
442
int32_t
use_svm
;
444
bool
use_cache
;
448
bool
do_calc
;
449
};
450
}
451
#endif
SHOGUN
机器学习工具包 - 项目文档