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
structure
Plif.h
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-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/mathematics/Math.h
>
16
#include <
shogun/structure/PlifBase.h
>
17
18
namespace
shogun
19
{
20
22
enum
ETransformType
23
{
25
T_LINEAR
,
27
T_LOG
,
29
T_LOG_PLUS1
,
31
T_LOG_PLUS3
,
33
T_LINEAR_PLUS3
34
};
35
37
class
CPlif
:
public
CPlifBase
38
{
39
public
:
44
CPlif
(int32_t
len
=0);
45
virtual
~CPlif
();
46
48
void
init_penalty_struct_cache
();
49
56
float64_t
lookup_penalty_svm
(
57
float64_t
p_value,
float64_t
*d_values)
const
;
58
65
float64_t
lookup_penalty
(
66
float64_t
p_value,
float64_t
* svm_values)
const
;
67
74
float64_t
lookup_penalty
(int32_t p_value,
float64_t
* svm_values)
const
;
75
81
inline
float64_t
lookup
(
float64_t
p_value)
82
{
83
ASSERT
(
use_svm
== 0);
84
return
lookup_penalty
(p_value, NULL);
85
}
86
88
void
penalty_clear_derivative
();
89
96
void
penalty_add_derivative_svm
(
97
float64_t
p_value,
float64_t
* svm_values,
float64_t
factor) ;
98
105
void
penalty_add_derivative
(
float64_t
p_value,
float64_t
* svm_values,
float64_t
factor);
106
112
const
float64_t
*
get_cum_derivative
(int32_t & p_len)
const
113
{
114
p_len =
len
;
115
return
cum_derivatives
.
vector
;
116
}
117
123
bool
set_transform_type
(
const
char
*type_str);
124
129
const
char
*
get_transform_type
()
130
{
131
if
(
transform
==
T_LINEAR
)
132
return
"linear"
;
133
else
if
(
transform
==
T_LOG
)
134
return
"log"
;
135
else
if
(
transform
==
T_LOG_PLUS1
)
136
return
"log(+1)"
;
137
else
if
(
transform
==
T_LOG_PLUS3
)
138
return
"log(+3)"
;
139
else
if
(
transform
==
T_LINEAR_PLUS3
)
140
return
"(+3)"
;
141
else
142
SG_ERROR
(
"wrong type"
);
143
return
""
;
144
}
145
146
151
void
set_id
(int32_t p_id)
152
{
153
id
=p_id;
154
}
155
160
int32_t
get_id
()
const
161
{
162
return
id
;
163
}
164
169
int32_t
get_max_id
()
const
170
{
171
return
get_id
();
172
}
173
178
void
set_use_svm
(int32_t p_use_svm)
179
{
180
invalidate_cache
();
181
use_svm
=p_use_svm;
182
}
183
188
int32_t
get_use_svm
()
const
189
{
190
return
use_svm
;
191
}
192
197
virtual
bool
uses_svm_values
()
const
198
{
199
return
(
get_use_svm
()!=0);
200
}
201
206
void
set_use_cache
(int32_t p_use_cache)
207
{
208
invalidate_cache
();
209
use_cache
=p_use_cache;
210
}
211
214
void
invalidate_cache
()
215
{
216
SG_FREE
(
cache
);
217
cache
=NULL;
218
}
219
224
int32_t
get_use_cache
()
225
{
226
return
use_cache
;
227
}
228
235
void
set_plif
(
236
int32_t p_len,
float64_t
*p_limits,
float64_t
* p_penalties)
237
{
238
ASSERT
(
len
==p_len);
239
240
for
(int32_t i=0; i<
len
; i++)
241
{
242
limits
[i]=p_limits[i];
243
penalties
[i]=p_penalties[i];
244
}
245
246
invalidate_cache
();
247
penalty_clear_derivative
();
248
}
249
254
void
set_plif_limits
(
SGVector<float64_t>
p_limits)
255
{
256
ASSERT
(
len
==p_limits.
vlen
);
257
258
limits
= p_limits;
259
260
invalidate_cache
();
261
penalty_clear_derivative
();
262
}
263
264
269
void
set_plif_penalty
(
SGVector<float64_t>
p_penalties)
270
{
271
ASSERT
(
len
==p_penalties.
vlen
);
272
273
penalties
= p_penalties;
274
275
invalidate_cache
();
276
penalty_clear_derivative
();
277
}
278
283
void
set_plif_length
(int32_t p_len)
284
{
285
if
(
len
!=p_len)
286
{
287
len
=p_len;
288
289
SG_DEBUG
(
"set_plif len=%i\n"
, p_len);
290
limits
=
SGVector<float64_t>
(
len
);
291
penalties
=
SGVector<float64_t>
(
len
);
292
cum_derivatives
=
SGVector<float64_t>
(
len
);
293
}
294
295
for
(int32_t i=0; i<
len
; i++)
296
{
297
limits
[i]=0.0;
298
penalties
[i]=0.0;
299
cum_derivatives
[i]=0.0;
300
}
301
302
invalidate_cache
();
303
penalty_clear_derivative
();
304
}
305
310
float64_t
*
get_plif_limits
()
311
{
312
return
limits
.
vector
;
313
}
314
319
float64_t
*
get_plif_penalties
()
320
{
321
return
penalties
.
vector
;
322
}
323
328
inline
void
set_max_value
(
float64_t
p_max_value)
329
{
330
max_value
=p_max_value;
331
invalidate_cache
();
332
}
333
338
virtual
float64_t
get_max_value
()
const
339
{
340
return
max_value
;
341
}
342
347
inline
void
set_min_value
(
float64_t
p_min_value)
348
{
349
min_value
=p_min_value;
350
invalidate_cache
();
351
}
352
357
virtual
float64_t
get_min_value
()
const
358
{
359
return
min_value
;
360
}
361
366
void
set_plif_name
(
char
*p_name);
367
372
inline
char
*
get_plif_name
()
const
373
{
374
if
(
name
)
375
return
name
;
376
else
377
{
378
char
buf[20];
379
sprintf(buf,
"plif%i"
,
id
);
380
//name = strdup(buf);
381
return
strdup(buf);
382
}
383
}
384
389
bool
get_do_calc
();
390
395
void
set_do_calc
(
bool
b);
396
400
void
get_used_svms
(int32_t* num_svms, int32_t* svm_ids);
401
406
inline
int32_t
get_plif_len
()
407
{
408
return
len
;
409
}
410
415
virtual
void
list_plif
()
const
416
{
417
SG_PRINT
(
"CPlif(min_value=%1.2f, max_value=%1.2f, use_svm=%i)\n"
,
min_value
,
max_value
,
use_svm
) ;
418
}
419
425
static
void
delete_penalty_struct
(
CPlif
** PEN, int32_t P);
426
428
inline
virtual
const
char
*
get_name
()
const
{
return
"Plif"
; }
429
430
protected
:
432
int32_t
len
;
434
SGVector<float64_t>
limits
;
436
SGVector<float64_t>
penalties
;
438
SGVector<float64_t>
cum_derivatives
;
440
float64_t
max_value
;
442
float64_t
min_value
;
444
float64_t
*
cache
;
446
enum
ETransformType
transform
;
448
int32_t
id
;
450
char
*
name
;
452
int32_t
use_svm
;
454
bool
use_cache
;
458
bool
do_calc
;
459
};
460
}
461
#endif
SHOGUN
Machine Learning Toolbox - Documentation