SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MulticlassMachine.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-2011 Soeren Sonnenburg
8  * Written (W) 2012 Fernando José Iglesias García and Sergey Lisitsyn
9  * Copyright (C) 2012 Sergey Lisitsyn, Fernando José Iglesias Garcia
10  */
11 
12 #ifndef _MULTICLASSMACHINE_H___
13 #define _MULTICLASSMACHINE_H___
14 
20 
21 namespace shogun
22 {
23 
24 class CFeatures;
25 class CLabels;
26 
29 {
30  public:
33 
39  CMulticlassMachine(CMulticlassStrategy* strategy, CMachine* machine, CLabels* labels);
40 
42  virtual ~CMulticlassMachine();
43 
48  virtual void set_labels(CLabels* lab);
49 
56  inline bool set_machine(int32_t num, CMachine* machine)
57  {
58  ASSERT(num<m_machines->get_num_elements() && num>=0);
59  if (machine != NULL && !is_acceptable_machine(machine))
60  SG_ERROR("Machine %s is not acceptable by %s", machine->get_name(), this->get_name());
61 
62  m_machines->set_element(machine, num);
63  return true;
64  }
65 
71  inline CMachine* get_machine(int32_t num) const
72  {
73  return (CMachine*) m_machines->get_element_safe(num);
74  }
75 
80  virtual CBinaryLabels* get_submachine_outputs(int32_t i);
81 
87  virtual float64_t get_submachine_output(int32_t i, int32_t num);
88 
93  virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL);
94 
99  virtual CMulticlassMultipleOutputLabels* apply_multiclass_multiple_output(CFeatures* data=NULL, int32_t n_outputs=5);
100 
105  virtual float64_t apply_one(int32_t vec_idx);
106 
112  {
114  return m_multiclass_strategy;
115  }
116 
122  {
124  }
125 
130  inline void set_rejection_strategy(CRejectionStrategy* rejection_strategy)
131  {
132  m_multiclass_strategy->set_rejection_strategy(rejection_strategy);
133  }
134 
136  virtual const char* get_name() const
137  {
138  return "MulticlassMachine";
139  }
140 
141  protected:
143  void init_strategy();
144 
146  void clear_machines();
147 
149  virtual bool train_machine(CFeatures* data = NULL);
150 
152  virtual bool init_machine_for_train(CFeatures* data) = 0;
153 
155  virtual bool init_machines_for_apply(CFeatures* data) = 0;
156 
158  virtual bool is_ready() = 0;
159 
161  virtual CMachine* get_machine_from_trained(CMachine* machine) = 0;
162 
164  virtual int32_t get_num_rhs_vectors() = 0;
165 
170  virtual void add_machine_subset(SGVector<index_t> subset) = 0;
171 
173  virtual void remove_machine_subset() = 0;
174 
176  virtual bool is_acceptable_machine(CMachine *machine)
177  {
178  return true;
179  }
180 
181  private:
182 
184  void register_parameters();
185 
186  protected:
189 
192 };
193 }
194 #endif

SHOGUN Machine Learning Toolbox - Documentation