SHOGUN  3.2.1
 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 
15 #include <shogun/lib/config.h>
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___ */

SHOGUN Machine Learning Toolbox - Documentation