SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
preprocessor
SumOne.cpp
浏览该文件的文档.
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 Sergey Lisitsyn
8
* Copyright (C) 2012 Sergey Lisitsyn
9
*/
10
11
#include <
shogun/preprocessor/SumOne.h
>
12
#include <
shogun/preprocessor/DensePreprocessor.h
>
13
#include <
shogun/mathematics/Math.h
>
14
#include <
shogun/features/Features.h
>
15
16
using namespace
shogun;
17
18
CSumOne::CSumOne
()
19
:
CDensePreprocessor
<
float64_t
>()
20
{
21
}
22
23
CSumOne::~CSumOne
()
24
{
25
}
26
28
bool
CSumOne::init(
CFeatures
* features)
29
{
30
ASSERT
(features->
get_feature_class
()==
C_DENSE
)
31
ASSERT
(features->
get_feature_type
()==
F_DREAL
)
32
33
return
true
;
34
}
35
37
void
CSumOne::cleanup
()
38
{
39
}
40
42
bool
CSumOne::load
(FILE* f)
43
{
44
SG_SET_LOCALE_C
;
45
SG_RESET_LOCALE
;
46
return
false
;
47
}
48
50
bool
CSumOne::save
(FILE* f)
51
{
52
SG_SET_LOCALE_C
;
53
SG_RESET_LOCALE
;
54
return
false
;
55
}
56
60
SGMatrix<float64_t>
CSumOne::apply_to_feature_matrix
(
CFeatures
* features)
61
{
62
SGMatrix<float64_t>
feature_matrix=((
CDenseFeatures<float64_t>
*)features)->get_feature_matrix();
63
64
for
(int32_t i=0; i<feature_matrix.
num_cols
; i++)
65
{
66
float64_t
* vec= &(feature_matrix.
matrix
[i*feature_matrix.
num_rows
]);
67
float64_t
sum =
SGVector<float64_t>::sum
(vec,feature_matrix.
num_rows
);
68
SGVector<float64_t>::scale_vector
(1.0/sum, vec, feature_matrix.
num_rows
);
69
}
70
return
feature_matrix;
71
}
72
75
SGVector<float64_t>
CSumOne::apply_to_feature_vector
(
SGVector<float64_t>
vector)
76
{
77
float64_t
* normed_vec = SG_MALLOC(
float64_t
, vector.
vlen
);
78
float64_t
sum =
SGVector<float64_t>::sum
(vector.
vector
, vector.
vlen
);
79
80
for
(int32_t i=0; i<vector.
vlen
; i++)
81
normed_vec[i]=vector.
vector
[i]/sum;
82
83
return
SGVector<float64_t>
(normed_vec,vector.
vlen
);
84
}
SHOGUN
机器学习工具包 - 项目文档