SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
distance
SparseDistance.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) 2007-2009 Soeren Sonnenburg
8
* Copyright (C) 2007-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#ifndef _SPARSEDISTANCE_H___
12
#define _SPARSEDISTANCE_H___
13
14
#include <
shogun/distance/Distance.h
>
15
#include <
shogun/features/SparseFeatures.h
>
16
17
namespace
shogun
18
{
20
template
<
class
ST>
class
CSparseDistance
:
public
CDistance
21
{
22
public
:
24
CSparseDistance
() :
CDistance
() {}
25
32
virtual
bool
init(
CFeatures
* l,
CFeatures
* r)
33
{
34
CDistance::init(l,r);
35
36
ASSERT
(l->
get_feature_class
()==
C_SPARSE
)
37
ASSERT
(r->
get_feature_class
()==
C_SPARSE
)
38
ASSERT
(l->
get_feature_type
()==this->
get_feature_type
())
39
ASSERT
(r->
get_feature_type
()==this->
get_feature_type
())
40
41
if
(((
CSparseFeatures<ST>
*)
lhs
)->get_num_features() != ((
CSparseFeatures<ST>
*)
rhs
)->get_num_features() )
42
{
43
SG_ERROR
(
"train or test features #dimension mismatch (l:%d vs. r:%d)\n"
,
44
((
CSparseFeatures<ST>
*)
lhs
)->get_num_features(),((
CSparseFeatures<ST>
*)
rhs
)->get_num_features());
45
}
46
return
true
;
47
}
48
53
virtual
EFeatureClass
get_feature_class
() {
return
C_SPARSE
; }
54
59
virtual
EFeatureType
get_feature_type
();
60
66
virtual
const
char
*
get_name
()
const
{
67
return
"SparseDistance"
; }
68
73
virtual
void
cleanup
()=0;
74
81
virtual
EDistanceType
get_distance_type
()=0;
82
};
83
88
template
<>
inline
EFeatureType
CSparseDistance<float64_t>::get_feature_type
() {
return
F_DREAL
; }
89
94
template
<>
inline
EFeatureType
CSparseDistance<uint64_t>::get_feature_type
() {
return
F_ULONG
; }
95
100
template
<>
inline
EFeatureType
CSparseDistance<int32_t>::get_feature_type
() {
return
F_INT
; }
101
106
template
<>
inline
EFeatureType
CSparseDistance<uint16_t>::get_feature_type
() {
return
F_WORD
; }
107
112
template
<>
inline
EFeatureType
CSparseDistance<int16_t>::get_feature_type
() {
return
F_SHORT
; }
113
118
template
<>
inline
EFeatureType
CSparseDistance<uint8_t>::get_feature_type
() {
return
F_BYTE
; }
119
124
template
<>
inline
EFeatureType
CSparseDistance<char>::get_feature_type
() {
return
F_CHAR
; }
125
}
// namespace shogun
126
#endif
SHOGUN
机器学习工具包 - 项目文档