Machine Learning Library
CMetric.h
Go to the documentation of this file.
1 /*
2  COPYRIGHT (C) 2003 APPLIED NEUROINFORMATIC GROUP - UNIVERSITY OF BIELEFELD.
3 
4  ALL RIGHTS RESERVED.
5 
6  REDISTRIBUTION AND USE IN SOURCE AND BINARY FORM, WITH OR WITHOUT
7  MODIFICATION, REQUIRE THE PERMISSION OF THE COPYRIGHT HOLDERS.
8 
9  COMMERCIAL USE WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT HOLDERS
10  IS FORBIDDEN
11 
12  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
13  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 
25 
26 #ifndef CMETRIC_H
27 #define CMETRIC_H
28 
29 #include <cmath>
30 #include <cstdio>
31 #include <cassert>
32 #include "CObject.h"
33 #include "CVector.h"
34 
35 
36 template<class Type> class CMetric;
37 template<class Type> class CVector;
38 
39 /******************************************************************************/
47 template<class Type>
48 class CMetric : public CObject<Type> {
49 public:
53  virtual Type distance(const CVector<Type>& rtVec1, const CVector<Type>& rtVec2) const { return 0; }
54  virtual string className() const { return "CMetric";};
55  virtual bool isA(const char* acClass) const { if(string(acClass) == this->className()) return true; else return CObject<Type>::isA(acClass);};
56  virtual void adaptVec(CVector<Type>& rtVec1, const CVector<Type>& rtVec2, float fEps) { };
57 };
58 
59 /******************************************************************************/
65 template<class Type>
66 class CEuclideanMetric : public CMetric<Type>{
67 public:
68 
76  Type distance(const CVector<Type>& rtVec1,const CVector<Type>& rtVec2) const;
77  virtual string className() const { return string("CEuclideanMetric");};
78  virtual bool isA(const char* acClass) const { if(string(acClass) == this->className()) return true; else return CMetric<Type>::isA(acClass);};
79  void adaptVec(CVector<Type>& rtVec1, const CVector<Type>& rtVec2, float fEps);
80 };
81 
82 /******************************************************************************/
88 template<class Type>
89 class CEuclideanMetric2 : public CMetric<Type>{
90 public:
91 
99  Type distance(const CVector<Type>& rtVec1, const CVector<Type>& rtVec2) const;
100  virtual string className() const { return string("CEuclideanMetric2");};
101  virtual bool isA(const char* acClass) const { if(string(acClass) == this->className()) return true; else return CMetric<Type>::isA(acClass);};
102  void adaptVec(CVector<Type>& rtVec1, const CVector<Type>& rtVec2, float fEps);
103 };
104 
105 /******************************************************************************/
111 template<class Type>
112 class CManhattenMetric : public CMetric<Type>{
113 public:
114 
122  Type distance(const CVector<Type>& rtVec1, const CVector<Type>& rtVec2) const;
123  virtual string className() const { return string("CManhattenMetric");};
124  virtual bool isA(const char* acClass) const { if(string(acClass) == this->className()) return true; else return CMetric<Type>::isA(acClass);};
125  void adaptVec(CVector<Type>& rtVec1, const CVector<Type>& rtVec2, float fEps);
126 };
127 
128 /******************************************************************************/
134 template<class Type>
135 class CMaximumMetric : public CMetric<Type>{
136 public:
137 
145  Type distance(const CVector<Type>& rtVec1, const CVector<Type>& rtVec2) const;
146  virtual string className() const { return string("CMaximumMetric");};
147  virtual bool isA(const char* acClass) const { if(string(acClass) == this->className()) return true; else return CMetric<Type>::isA(acClass);};
148  void adaptVec(CVector<Type>& rtVec1, const CVector<Type>& rtVec2, float fEps);
149 };
150 
151 /******************************************************************************/
156 template<class Type>
157 class CScalarMetric : public CMetric<Type>{
158 public:
159 
168  Type distance(const CVector<Type>& rtVec1, const CVector<Type>& rtVec2) const;
169  virtual string className() const { return string("CScalarMetric");};
170  virtual bool isA(const char* acClass) const { if(string(acClass) == this->className()) return true; else return CMetric<Type>::isA(acClass);};
171  void adaptVec(CVector<Type>& rtVec1, const CVector<Type>& rtVec2, float fEps);
172 };
173 
174 
175 /******************************************************************************/
180 template<class Type>
181 class CCoCosineMetric : public CMetric<Type>{
182 public:
183 
192  Type distance(const CVector<Type>& rtVec1, const CVector<Type>& rtVec2) const;
193  virtual string className() const { return string("CCoCosineMetric");};
194  virtual bool isA(const char* acClass) const { if(string(acClass) == this->className()) return true; else return CMetric<Type>::isA(acClass);};
195  void adaptVec(CVector<Type>& rtVec1, const CVector<Type>& rtVec2, float fEps);
196 };
197 
198 /******************************************************************************/
204 template<class Type>
205 class CAngleMetric : public CMetric<Type>{
206 public:
207 
215  Type distance(const CVector<Type>& rtVec1, const CVector<Type>& rtVec2) const;
216  virtual string className() const { return string("CAngleMetric");};
217  virtual bool isA(const char* acClass) const { if(string(acClass) == this->className()) return true; else return CMetric<Type>::isA(acClass);};
218  void adaptVec(CVector<Type>& rtVec1, const CVector<Type>& rtVec2, float fEps);
219 };
220 
221 /******************************************************************************/
227 template<class Type>
228 class CHyperbolicMetric : public CMetric<Type>{
229 public:
230 
238  Type distance(const CVector<Type>& rtVec1, const CVector<Type>& rtVec2) const;
239  virtual string className() const { return string("CHyperbolicMetric");};
240  virtual bool isA(const char* acClass) const {
241  if(string(acClass) == this->className())
242  return true;
243  else
244  return CMetric<Type>::isA(acClass);
245  };
246  void adaptVec(CVector<Type>& rtVec1, const CVector<Type>& rtVec2, float fEps);
247 };
248 
249 #endif
void adaptVec(CVector< Type > &rtVec1, const CVector< Type > &rtVec2, float fEps)
Manhatten metric object.
Definition: CMetric.h:112
virtual void adaptVec(CVector< Type > &rtVec1, const CVector< Type > &rtVec2, float fEps)
Definition: CMetric.h:56
void adaptVec(CVector< Type > &rtVec1, const CVector< Type > &rtVec2, float fEps)
Hyperbolic metric object.
Definition: CMetric.h:228
Euclidean2 metric object.
Definition: CMetric.h:89
Maximum metric object.
Definition: CMetric.h:135
virtual string className() const
Returns the class name.
Definition: CMetric.h:100
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CMetric.h:194
Type distance(const CVector< Type > &rtVec1, const CVector< Type > &rtVec2) const
Base class for metrix objects.
Definition: CMetric.h:36
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CMetric.h:240
Type distance(const CVector< Type > &rtVec1, const CVector< Type > &rtVec2) const
Euclidean metric object.
Definition: CMetric.h:66
void adaptVec(CVector< Type > &rtVec1, const CVector< Type > &rtVec2, float fEps)
Type distance(const CVector< Type > &rtVec1, const CVector< Type > &rtVec2) const
virtual string className() const
Returns the class name.
Definition: CMetric.h:77
Type distance(const CVector< Type > &rtVec1, const CVector< Type > &rtVec2) const
virtual string className() const
Returns the class name.
Definition: CMetric.h:216
Angle based metric object.
Definition: CMetric.h:205
Scalar metric object Template class for metric based on scalar product.
Definition: CMetric.h:157
virtual string className() const
Returns the class name.
Definition: CMetric.h:239
virtual string className() const
Returns the class name.
Definition: CMetric.h:193
virtual string className() const
Returns the class name.
Definition: CMetric.h:146
CoCosine metric object Template class for metric based on scalar product.
Definition: CMetric.h:181
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CMetric.h:78
void adaptVec(CVector< Type > &rtVec1, const CVector< Type > &rtVec2, float fEps)
virtual Type distance(const CVector< Type > &rtVec1, const CVector< Type > &rtVec2) const
Definition: CMetric.h:53
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CMetric.h:170
Type distance(const CVector< Type > &rtVec1, const CVector< Type > &rtVec2) const
virtual string className() const
Returns the class name.
Definition: CMetric.h:169
void adaptVec(CVector< Type > &rtVec1, const CVector< Type > &rtVec2, float fEps)
Type distance(const CVector< Type > &rtVec1, const CVector< Type > &rtVec2) const
Type distance(const CVector< Type > &rtVec1, const CVector< Type > &rtVec2) const
templatized vector for numerical applications
Definition: CMatrix.h:39
void adaptVec(CVector< Type > &rtVec1, const CVector< Type > &rtVec2, float fEps)
Base class for all object.
Definition: CObject.h:51
void adaptVec(CVector< Type > &rtVec1, const CVector< Type > &rtVec2, float fEps)
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CMetric.h:217
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CMetric.h:101
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CObject.h:93
void adaptVec(CVector< Type > &rtVec1, const CVector< Type > &rtVec2, float fEps)
Type distance(const CVector< Type > &rtVec1, const CVector< Type > &rtVec2) const
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CMetric.h:147
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CMetric.h:124
virtual string className() const
Returns the class name.
Definition: CMetric.h:54
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CMetric.h:55
virtual string className() const
Returns the class name.
Definition: CMetric.h:123