SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
87  virtual float64_t* get_distance_matrix_real(int32_t &m, int32_t &n, float64_t* target)
88  {
89  return CDistance::get_distance_matrix_real(m, n, target);
90  }
91 
99  virtual float32_t* get_distance_matrix_shortreal(int32_t &m, int32_t &n, float32_t* target)
100  {
101  return CDistance::get_distance_matrix_shortreal(m, n, target);
102  }
103 
113  virtual bool init(CFeatures* lhs, CFeatures* rhs)
114  {
115  if (this->parallel->get_num_threads()!=1)
116  {
117  SG_WARNING("Enforcing to use only one thread due to restrictions of directors\n")
118  this->parallel->set_num_threads(1);
119  }
120  return CDistance::init(lhs, rhs);
121  }
122 
124  virtual void cleanup()
125  {
126 
127  }
128 
133  virtual int32_t get_num_vec_lhs()
134  {
136  }
137 
142  virtual int32_t get_num_vec_rhs()
143  {
145  }
146 
151  virtual void set_num_vec_lhs(int32_t num)
152  {
153  num_lhs=num;
154  }
155 
160  virtual void set_num_vec_rhs(int32_t num)
161  {
162  num_rhs=num;
163  }
164 
169  virtual bool has_features()
170  {
171  if (!external_features)
172  return CDistance::has_features();
173  else
174  return true;
175  }
176 
178  virtual void remove_lhs_and_rhs()
179  {
181  }
182 
184  virtual void remove_lhs()
185  {
187  }
188 
190  virtual void remove_rhs()
191  {
193  }
194 
199  virtual EDistanceType get_distance_type() { return D_DIRECTOR; }
200 
205  virtual EFeatureType get_feature_type() { return F_ANY; }
206 
211  virtual EFeatureClass get_feature_class() { return C_ANY; }
212 
217  virtual const char* get_name() const { return "DirectorDistance"; }
218 
224  virtual void set_precompute_matrix(bool flag)
225  {
227  }
228 
229  protected:
233  virtual float64_t compute(int32_t x, int32_t y)
234  {
235  return distance_function(x, y);
236  }
237 
238  protected:
239  /* */
240  bool external_features;
241 };
242 
243 }
244 
245 #endif /* USE_SWIG_DIRECTORS */
246 #endif /* _DIRECTORDISTANCE_H___ */

SHOGUN Machine Learning Toolbox - Documentation