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