SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
kernel
SparseKernel.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-2009 Soeren Sonnenburg
8
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#ifndef _SPARSEKERNEL_H___
12
#define _SPARSEKERNEL_H___
13
14
#include <
shogun/kernel/Kernel.h
>
15
#include <
shogun/features/SparseFeatures.h
>
16
17
namespace
shogun
18
{
24
template
<
class
ST>
class
CSparseKernel
:
public
CKernel
25
{
26
public
:
31
CSparseKernel
(int32_t cachesize) :
CKernel
(cachesize) {}
32
38
CSparseKernel
(
CFeatures
* l,
CFeatures
* r) :
CKernel
(10)
39
{
40
init
(l, r);
41
}
42
49
virtual
bool
init
(
CFeatures
* l,
CFeatures
* r)
50
{
51
CKernel::init(l,r);
52
53
ASSERT
(l->
get_feature_class
()==
C_SPARSE
)
54
ASSERT
(r->
get_feature_class
()==
C_SPARSE
)
55
ASSERT
(l->
get_feature_type
()==this->
get_feature_type
())
56
ASSERT
(r->
get_feature_type
()==this->
get_feature_type
())
57
58
if
(((
CSparseFeatures<ST>
*)
lhs
)->get_num_features() != ((
CSparseFeatures<ST>
*)
rhs
)->get_num_features())
59
{
60
SG_ERROR
(
"train or test features #dimension mismatch (l:%d vs. r:%d)\n"
,
61
((
CSparseFeatures<ST>
*)
lhs
)->get_num_features(),((
CSparseFeatures<ST>
*)
rhs
)->get_num_features());
62
}
63
return
true
;
64
}
65
70
virtual
EFeatureClass
get_feature_class
() {
return
C_SPARSE
; }
71
76
virtual
EFeatureType
get_feature_type
();
77
83
virtual
const
char
*
get_name
()
const
{
84
return
"SparseKernel"
; }
85
93
virtual
EKernelType
get_kernel_type
()=0;
94
};
95
96
template
<>
inline
EFeatureType
CSparseKernel<float64_t>::get_feature_type
() {
return
F_DREAL
; }
97
98
template
<>
inline
EFeatureType
CSparseKernel<uint64_t>::get_feature_type
() {
return
F_ULONG
; }
99
100
template
<>
inline
EFeatureType
CSparseKernel<int32_t>::get_feature_type
() {
return
F_INT
; }
101
102
template
<>
inline
EFeatureType
CSparseKernel<uint16_t>::get_feature_type
() {
return
F_WORD
; }
103
104
template
<>
inline
EFeatureType
CSparseKernel<int16_t>::get_feature_type
() {
return
F_SHORT
; }
105
106
template
<>
inline
EFeatureType
CSparseKernel<uint8_t>::get_feature_type
() {
return
F_BYTE
; }
107
108
template
<>
inline
EFeatureType
CSparseKernel<char>::get_feature_type
() {
return
F_CHAR
; }
109
}
110
#endif
/* _SPARSEKERNEL_H__ */
SHOGUN
机器学习工具包 - 项目文档