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
SplineKernel.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 Sergey Bartunov
8
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
* Copyright (C) 2010 Berlin Institute of Technology
10
*/
11
12
#include <
shogun/lib/config.h
>
13
#include <
shogun/lib/common.h
>
14
#include <
shogun/io/SGIO.h
>
15
#include <
shogun/kernel/SplineKernel.h
>
16
#include <
shogun/features/DotFeatures.h
>
17
#include <
shogun/features/DenseFeatures.h
>
18
19
using namespace
shogun;
20
21
CSplineKernel::CSplineKernel
() :
CDotKernel
()
22
{
23
}
24
25
CSplineKernel::CSplineKernel
(
CDotFeatures
* l,
CDotFeatures
* r) :
CDotKernel
()
26
{
27
init
(l,r);
28
}
29
30
CSplineKernel::~CSplineKernel
()
31
{
32
cleanup
();
33
}
34
35
bool
CSplineKernel::init(
CFeatures
* l,
CFeatures
* r)
36
{
37
ASSERT
(l->
get_feature_type
()==
F_DREAL
);
38
ASSERT
(l->
get_feature_type
()==r->
get_feature_type
());
39
40
ASSERT
(l->
get_feature_class
()==
C_DENSE
);
41
ASSERT
(l->
get_feature_class
()==r->
get_feature_class
());
42
43
CDotKernel::init(l,r);
44
return
init_normalizer
();
45
}
46
47
void
CSplineKernel::cleanup
()
48
{
49
CKernel::cleanup
();
50
}
51
52
float64_t
CSplineKernel::compute
(int32_t idx_a, int32_t idx_b)
53
{
54
int32_t alen, blen;
55
bool
afree, bfree;
56
57
float64_t
* avec = ((
CDenseFeatures<float64_t>
*)
lhs
)->get_feature_vector(idx_a, alen, afree);
58
float64_t
* bvec = ((
CDenseFeatures<float64_t>
*)
rhs
)->get_feature_vector(idx_b, blen, bfree);
59
ASSERT
(alen == blen);
60
61
float64_t
result = 0;
62
for
(int32_t i = 0; i < alen; i++) {
63
const
float64_t
x = avec[i], y = bvec[i];
64
const
float64_t
min =
CMath::min
(avec[i], bvec[i]);
65
result += 1 + x*y + x*y*min - ((x+y)/2)*min*min + min*min*min/3;
66
}
67
68
((
CDenseFeatures<float64_t>
*)
lhs
)->free_feature_vector(avec, idx_a, afree);
69
((
CDenseFeatures<float64_t>
*)
rhs
)->free_feature_vector(bvec, idx_b, bfree);
70
71
return
result;
72
}
SHOGUN
Machine Learning Toolbox - Documentation