SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LinearKernel.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-2010 Soeren Sonnenburg
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/common.h>
13 #include <shogun/io/SGIO.h>
17 
18 using namespace shogun;
19 
21 : CDotKernel(0)
22 {
24 }
25 
27 : CDotKernel(0)
28 {
30  init(l,r);
31 }
32 
34 {
35  cleanup();
36 }
37 
38 bool CLinearKernel::init(CFeatures* l, CFeatures* r)
39 {
40  CDotKernel::init(l, r);
41 
42  return init_normalizer();
43 }
44 
46 {
48 
50 }
51 
52 void CLinearKernel::add_to_normal(int32_t idx, float64_t weight)
53 {
54  ((CDotFeatures*) lhs)->add_to_dense_vec(
55  normalizer->normalize_lhs(weight, idx), idx, normal.vector, normal.size());
56  set_is_initialized(true);
57 }
58 
60  int32_t num_suppvec, int32_t* sv_idx, float64_t* alphas)
61 {
62  clear_normal();
63 
64  for (int32_t i=0; i<num_suppvec; i++)
65  add_to_normal(sv_idx[i], alphas[i]);
66 
67  set_is_initialized(true);
68  return true;
69 }
70 
72 {
73  clear_normal();
74 
75  int32_t num_suppvec=km->get_num_support_vectors();
76 
77  for (int32_t i=0; i<num_suppvec; i++)
79 
80  set_is_initialized(true);
81  return true;
82 }
83 
85 {
87  set_is_initialized(false);
88 
89  return true;
90 }
91 
93 {
95  float64_t result = ((CDotFeatures*) rhs)->
96  dense_dot(idx, normal.vector, normal.size());
97  return normalizer->normalize_rhs(result, idx);
98 }

SHOGUN Machine Learning Toolbox - Documentation