SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KernelMulticlassMachine.h
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-2012 Soeren Sonnenburg and Sergey Lisitsyn
8  * Written (W) 2012 Heiko Strathmann
9  * Copyright (C) 1999-2012 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
11 
12 #ifndef _KERNELMULTICLASSMACHINE_H___
13 #define _KERNELMULTICLASSMACHINE_H___
14 
15 #include <shogun/lib/common.h>
17 #include <shogun/kernel/Kernel.h>
20 
21 namespace shogun
22 {
23 
24 class CKernel;
25 class CKernelMachine;
26 
29 {
30  public:
33  {
34  SG_ADD((CSGObject**)&m_kernel,"kernel", "The kernel to be used", MS_AVAILABLE);
35  }
36 
44  CMulticlassMachine(strategy,(CMachine*)machine,labs), m_kernel(NULL)
45  {
46  set_kernel(kernel);
47  SG_ADD((CSGObject**)&m_kernel,"kernel", "The kernel to be used", MS_AVAILABLE);
48  }
49 
52  {
54  }
55 
57  virtual const char* get_name() const
58  {
59  return "KernelMulticlassMachine";
60  }
61 
67  {
68  ((CKernelMachine*)m_machine)->set_kernel(k);
69  SG_REF(k);
71  m_kernel=k;
72  }
73 
79  {
81  return m_kernel;
82  }
83 
90  virtual void store_model_features();
91 
92  protected:
93 
95  virtual bool init_machine_for_train(CFeatures* data)
96  {
97  if (data)
98  m_kernel->init(data,data);
99 
100  ((CKernelMachine*)m_machine)->set_kernel(m_kernel);
101 
102  return true;
103  }
104 
106  virtual bool init_machines_for_apply(CFeatures* data)
107  {
108  if (data)
109  {
110  /* set data to rhs for this kernel */
111  CFeatures* lhs=m_kernel->get_lhs();
112  m_kernel->init(lhs, data);
113  SG_UNREF(lhs);
114  }
115 
116  /* set kernel to all sub-machines */
117  for (int32_t i=0; i<m_machines->get_num_elements(); i++)
118  {
119  CKernelMachine *machine=
121  machine->set_kernel(m_kernel);
122  SG_UNREF(machine);
123  }
124 
125  return true;
126  }
127 
129  virtual bool is_ready()
130  {
132  return true;
133 
134  return false;
135  }
136 
139  {
140  return new CKernelMachine((CKernelMachine*)machine);
141  }
142 
144  virtual int32_t get_num_rhs_vectors()
145  {
146  return m_kernel->get_num_vec_rhs();
147  }
148 
154  {
156  }
157 
159  virtual void remove_machine_subset()
160  {
162  }
163 
164  protected:
165 
168 
169 };
170 }
171 #endif

SHOGUN Machine Learning Toolbox - Documentation