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
SphericalKernel.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
* Based on GaussianKernel, Written (W) 1999-2010 Soeren Sonnenburg
8
* Written (W) 2011 Shashwat Lal Das
9
* Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
10
*/
11
12
#include <
shogun/kernel/SphericalKernel.h
>
13
#include <
shogun/mathematics/Math.h
>
14
15
using namespace
shogun;
16
17
CSphericalKernel::CSphericalKernel
():
CKernel
(0),
distance
(NULL)
18
{
19
init
();
20
set_sigma
(1.0);
21
}
22
23
CSphericalKernel::CSphericalKernel
(int32_t size,
float64_t
sig,
CDistance
* dist)
24
:
CKernel
(size),
distance
(dist)
25
{
26
ASSERT
(
distance
)
27
SG_REF
(
distance
);
28
init
();
29
set_sigma
(sig);
30
}
31
32
CSphericalKernel::CSphericalKernel
(
33
CFeatures
*l,
CFeatures
*r,
float64_t
sig,
CDistance
* dist)
34
:
CKernel
(10),
distance
(dist)
35
{
36
ASSERT
(
distance
)
37
SG_REF
(
distance
);
38
init
();
39
set_sigma
(sig);
40
init
(l, r);
41
}
42
43
CSphericalKernel::~CSphericalKernel
()
44
{
45
cleanup
();
46
SG_UNREF
(
distance
);
47
}
48
49
bool
CSphericalKernel::init
(
CFeatures
* l,
CFeatures
* r)
50
{
51
ASSERT
(
distance
)
52
CKernel::init
(l,r);
53
distance
->
init
(l,r);
54
return
init_normalizer
();
55
}
56
57
void
CSphericalKernel::init
()
58
{
59
SG_ADD
((
CSGObject
**) &
distance
,
"distance"
,
"Distance to be used."
,
60
MS_AVAILABLE
);
61
SG_ADD
(&
sigma
,
"sigma"
,
"Sigma kernel parameter."
,
MS_AVAILABLE
);
62
}
63
64
float64_t
CSphericalKernel::compute
(int32_t idx_a, int32_t idx_b)
65
{
66
float64_t
dist=
distance
->
distance
(idx_a, idx_b);
67
float64_t
ds_ratio=dist/
sigma
;
68
69
if
(dist <
sigma
)
70
return
1.0-1.5*(ds_ratio)+0.5*(ds_ratio*ds_ratio*ds_ratio);
71
else
72
return
0;
73
}
SHOGUN
Machine Learning Toolbox - Documentation