SimpleDistance.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2006-2009 Christian Gehl
00008  * Copyright (C) 2006-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _SIMPLEDISTANCE_H___
00012 #define _SIMPLEDISTANCE_H___
00013 
00014 #include <shogun/distance/Distance.h>
00015 #include <shogun/features/SimpleFeatures.h>
00016 #include <shogun/io/SGIO.h>
00017 
00018 namespace shogun
00019 {
00021 template <class ST> class CSimpleDistance : public CDistance
00022 {
00023     public:
00025         CSimpleDistance() : CDistance() {}
00026 
00033         virtual bool init(CFeatures* l, CFeatures* r)
00034         {
00035             CDistance::init(l,r);
00036 
00037             ASSERT(l->get_feature_class()==C_SIMPLE);
00038             ASSERT(r->get_feature_class()==C_SIMPLE);
00039             ASSERT(l->get_feature_type()==this->get_feature_type());
00040             ASSERT(r->get_feature_type()==this->get_feature_type());
00041             
00042             
00043             if ( ((CSimpleFeatures<ST>*) l)->get_num_features() != ((CSimpleFeatures<ST>*) r)->get_num_features() )
00044             {  
00045                 SG_ERROR( "train or test features #dimension mismatch (l:%d vs. r:%d)\n",
00046                         ((CSimpleFeatures<ST>*) l)->get_num_features(),((CSimpleFeatures<ST>*) r)->get_num_features());
00047             }
00048         
00049             return true;
00050         }
00051 
00056         inline virtual EFeatureClass get_feature_class() { return C_SIMPLE; }
00057 
00062         inline virtual EFeatureType get_feature_type();
00063 
00069         virtual const char* get_name(void) const {
00070             return "SimpleDistance"; }
00071 
00076         virtual void cleanup()=0;
00077 
00084         virtual EDistanceType get_distance_type()=0;
00085 };
00086 
00091 template<> inline EFeatureType CSimpleDistance<float64_t>::get_feature_type() { return F_DREAL; }
00092 
00097 template<> inline EFeatureType CSimpleDistance<uint64_t>::get_feature_type() { return F_ULONG; }
00098 
00103 template<> inline EFeatureType CSimpleDistance<int32_t>::get_feature_type() { return F_INT; }
00104 
00109 template<> inline EFeatureType CSimpleDistance<uint16_t>::get_feature_type() { return F_WORD; }
00110 
00115 template<> inline EFeatureType CSimpleDistance<int16_t>::get_feature_type() { return F_SHORT; }
00116 
00121 template<> inline EFeatureType CSimpleDistance<uint8_t>::get_feature_type() { return F_BYTE; }
00122 
00127 template<> inline EFeatureType CSimpleDistance<char>::get_feature_type() { return F_CHAR; }
00128 
00129 } // namespace shogun
00130 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation