SHOGUN
v1.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
shogun
kernel
CustomKernel.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) 1999-2009 Soeren Sonnenburg
8
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9
*/
10
11
#include <
shogun/lib/common.h
>
12
#include <
shogun/kernel/CustomKernel.h
>
13
#include <
shogun/features/Features.h
>
14
#include <
shogun/features/DummyFeatures.h
>
15
#include <
shogun/io/SGIO.h
>
16
17
using namespace
shogun;
18
19
void
20
CCustomKernel::init()
21
{
22
m_parameters
->
add
(&
kmatrix
,
"kmatrix"
,
"Kernel matrix."
);
23
m_parameters
->
add
(&
upper_diagonal
,
"upper_diagonal"
);
24
}
25
26
CCustomKernel::CCustomKernel
()
27
:
CKernel
(10), kmatrix(), upper_diagonal(false)
28
{
29
init();
30
}
31
32
CCustomKernel::CCustomKernel
(
CKernel
* k)
33
:
CKernel
(10)
34
{
35
set_full_kernel_matrix_from_full
(k->
get_kernel_matrix
());
36
}
37
38
CCustomKernel::CCustomKernel
(
SGMatrix<float64_t>
km)
39
:
CKernel
(10), upper_diagonal(false)
40
{
41
init();
42
set_full_kernel_matrix_from_full
(km);
43
}
44
45
CCustomKernel::~CCustomKernel
()
46
{
47
cleanup
();
48
}
49
50
bool
CCustomKernel::dummy_init
(int32_t rows, int32_t cols)
51
{
52
return
init(
new
CDummyFeatures
(rows),
new
CDummyFeatures
(cols));
53
}
54
55
bool
CCustomKernel::init(
CFeatures
* l,
CFeatures
* r)
56
{
57
CKernel::init(l, r);
58
59
SG_DEBUG
(
"num_vec_lhs: %d vs num_rows %d\n"
, l->
get_num_vectors
(),
kmatrix
.
num_rows
);
60
SG_DEBUG
(
"num_vec_rhs: %d vs num_cols %d\n"
, r->
get_num_vectors
(),
kmatrix
.
num_cols
);
61
ASSERT
(l->
get_num_vectors
()==
kmatrix
.
num_rows
);
62
ASSERT
(r->
get_num_vectors
()==
kmatrix
.
num_cols
);
63
return
init_normalizer
();
64
}
65
66
void
CCustomKernel::cleanup_custom()
67
{
68
SG_DEBUG
(
"cleanup up custom kernel\n"
);
69
SG_FREE
(
kmatrix
.
matrix
);
70
kmatrix
.
matrix
=NULL;
71
upper_diagonal
=
false
;
72
kmatrix
.
num_cols
=0;
73
kmatrix
.
num_rows
=0;
74
}
75
76
void
CCustomKernel::cleanup
()
77
{
78
cleanup_custom();
79
CKernel::cleanup
();
80
}
81
SHOGUN
Machine Learning Toolbox - Documentation