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
distance
KernelDistance.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) 2010 Christian Widmer
8
* Copyright (C) 2010 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/distance/KernelDistance.h
>
16
#include <
shogun/features/DenseFeatures.h
>
17
18
using namespace
shogun;
19
20
CKernelDistance::CKernelDistance
() :
CDistance
()
21
{
22
init
();
23
}
24
25
CKernelDistance::CKernelDistance
(
float64_t
w,
CKernel
* k)
26
:
CDistance
()
27
{
28
init
();
29
30
kernel=k;
31
width=w;
32
ASSERT
(kernel)
33
SG_REF
(kernel);
34
}
35
36
CKernelDistance::CKernelDistance
(
37
CFeatures
*l,
CFeatures
*r,
float64_t
w ,
CKernel
* k)
38
:
CDistance
()
39
{
40
init
();
41
42
kernel=k;
43
width=w;
44
ASSERT
(kernel)
45
SG_REF
(kernel);
46
47
init
(l, r);
48
}
49
50
CKernelDistance::~CKernelDistance
()
51
{
52
// important to have the cleanup of CDistance first, it calls get_name which
53
// uses the distance
54
cleanup
();
55
SG_UNREF
(kernel);
56
}
57
58
bool
CKernelDistance::init(
CFeatures
* l,
CFeatures
* r)
59
{
60
ASSERT
(kernel)
61
kernel->
init
(l,r);
62
return
CDistance::init(l,r);
63
}
64
65
float64_t
CKernelDistance::compute
(int32_t idx_a, int32_t idx_b)
66
{
67
float64_t
result=kernel->
kernel
(idx_a, idx_b);
68
return
exp(-result/width);
69
}
70
71
void
CKernelDistance::init()
72
{
73
kernel = NULL;
74
width = 0.0;
75
76
m_parameters
->
add
(&width,
"width"
,
"Width of RBF Kernel"
);
77
m_parameters
->
add
((
CSGObject
**) &kernel,
"kernel"
,
78
"Kernel."
);
79
}
SHOGUN
Machine Learning Toolbox - Documentation