SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
DirectorDistance.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  * Copyright (C) 2012 Evgeniy Andreev (gsomix)
8  */
9 
10 #ifndef _DIRECTORDISTANCE_H___
11 #define _DIRECTORDISTANCE_H___
12 
13 #include <shogun/lib/config.h>
14 
15 #ifdef USE_SWIG_DIRECTORS
16 
17 #include <shogun/lib/common.h>
18 #include <shogun/lib/DataType.h>
20 
21 namespace shogun
22 {
23 
24 #define IGNORE_IN_CLASSLIST
25 IGNORE_IN_CLASSLIST class CDirectorDistance : public CDistance
26 {
27  public:
28  /* default constructor */
29  CDirectorDistance(bool is_external_features)
30  : CDistance(), external_features(is_external_features)
31  {
32 
33  }
34 
36  virtual ~CDirectorDistance()
37  {
38  cleanup();
39  }
40 
41  virtual float64_t distance_function(int32_t x, int32_t y)
42  {
43  SG_ERROR("Distance function of Director Distance needs to be overridden.\n")
44  return 0;
45  }
46 
54  virtual float64_t distance(int32_t idx_a, int32_t idx_b)
55  {
56  if (idx_a < 0 || idx_b <0)
57  return 0;
58 
59  if (!external_features)
60  CDistance::distance(idx_a, idx_b);
61  else
62  return compute(idx_a, idx_b);
63  }
64 
78  virtual float64_t distance_upper_bounded(int32_t idx_a, int32_t idx_b, float64_t upper_bound)
79  {
80  return CDistance::distance(idx_a, idx_b);
81  }
82 
92  virtual bool init(CFeatures* lhs, CFeatures* rhs)
93  {
94  if (this->parallel->get_num_threads()!=1)
95  {
96  SG_WARNING("Enforcing to use only one thread due to restrictions of directors\n")
97  this->parallel->set_num_threads(1);
98  }
99  return CDistance::init(lhs, rhs);
100  }
101 
103  virtual void cleanup()
104  {
105 
106  }
107 
112  virtual int32_t get_num_vec_lhs()
113  {
115  }
116 
121  virtual int32_t get_num_vec_rhs()
122  {
124  }
125 
130  virtual void set_num_vec_lhs(int32_t num)
131  {
132  num_lhs=num;
133  }
134 
139  virtual void set_num_vec_rhs(int32_t num)
140  {
141  num_rhs=num;
142  }
143 
148  virtual bool has_features()
149  {
150  if (!external_features)
151  return CDistance::has_features();
152  else
153  return true;
154  }
155 
157  virtual void remove_lhs_and_rhs()
158  {
160  }
161 
163  virtual void remove_lhs()
164  {
166  }
167 
169  virtual void remove_rhs()
170  {
172  }
173 
178  virtual EDistanceType get_distance_type() { return D_DIRECTOR; }
179 
184  virtual EFeatureType get_feature_type() { return F_ANY; }
185 
190  virtual EFeatureClass get_feature_class() { return C_ANY; }
191 
196  virtual const char* get_name() const { return "DirectorDistance"; }
197 
203  virtual void set_precompute_matrix(bool flag)
204  {
206  }
207 
208  protected:
212  virtual float64_t compute(int32_t x, int32_t y)
213  {
214  return distance_function(x, y);
215  }
216 
217  protected:
218  /* */
219  bool external_features;
220 };
221 
222 }
223 
224 #endif /* USE_SWIG_DIRECTORS */
225 #endif /* _DIRECTORDISTANCE_H___ */
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
virtual bool has_features()
Definition: Distance.h:301
virtual int32_t get_num_vec_lhs()
Definition: Distance.h:283
virtual void remove_lhs()
takes all necessary steps if the lhs is removed from distance matrix
Definition: Distance.cpp:130
#define SG_ERROR(...)
Definition: SGIO.h:129
EFeatureClass
shogun feature class
Definition: FeatureTypes.h:38
virtual void set_precompute_matrix(bool flag)
Definition: Distance.h:268
EDistanceType
Definition: Distance.h:32
virtual void remove_lhs_and_rhs()
Definition: Distance.cpp:119
double float64_t
Definition: common.h:50
virtual int32_t get_num_vec_rhs()
Definition: Distance.h:292
EFeatureType
shogun feature type
Definition: FeatureTypes.h:19
virtual float64_t distance(int32_t idx_a, int32_t idx_b)
Definition: Distance.cpp:189
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
#define IGNORE_IN_CLASSLIST
Definition: CPLEXSVM.h:24
#define SG_WARNING(...)
Definition: SGIO.h:128
virtual void remove_rhs()
takes all necessary steps if the rhs is removed from distance matrix
Definition: Distance.cpp:138

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