SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
MCLDA.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) 2013 Kevin Hughes
8  * Copyright (C) 2013 Kevin Hughes
9  *
10  * Thanks to Fernando José Iglesias García (shogun)
11  * and Matthieu Perrot (scikit-learn)
12  */
13 
14 #ifndef _MCLDA_H__
15 #define _MCLDA_H__
16 
17 #include <shogun/lib/config.h>
18 
19 
23 #include <shogun/lib/SGNDArray.h>
24 
25 namespace shogun
26 {
27 
28 //#define DEBUG_MCLDA
29 
39 {
40  public:
42 
43 
48  CMCLDA(float64_t tolerance = 1e-4, bool store_cov = false);
49 
57  CMCLDA(CDenseFeatures<float64_t>* traindat, CLabels* trainlab, float64_t tolerance = 1e-4, bool store_cov = false);
58 
59  virtual ~CMCLDA();
60 
66  virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL);
67 
72  inline void set_tolerance(float64_t tolerance) { m_tolerance = tolerance; }
73 
78  inline bool get_tolerance() { return m_tolerance; }
79 
84  virtual EMachineType get_classifier_type() { return CT_LDA; } // for now add to machine typers properly later
85 
90  virtual void set_features(CDotFeatures* feat)
91  {
92  if (feat->get_feature_class() != C_DENSE ||
93  feat->get_feature_type() != F_DREAL)
94  SG_ERROR("MCLDA requires SIMPLE REAL valued features\n")
95 
96  SG_REF(feat);
97  SG_UNREF(m_features);
98  m_features = feat;
99  }
100 
105  virtual CDotFeatures* get_features() { SG_REF(m_features); return m_features; }
106 
111  virtual const char* get_name() const { return "MCLDA"; }
112 
119  inline SGVector< float64_t > get_mean(int32_t c) const
120  {
121  return SGVector< float64_t >(m_means.get_column_vector(c), m_dim, false);
122  }
123 
129  {
130  return m_cov;
131  }
132 
133  protected:
140  virtual bool train_machine(CFeatures* data = NULL);
141 
142  private:
143  void init();
144 
145  void cleanup();
146 
147  private:
149  CDotFeatures* m_features;
150 
152  float64_t m_tolerance;
153 
155  bool m_store_cov;
156 
158  int32_t m_num_classes;
159 
161  int32_t m_dim;
162 
166  SGMatrix< float64_t > m_cov;
167 
169  SGMatrix< float64_t > m_means;
170 
172  SGVector< float64_t > m_xbar;
173 
175  int32_t m_rank;
176 
178  SGMatrix< float64_t > m_scalings;
179 
181  SGMatrix< float64_t > m_coef;
182 
184  SGVector< float64_t > m_intercept;
185 
186 }; /* class MCLDA */
187 } /* namespace shogun */
188 
189 #endif /* _MCLDA_H__ */
EMachineType
Definition: Machine.h:33
SGVector< float64_t > get_mean(int32_t c) const
Definition: MCLDA.h:119
CMCLDA(float64_t tolerance=1e-4, bool store_cov=false)
Definition: MCLDA.cpp:29
experimental abstract native multiclass machine class
virtual ~CMCLDA()
Definition: MCLDA.cpp:50
SGMatrix< float64_t > get_cov() const
Definition: MCLDA.h:128
virtual CMulticlassLabels * apply_multiclass(CFeatures *data=NULL)
Definition: MCLDA.cpp:81
virtual bool train_machine(CFeatures *data=NULL)
Definition: MCLDA.cpp:153
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
Class MCLDA implements multiclass Linear Discriminant Analysis.
Definition: MCLDA.h:38
#define SG_ERROR(...)
Definition: SGIO.h:129
virtual void set_features(CDotFeatures *feat)
Definition: MCLDA.h:90
Features that support dot products among other operations.
Definition: DotFeatures.h:44
#define SG_REF(x)
Definition: SGObject.h:54
Multiclass Labels for multi-class classification.
virtual EMachineType get_classifier_type()
Definition: MCLDA.h:84
#define MACHINE_PROBLEM_TYPE(PT)
Definition: Machine.h:120
bool get_tolerance()
Definition: MCLDA.h:78
double float64_t
Definition: common.h:50
virtual EFeatureClass get_feature_class() const =0
T * get_column_vector(index_t col) const
Definition: SGMatrix.h:113
virtual CDotFeatures * get_features()
Definition: MCLDA.h:105
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
void set_tolerance(float64_t tolerance)
Definition: MCLDA.h:72
virtual const char * get_name() const
Definition: MCLDA.h:111
virtual EFeatureType get_feature_type() const =0

SHOGUN Machine Learning Toolbox - Documentation