SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
kernel
DistanceKernel.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) 2007-2009 Christian Gehl
8
* Copyright (C) 2007-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#include <
shogun/lib/config.h
>
12
13
#include <
shogun/lib/common.h
>
14
#include <
shogun/io/SGIO.h
>
15
#include <
shogun/kernel/DistanceKernel.h
>
16
#include <
shogun/features/DenseFeatures.h
>
17
18
using namespace
shogun;
19
20
CDistanceKernel::CDistanceKernel
()
21
:
CKernel
(0),
distance
(NULL), width(0.0)
22
{
23
register_params
();
24
}
25
26
CDistanceKernel::CDistanceKernel
(int32_t size,
float64_t
w,
CDistance
* d)
27
:
CKernel
(size),
distance
(d)
28
{
29
ASSERT
(
distance
)
30
set_width
(w);
31
SG_REF
(
distance
);
32
register_params
();
33
}
34
35
CDistanceKernel::CDistanceKernel
(
36
CFeatures
*l,
CFeatures
*r,
float64_t
w ,
CDistance
* d)
37
:
CKernel
(10),
distance
(d)
38
{
39
set_width
(w);
40
ASSERT
(
distance
)
41
SG_REF
(
distance
);
42
init
(l, r);
43
register_params
();
44
}
45
46
CDistanceKernel::~CDistanceKernel
()
47
{
48
// important to have the cleanup of CKernel first, it calls get_name which
49
// uses the distance
50
cleanup
();
51
SG_UNREF
(
distance
);
52
}
53
54
bool
CDistanceKernel::init(
CFeatures
* l,
CFeatures
* r)
55
{
56
ASSERT
(
distance
)
57
CKernel::init(l,r);
58
distance
->
init
(l,r);
59
return
init_normalizer
();
60
}
61
62
float64_t
CDistanceKernel::compute
(int32_t idx_a, int32_t idx_b)
63
{
64
float64_t
result=
distance
->
distance
(idx_a, idx_b);
65
return
exp(-result/
width
);
66
}
67
68
void
CDistanceKernel::register_params
()
69
{
70
SG_ADD
(&
width
,
"width"
,
"Kernel width."
,
MS_AVAILABLE
);
71
SG_ADD
((
CSGObject
**) &
distance
,
"distance"
,
"Distance to be used."
,
72
MS_AVAILABLE
);
73
}
SHOGUN
Machine Learning Toolbox - Documentation