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
preprocessor
LogPlusOne.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) 1999-2009 Soeren Sonnenburg
8
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#include <
shogun/preprocessor/LogPlusOne.h
>
12
#include <
shogun/preprocessor/DensePreprocessor.h
>
13
#include <
shogun/features/Features.h
>
14
#include <
shogun/mathematics/Math.h
>
15
16
using namespace
shogun;
17
18
CLogPlusOne::CLogPlusOne
()
19
:
CDensePreprocessor
<
float64_t
>()
20
{
21
}
22
23
24
CLogPlusOne::~CLogPlusOne
()
25
{
26
}
27
29
bool
CLogPlusOne::init(
CFeatures
* features)
30
{
31
ASSERT
(features->
get_feature_class
()==
C_DENSE
);
32
ASSERT
(features->
get_feature_type
()==
F_DREAL
);
33
34
return
true
;
35
}
36
38
void
CLogPlusOne::cleanup
()
39
{
40
}
41
43
bool
CLogPlusOne::load
(FILE* f)
44
{
45
SG_SET_LOCALE_C
;
46
SG_RESET_LOCALE
;
47
return
false
;
48
}
49
51
bool
CLogPlusOne::save
(FILE* f)
52
{
53
SG_SET_LOCALE_C
;
54
SG_RESET_LOCALE
;
55
return
false
;
56
}
57
61
SGMatrix<float64_t>
CLogPlusOne::apply_to_feature_matrix
(
CFeatures
* features)
62
{
63
SGMatrix<float64_t>
feature_matrix =
64
((
CDenseFeatures<float64_t>
*)features)->get_feature_matrix();
65
66
for
(int32_t i=0; i<feature_matrix.
num_cols
; i++)
67
{
68
for
(int32_t j=0; j<feature_matrix.
num_rows
; j++)
69
feature_matrix.
matrix
[i*feature_matrix.
num_rows
+j] =
70
CMath::log
(feature_matrix.
matrix
[i*feature_matrix.
num_rows
+j]+1.0);
71
}
72
return
feature_matrix;
73
}
74
77
SGVector<float64_t>
CLogPlusOne::apply_to_feature_vector
(
SGVector<float64_t>
vector)
78
{
79
float64_t
* log_vec =
SG_MALLOC
(
float64_t
, vector.
vlen
);
80
81
for
(int32_t i=0; i<vector.
vlen
; i++)
82
log_vec[i]=
CMath::log
(vector.
vector
[i]+1.0);
83
84
return
SGVector<float64_t>
(log_vec,vector.
vlen
);
85
}
SHOGUN
Machine Learning Toolbox - Documentation