SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
distance
AttenuatedEuclideanDistance.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) 2011 Miguel Angel Bautista
8
* Copyright (C) 2011 Berlin Institute of Technology and Max Planck Society
9
*/
10
11
#include <
shogun/lib/common.h
>
12
#include <
shogun/io/SGIO.h
>
13
#include <
shogun/distance/AttenuatedEuclideanDistance.h
>
14
#include <
shogun/features/Features.h
>
15
16
using namespace
shogun;
17
18
CAttenuatedEuclideanDistance::CAttenuatedEuclideanDistance
() :
CRealDistance
()
19
{
20
init
();
21
}
22
23
CAttenuatedEuclideanDistance::CAttenuatedEuclideanDistance
(
CDenseFeatures<float64_t>
* l,
CDenseFeatures<float64_t>
* r)
24
:
CRealDistance
()
25
{
26
init
();
27
init
(l, r);
28
}
29
30
CAttenuatedEuclideanDistance::~CAttenuatedEuclideanDistance
()
31
{
32
cleanup
();
33
}
34
35
bool
CAttenuatedEuclideanDistance::init(
CFeatures
* l,
CFeatures
* r)
36
{
37
CRealDistance::init(l, r);
38
return
true
;
39
}
40
41
void
CAttenuatedEuclideanDistance::cleanup
()
42
{
43
}
44
45
float64_t
CAttenuatedEuclideanDistance::compute
(int32_t idx_a, int32_t idx_b)
46
{
47
int32_t alen, blen;
48
bool
afree, bfree;
49
float64_t
result=0;
50
51
float64_t
* avec=((
CDenseFeatures<float64_t>
*)
lhs
)->
52
get_feature_vector(idx_a, alen, afree);
53
float64_t
* bvec=((
CDenseFeatures<float64_t>
*)
rhs
)->
54
get_feature_vector(idx_b, blen, bfree);
55
ASSERT
(alen==blen)
56
57
for
(int32_t i=0; i<alen; i++)
58
result+=(
CMath::abs
(avec[i])*
CMath::abs
(bvec[i]))*
CMath::pow
(avec[i] - bvec[i],2);
59
60
((
CDenseFeatures<float64_t>
*)
lhs
)->free_feature_vector(avec, idx_a, afree);
61
((
CDenseFeatures<float64_t>
*)
rhs
)->free_feature_vector(bvec, idx_b, bfree);
62
63
if
(
disable_sqrt
)
64
return
result;
65
66
return
CMath::sqrt
(result);
67
}
68
69
void
CAttenuatedEuclideanDistance::init()
70
{
71
disable_sqrt
=
false
;
72
73
m_parameters
->
add
(&
disable_sqrt
,
"disable_sqrt"
,
"If sqrt shall not be applied."
);
74
}
SHOGUN
机器学习工具包 - 项目文档