SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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  * Written (W) 2013 Shell Hu and Heiko Strathmann
10  * Copyright (C) 2012 Sergey Lisitsyn, Fernando José Iglesias Garcia
11  */
12 
13 #ifndef _MULTICLASSMACHINE_H___
14 #define _MULTICLASSMACHINE_H___
15 
16 #include <shogun/lib/config.h>
17 
21 
22 namespace shogun
23 {
24 
25 class CFeatures;
26 class CLabels;
27 class CMulticlassLabels;
28 class CMultilabelLabels;
29 
32 {
33  public:
36 
42  CMulticlassMachine(CMulticlassStrategy* strategy, CMachine* machine, CLabels* labels);
43 
45  virtual ~CMulticlassMachine();
46 
51  virtual void set_labels(CLabels* lab);
52 
59  inline bool set_machine(int32_t num, CMachine* machine)
60  {
61  ASSERT(num<m_machines->get_num_elements() && num>=0)
62  if (machine != NULL && !is_acceptable_machine(machine))
63  SG_ERROR("Machine %s is not acceptable by %s", machine->get_name(), this->get_name())
64 
65  m_machines->set_element(machine, num);
66  return true;
67  }
68 
74  inline CMachine* get_machine(int32_t num) const
75  {
76  return (CMachine*) m_machines->get_element_safe(num);
77  }
78 
83  virtual CBinaryLabels* get_submachine_outputs(int32_t i);
84 
90  virtual float64_t get_submachine_output(int32_t i, int32_t num);
91 
96  virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL);
97 
102  virtual CMultilabelLabels* apply_multilabel_output(CFeatures* data=NULL, int32_t n_outputs=5);
103 
108  virtual float64_t apply_one(int32_t vec_idx);
109 
115  {
117  return m_multiclass_strategy;
118  }
119 
125  {
127  }
128 
133  inline void set_rejection_strategy(CRejectionStrategy* rejection_strategy)
134  {
135  m_multiclass_strategy->set_rejection_strategy(rejection_strategy);
136  }
137 
139  virtual const char* get_name() const
140  {
141  return "MulticlassMachine";
142  }
143 
146  {
148  }
149 
153  inline void set_prob_heuris(EProbHeuristicType prob_heuris)
154  {
156  }
157 
158  protected:
160  void init_strategy();
161 
163  void clear_machines();
164 
166  virtual bool train_machine(CFeatures* data = NULL);
167 
169  virtual bool init_machine_for_train(CFeatures* data) = 0;
170 
172  virtual bool init_machines_for_apply(CFeatures* data) = 0;
173 
175  virtual bool is_ready() = 0;
176 
178  virtual CMachine* get_machine_from_trained(CMachine* machine) = 0;
179 
181  virtual int32_t get_num_rhs_vectors() = 0;
182 
187  virtual void add_machine_subset(SGVector<index_t> subset) = 0;
188 
190  virtual void remove_machine_subset() = 0;
191 
193  virtual bool is_acceptable_machine(CMachine *machine)
194  {
195  return true;
196  }
197 
198  private:
199 
201  void register_parameters();
202 
203  protected:
206 
209 };
210 }
211 #endif
CMachine * get_machine(int32_t num) const
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual CMulticlassLabels * apply_multiclass(CFeatures *data=NULL)
virtual bool is_acceptable_machine(CMachine *machine)
#define SG_ERROR(...)
Definition: SGIO.h:129
CRejectionStrategy * get_rejection_strategy() const
virtual CMachine * get_machine_from_trained(CMachine *machine)=0
virtual void add_machine_subset(SGVector< index_t > subset)=0
virtual const char * get_name() const
Definition: Machine.h:305
CRejectionStrategy * get_rejection_strategy()
virtual float64_t get_submachine_output(int32_t i, int32_t num)
void set_prob_heuris_type(EProbHeuristicType prob_heuris)
#define SG_REF(x)
Definition: SGObject.h:51
bool set_element(CSGObject *e, int32_t idx1, int32_t idx2=0, int32_t idx3=0)
A generic learning machine interface.
Definition: Machine.h:143
Multiclass Labels for multi-class classification.
virtual bool init_machine_for_train(CFeatures *data)=0
virtual bool is_ready()=0
#define ASSERT(x)
Definition: SGIO.h:201
CMulticlassStrategy * m_multiclass_strategy
double float64_t
Definition: common.h:50
experimental abstract generic multiclass machine class
CMulticlassStrategy * get_multiclass_strategy() const
virtual CBinaryLabels * get_submachine_outputs(int32_t i)
virtual CMultilabelLabels * apply_multilabel_output(CFeatures *data=NULL, int32_t n_outputs=5)
virtual bool init_machines_for_apply(CFeatures *data)=0
base rejection strategy class
virtual float64_t apply_one(int32_t vec_idx)
virtual void remove_machine_subset()=0
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CSGObject * get_element_safe(int32_t index) const
The class Features is the base class of all feature objects.
Definition: Features.h:68
void set_rejection_strategy(CRejectionStrategy *rejection_strategy)
void set_prob_heuris(EProbHeuristicType prob_heuris)
Binary Labels for binary classification.
Definition: BinaryLabels.h:37
class MulticlassStrategy used to construct generic multiclass classifiers with ensembles of binary cl...
EProbHeuristicType get_prob_heuris()
virtual bool train_machine(CFeatures *data=NULL)
virtual const char * get_name() const
virtual int32_t get_num_rhs_vectors()=0
Multilabel Labels for multi-label classification.
void set_rejection_strategy(CRejectionStrategy *rejection_strategy)
bool set_machine(int32_t num, CMachine *machine)
virtual void set_labels(CLabels *lab)
EProbHeuristicType get_prob_heuris_type()

SHOGUN Machine Learning Toolbox - Documentation