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 
45  CQDA(float64_t tolerance = 1e-4, bool store_covs = false);
46 
54  CQDA(CDenseFeatures<float64_t>* traindat, CLabels* trainlab, float64_t tolerance = 1e-4, bool store_covs = false);
55 
56  virtual ~CQDA();
57 
63  virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL);
64 
69  inline void set_store_covs(bool store_covs) { m_store_covs = store_covs; }
70 
75  inline bool get_store_covs() { return m_store_covs; }
76 
81  inline void set_tolerance(float64_t tolerance) { m_tolerance = tolerance; }
82 
87  inline bool get_tolerance() { return m_tolerance; }
88 
93  virtual EMachineType get_classifier_type() { return CT_QDA; }
94 
99  virtual void set_features(CDotFeatures* feat)
100  {
101  if (feat->get_feature_class() != C_DENSE ||
102  feat->get_feature_type() != F_DREAL)
103  SG_ERROR("QDA requires SIMPLE REAL valued features\n")
104 
105  SG_REF(feat);
106  SG_UNREF(m_features);
107  m_features = feat;
108  }
109 
114  virtual CDotFeatures* get_features() { SG_REF(m_features); return m_features; }
115 
120  virtual const char* get_name() const { return "QDA"; }
121 
128  inline SGVector< float64_t > get_mean(int32_t c) const
129  {
130  return SGVector< float64_t >(m_means.get_column_vector(c), m_dim, false);
131  }
132 
139  inline SGMatrix< float64_t > get_cov(int32_t c) const
140  {
141  return SGMatrix< float64_t >(m_covs.get_matrix(c), m_dim, m_dim, false);
142  }
143 
144  protected:
151  virtual bool train_machine(CFeatures* data = NULL);
152 
153  private:
154  void init();
155 
156  void cleanup();
157 
158  private:
160  CDotFeatures* m_features;
161 
163  float64_t m_tolerance;
164 
166  bool m_store_covs;
167 
169  int32_t m_num_classes;
170 
172  int32_t m_dim;
173 
177  SGNDArray< float64_t > m_covs;
178 
180  SGMatrix< float64_t > m_means;
181 
184 
186  SGVector< float32_t > m_slog;
187 
188 }; /* class QDA */
189 } /* namespace shogun */
190 
191 #endif /* _QDA_H__ */
EMachineType
Definition: Machine.h:33
virtual EMachineType get_classifier_type()
Definition: QDA.h:93
Class QDA implements Quadratic Discriminant Analysis.
Definition: QDA.h:35
void set_tolerance(float64_t tolerance)
Definition: QDA.h:81
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:120
virtual CDotFeatures * get_features()
Definition: QDA.h:114
#define SG_ERROR(...)
Definition: SGIO.h:129
Features that support dot products among other operations.
Definition: DotFeatures.h:44
#define SG_REF(x)
Definition: SGObject.h:51
T * get_matrix(index_t matIdx) const
Definition: SGNDArray.h:72
SGMatrix< float64_t > get_cov(int32_t c) const
Definition: QDA.h:139
Multiclass Labels for multi-class classification.
SGVector< float64_t > get_mean(int32_t c) const
Definition: QDA.h:128
bool get_tolerance()
Definition: QDA.h:87
bool get_store_covs()
Definition: QDA.h:75
#define MACHINE_PROBLEM_TYPE(PT)
Definition: Machine.h:120
virtual CMulticlassLabels * apply_multiclass(CFeatures *data=NULL)
Definition: QDA.cpp:68
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:52
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:69
virtual void set_features(CDotFeatures *feat)
Definition: QDA.h:99
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual ~CQDA()
Definition: QDA.cpp:41
virtual bool train_machine(CFeatures *data=NULL)
Definition: QDA.cpp:143
CQDA(float64_t tolerance=1e-4, bool store_covs=false)
Definition: QDA.cpp:26
virtual EFeatureType get_feature_type() const =0

SHOGUN Machine Learning Toolbox - Documentation