SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 }
virtual void cleanup()
Definition: Kernel.cpp:162
virtual float64_t normalize_rhs(float64_t value, int32_t idx_rhs)=0
virtual float64_t compute_optimized(int32_t idx)
virtual bool delete_optimization()
void set_is_initialized(bool p_init)
Definition: Kernel.h:899
uint64_t properties
Definition: Kernel.h:1082
A generic KernelMachine interface.
Definition: KernelMachine.h:51
Features that support dot products among other operations.
Definition: DotFeatures.h:44
bool get_is_initialized()
Definition: Kernel.h:753
int32_t size() const
Definition: SGVector.h:115
Template class DotKernel is the base class for kernels working on DotFeatures.
Definition: DotKernel.h:31
virtual void clear_normal()
Definition: LinearKernel.h:103
#define ASSERT(x)
Definition: SGIO.h:201
double float64_t
Definition: common.h:50
float64_t get_alpha(int32_t idx)
virtual void add_to_normal(int32_t idx, float64_t weight)
int32_t get_support_vector(int32_t idx)
SGVector< float64_t > normal
Definition: LinearKernel.h:139
virtual bool init(CFeatures *l, CFeatures *r)
virtual bool init_normalizer()
Definition: Kernel.cpp:157
CFeatures * rhs
feature vectors to occur on right hand side
Definition: Kernel.h:1061
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CFeatures * lhs
feature vectors to occur on left hand side
Definition: Kernel.h:1059
The class Features is the base class of all feature objects.
Definition: Features.h:68
CKernelNormalizer * normalizer
Definition: Kernel.h:1086
virtual void cleanup()
virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)=0
virtual bool init_optimization(int32_t num_suppvec, int32_t *sv_idx, float64_t *alphas)

SHOGUN Machine Learning Toolbox - Documentation