SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
QDA.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) 2012 Fernando José Iglesias García
8  * Copyright (C) 2012 Fernando José Iglesias García
9  */
10 
11 #ifndef _QDA_H__
12 #define _QDA_H__
13 
14 #include <shogun/lib/config.h>
15 
16 
20 #include <shogun/lib/SGNDArray.h>
21 
22 namespace shogun
23 {
24 
25 //#define DEBUG_QDA
26 
36 {
37  public:
39 
40 
41  CQDA();
42 
48  CQDA(float64_t tolerance, bool store_covs);
49 
55  CQDA(CDenseFeatures<float64_t>* traindat, CLabels* trainlab);
56 
63  CQDA(CDenseFeatures<float64_t>* traindat, CLabels* trainlab, float64_t tolerance);
64 
71  CQDA(CDenseFeatures<float64_t>* traindat, CLabels* trainlab, bool store_covs);
72 
80  CQDA(CDenseFeatures<float64_t>* traindat, CLabels* trainlab, float64_t tolerance, bool store_covs);
81 
82  virtual ~CQDA();
83 
89  virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL);
90 
95  inline void set_store_covs(bool store_covs) { m_store_covs = store_covs; }
96 
101  inline bool get_store_covs() { return m_store_covs; }
102 
107  inline void set_tolerance(float64_t tolerance) { m_tolerance = tolerance; }
108 
113  inline bool get_tolerance() { return m_tolerance; }
114 
120 
125  virtual void set_features(CDotFeatures* feat)
126  {
127  if (feat->get_feature_class() != C_DENSE ||
128  feat->get_feature_type() != F_DREAL)
129  SG_ERROR("QDA requires SIMPLE REAL valued features\n")
130 
131  SG_REF(feat);
132  SG_UNREF(m_features);
133  m_features = feat;
134  }
135 
140  virtual CDotFeatures* get_features() { SG_REF(m_features); return m_features; }
141 
146  virtual const char* get_name() const { return "QDA"; }
147 
154  inline SGVector< float64_t > get_mean(int32_t c) const
155  {
156  return SGVector< float64_t >(m_means.get_column_vector(c), m_dim, false);
157  }
158 
165  inline SGMatrix< float64_t > get_cov(int32_t c) const
166  {
167  REQUIRE(m_store_covs, "Covariance matrices were not stored. "
168  "Please activate to access them subsequently.\n");
169  return SGMatrix< float64_t >(m_covs.get_matrix(c), m_dim, m_dim, false);
170  }
171 
172  protected:
179  virtual bool train_machine(CFeatures* data = NULL);
180 
181  private:
182  void init();
183 
184  void cleanup();
185 
186  private:
188  CDotFeatures* m_features;
189 
191  float64_t m_tolerance;
192 
194  bool m_store_covs;
195 
197  int32_t m_num_classes;
198 
200  int32_t m_dim;
201 
205  SGNDArray< float64_t > m_covs;
206 
208  SGMatrix< float64_t > m_means;
209 
212 
214  SGVector< float32_t > m_slog;
215 
216 }; /* class QDA */
217 } /* namespace shogun */
218 
219 #endif /* _QDA_H__ */
EMachineType
Definition: Machine.h:33
virtual EMachineType get_classifier_type()
Definition: QDA.h:119
Class QDA implements Quadratic Discriminant Analysis.
Definition: QDA.h:35
void set_tolerance(float64_t tolerance)
Definition: QDA.h:107
experimental abstract native multiclass machine class
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual const char * get_name() const
Definition: QDA.h:146
virtual CDotFeatures * get_features()
Definition: QDA.h:140
#define SG_ERROR(...)
Definition: SGIO.h:129
#define REQUIRE(x,...)
Definition: SGIO.h:206
Features that support dot products among other operations.
Definition: DotFeatures.h:44
#define SG_REF(x)
Definition: SGObject.h:54
T * get_matrix(index_t matIdx) const
Definition: SGNDArray.h:72
SGMatrix< float64_t > get_cov(int32_t c) const
Definition: QDA.h:165
Multiclass Labels for multi-class classification.
SGVector< float64_t > get_mean(int32_t c) const
Definition: QDA.h:154
bool get_tolerance()
Definition: QDA.h:113
bool get_store_covs()
Definition: QDA.h:101
#define MACHINE_PROBLEM_TYPE(PT)
Definition: Machine.h:120
virtual CMulticlassLabels * apply_multiclass(CFeatures *data=NULL)
Definition: QDA.cpp:106
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
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
void set_store_covs(bool store_covs)
Definition: QDA.h:95
virtual void set_features(CDotFeatures *feat)
Definition: QDA.h:125
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual ~CQDA()
Definition: QDA.cpp:77
virtual bool train_machine(CFeatures *data=NULL)
Definition: QDA.cpp:173
virtual EFeatureType get_feature_type() const =0

SHOGUN Machine Learning Toolbox - Documentation