SHOGUN
v1.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
shogun
distance
AttenuatedEuclidianDistance.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) 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/AttenuatedEuclidianDistance.h
>
14
#include <
shogun/features/Features.h
>
15
#include <
shogun/features/SimpleFeatures.h
>
16
17
using namespace
shogun;
18
19
CAttenuatedEuclidianDistance::CAttenuatedEuclidianDistance
() :
CRealDistance
()
20
{
21
init
();
22
}
23
24
CAttenuatedEuclidianDistance::CAttenuatedEuclidianDistance
(
CSimpleFeatures<float64_t>
* l,
CSimpleFeatures<float64_t>
* r)
25
:
CRealDistance
()
26
{
27
init
();
28
init
(l, r);
29
}
30
31
CAttenuatedEuclidianDistance::~CAttenuatedEuclidianDistance
()
32
{
33
cleanup
();
34
}
35
36
bool
CAttenuatedEuclidianDistance::init(
CFeatures
* l,
CFeatures
* r)
37
{
38
CRealDistance::init(l, r);
39
return
true
;
40
}
41
42
void
CAttenuatedEuclidianDistance::cleanup
()
43
{
44
}
45
46
float64_t
CAttenuatedEuclidianDistance::compute
(int32_t idx_a, int32_t idx_b)
47
{
48
int32_t alen, blen;
49
bool
afree, bfree;
50
float64_t
result=0;
51
52
float64_t
* avec=((
CSimpleFeatures<float64_t>
*)
lhs
)->
53
get_feature_vector(idx_a, alen, afree);
54
float64_t
* bvec=((
CSimpleFeatures<float64_t>
*)
rhs
)->
55
get_feature_vector(idx_b, blen, bfree);
56
ASSERT
(alen==blen);
57
58
for
(int32_t i=0; i<alen; i++)
59
result+=(
CMath::abs
(avec[i])*
CMath::abs
(bvec[i]))*
CMath::pow
(avec[i] - bvec[i],2);
60
61
((
CSimpleFeatures<float64_t>
*)
lhs
)->free_feature_vector(avec, idx_a, afree);
62
((
CSimpleFeatures<float64_t>
*)
rhs
)->free_feature_vector(bvec, idx_b, bfree);
63
64
if
(
disable_sqrt
)
65
return
result;
66
67
return
CMath::sqrt
(result);
68
}
69
70
void
CAttenuatedEuclidianDistance::init()
71
{
72
disable_sqrt
=
false
;
73
74
m_parameters
->
add
(&
disable_sqrt
,
"disable_sqrt"
,
"If sqrt shall not be applied."
);
75
}
SHOGUN
Machine Learning Toolbox - Documentation