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
LogKernel.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 Jakub Jirku
8
* Copyright (C) 2007-2011 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#include <
shogun/kernel/LogKernel.h
>
12
#include <
shogun/mathematics/Math.h
>
13
14
using namespace
shogun;
15
16
CLogKernel::CLogKernel
():
CKernel
(0), m_distance(NULL), m_degree(1.8)
17
{
18
init
();
19
}
20
21
CLogKernel::CLogKernel
(int32_t cache,
float64_t
degree,
CDistance
* dist)
22
:
CKernel
(cache), m_distance(dist), m_degree(degree)
23
{
24
init
();
25
ASSERT
(
m_distance
)
26
SG_REF
(
m_distance
);
27
}
28
29
CLogKernel::CLogKernel
(
CFeatures
*l,
CFeatures
*r,
float64_t
degree,
CDistance
* dist)
30
:
CKernel
(10), m_distance(dist), m_degree(degree)
31
{
32
init
();
33
ASSERT
(
m_distance
)
34
SG_REF
(
m_distance
);
35
init
(l, r);
36
}
37
38
CLogKernel::~CLogKernel
()
39
{
40
cleanup
();
41
SG_UNREF
(
m_distance
);
42
}
43
44
bool
CLogKernel::init(
CFeatures
* l,
CFeatures
* r)
45
{
46
ASSERT
(
m_distance
)
47
CKernel::init(l,r);
48
m_distance
->
init
(l,r);
49
return
init_normalizer
();
50
}
51
52
void
CLogKernel::init()
53
{
54
SG_ADD
(&
m_degree
,
"degree"
,
"Degree kernel parameter."
,
MS_AVAILABLE
);
55
SG_ADD
((
CSGObject
**) &
m_distance
,
"distance"
,
"Distance to be used."
,
56
MS_AVAILABLE
);
57
}
58
59
float64_t
CLogKernel::compute
(int32_t idx_a, int32_t idx_b)
60
{
61
float64_t
dist =
m_distance
->
distance
(idx_a, idx_b);
62
float64_t
temp = pow(dist,
m_degree
);
63
temp = log(temp + 1);
64
return
-temp;
65
}
SHOGUN
Machine Learning Toolbox - Documentation