SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
QDA.h
浏览该文件的文档.
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 #ifdef HAVE_EIGEN3
17 
21 #include <shogun/lib/SGNDArray.h>
22 
23 namespace shogun
24 {
25 
26 //#define DEBUG_QDA
27 
37 {
38  public:
40 
41 
46  CQDA(float64_t tolerance = 1e-4, bool store_covs = false);
47 
55  CQDA(CDenseFeatures<float64_t>* traindat, CLabels* trainlab, float64_t tolerance = 1e-4, bool store_covs = false);
56 
57  virtual ~CQDA();
58 
64  virtual CMulticlassLabels* apply_multiclass(CFeatures* data=NULL);
65 
70  inline void set_store_covs(bool store_covs) { m_store_covs = store_covs; }
71 
76  inline bool get_store_covs() { return m_store_covs; }
77 
82  inline void set_tolerance(float64_t tolerance) { m_tolerance = tolerance; }
83 
88  inline bool get_tolerance() { return m_tolerance; }
89 
94  virtual EMachineType get_classifier_type() { return CT_QDA; }
95 
100  virtual void set_features(CDotFeatures* feat)
101  {
102  if (feat->get_feature_class() != C_DENSE ||
103  feat->get_feature_type() != F_DREAL)
104  SG_ERROR("QDA requires SIMPLE REAL valued features\n")
105 
106  SG_REF(feat);
107  SG_UNREF(m_features);
108  m_features = feat;
109  }
110 
115  virtual CDotFeatures* get_features() { SG_REF(m_features); return m_features; }
116 
121  virtual const char* get_name() const { return "QDA"; }
122 
129  inline SGVector< float64_t > get_mean(int32_t c) const
130  {
131  return SGVector< float64_t >(m_means.get_column_vector(c), m_dim, false);
132  }
133 
140  inline SGMatrix< float64_t > get_cov(int32_t c) const
141  {
142  return SGMatrix< float64_t >(m_covs.get_matrix(c), m_dim, m_dim, false);
143  }
144 
145  protected:
152  virtual bool train_machine(CFeatures* data = NULL);
153 
154  private:
155  void init();
156 
157  void cleanup();
158 
159  private:
161  CDotFeatures* m_features;
162 
164  float64_t m_tolerance;
165 
167  bool m_store_covs;
168 
170  int32_t m_num_classes;
171 
173  int32_t m_dim;
174 
178  SGNDArray< float64_t > m_covs;
179 
181  SGMatrix< float64_t > m_means;
182 
185 
187  SGVector< float32_t > m_slog;
188 
189 }; /* class QDA */
190 } /* namespace shogun */
191 
192 #endif /* HAVE_EIGEN3 */
193 #endif /* _QDA_H__ */
EMachineType
Definition: Machine.h:33
virtual EMachineType get_classifier_type()
Definition: QDA.h:94
Class QDA implements Quadratic Discriminant Analysis.
Definition: QDA.h:36
void set_tolerance(float64_t tolerance)
Definition: QDA.h:82
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:121
virtual CDotFeatures * get_features()
Definition: QDA.h:115
#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:140
Multiclass Labels for multi-class classification.
SGVector< float64_t > get_mean(int32_t c) const
Definition: QDA.h:129
bool get_tolerance()
Definition: QDA.h:88
bool get_store_covs()
Definition: QDA.h:76
#define MACHINE_PROBLEM_TYPE(PT)
Definition: Machine.h:120
virtual CMulticlassLabels * apply_multiclass(CFeatures *data=NULL)
Definition: QDA.cpp:69
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:115
#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:70
virtual void set_features(CDotFeatures *feat)
Definition: QDA.h:100
The class Features is the base class of all feature objects.
Definition: Features.h:68
virtual ~CQDA()
Definition: QDA.cpp:42
virtual bool train_machine(CFeatures *data=NULL)
Definition: QDA.cpp:144
CQDA(float64_t tolerance=1e-4, bool store_covs=false)
Definition: QDA.cpp:27
virtual EFeatureType get_feature_type() const =0

SHOGUN 机器学习工具包 - 项目文档