SHOGUN  v3.2.0
DirectorDistance.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  * Copyright (C) 2012 Evgeniy Andreev (gsomix)
8  */
9 
10 #ifndef _DIRECTORDISTANCE_H___
11 #define _DIRECTORDISTANCE_H___
12 
13 #ifdef USE_SWIG_DIRECTORS
14 #include <shogun/lib/common.h>
15 #include <shogun/lib/DataType.h>
17 
18 namespace shogun
19 {
20 
21 #define IGNORE_IN_CLASSLIST
22 IGNORE_IN_CLASSLIST class CDirectorDistance : public CDistance
23 {
24  public:
25  /* default constructor */
26  CDirectorDistance(bool is_external_features)
27  : CDistance(), external_features(is_external_features)
28  {
29 
30  }
31 
33  virtual ~CDirectorDistance()
34  {
35  cleanup();
36  }
37 
38  virtual float64_t distance_function(int32_t x, int32_t y)
39  {
40  SG_ERROR("Distance function of Director Distance needs to be overridden.\n")
41  return 0;
42  }
43 
51  virtual float64_t distance(int32_t idx_a, int32_t idx_b)
52  {
53  if (idx_a < 0 || idx_b <0)
54  return 0;
55 
56  if (!external_features)
57  CDistance::distance(idx_a, idx_b);
58  else
59  return compute(idx_a, idx_b);
60  }
61 
75  virtual float64_t distance_upper_bounded(int32_t idx_a, int32_t idx_b, float64_t upper_bound)
76  {
77  return CDistance::distance(idx_a, idx_b);
78  }
79 
89  virtual bool init(CFeatures* lhs, CFeatures* rhs)
90  {
91  if (this->parallel->get_num_threads()!=1)
92  {
93  SG_WARNING("Enforcing to use only one thread due to restrictions of directors\n")
94  this->parallel->set_num_threads(1);
95  }
96  return CDistance::init(lhs, rhs);
97  }
98 
100  virtual void cleanup()
101  {
102 
103  }
104 
109  virtual int32_t get_num_vec_lhs()
110  {
112  }
113 
118  virtual int32_t get_num_vec_rhs()
119  {
121  }
122 
127  virtual void set_num_vec_lhs(int32_t num)
128  {
129  num_lhs=num;
130  }
131 
136  virtual void set_num_vec_rhs(int32_t num)
137  {
138  num_rhs=num;
139  }
140 
145  virtual bool has_features()
146  {
147  if (!external_features)
148  return CDistance::has_features();
149  else
150  return true;
151  }
152 
154  virtual void remove_lhs_and_rhs()
155  {
157  }
158 
160  virtual void remove_lhs()
161  {
163  }
164 
166  virtual void remove_rhs()
167  {
169  }
170 
175  virtual EDistanceType get_distance_type() { return D_DIRECTOR; }
176 
181  virtual EFeatureType get_feature_type() { return F_ANY; }
182 
187  virtual EFeatureClass get_feature_class() { return C_ANY; }
188 
193  virtual const char* get_name() const { return "DirectorDistance"; }
194 
200  virtual void set_precompute_matrix(bool flag)
201  {
203  }
204 
205  protected:
209  virtual float64_t compute(int32_t x, int32_t y)
210  {
211  return distance_function(x, y);
212  }
213 
214  protected:
215  /* */
216  bool external_features;
217 };
218 
219 }
220 
221 #endif /* USE_SWIG_DIRECTORS */
222 #endif /* _DIRECTORDISTANCE_H___ */
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
virtual bool has_features()
Definition: Distance.h:300
virtual int32_t get_num_vec_lhs()
Definition: Distance.h:282
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:131
EFeatureClass
shogun feature class
Definition: FeatureTypes.h:35
virtual void set_precompute_matrix(bool flag)
Definition: Distance.h:267
EDistanceType
Definition: Distance.h:31
virtual void remove_lhs_and_rhs()
Definition: Distance.cpp:119
double float64_t
Definition: common.h:48
virtual int32_t get_num_vec_rhs()
Definition: Distance.h:291
EFeatureType
shogun feature type
Definition: FeatureTypes.h:16
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:16
#define IGNORE_IN_CLASSLIST
Definition: CPLEXSVM.h:21
#define SG_WARNING(...)
Definition: SGIO.h:130
virtual void remove_rhs()
takes all necessary steps if the rhs is removed from distance matrix
Definition: Distance.cpp:138

SHOGUN Machine Learning Toolbox - Documentation