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) 2007-2009 Soeren Sonnenburg 00008 * Copyright (C) 2007-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef _SPARSEDISTANCE_H___ 00012 #define _SPARSEDISTANCE_H___ 00013 00014 #include <shogun/distance/Distance.h> 00015 #include <shogun/features/SparseFeatures.h> 00016 00017 namespace shogun 00018 { 00020 template <class ST> class CSparseDistance : public CDistance 00021 { 00022 public: 00024 CSparseDistance() : CDistance() {} 00025 00032 virtual bool init(CFeatures* l, CFeatures* r) 00033 { 00034 CDistance::init(l,r); 00035 00036 ASSERT(l->get_feature_class()==C_SPARSE); 00037 ASSERT(r->get_feature_class()==C_SPARSE); 00038 ASSERT(l->get_feature_type()==this->get_feature_type()); 00039 ASSERT(r->get_feature_type()==this->get_feature_type()); 00040 00041 if (((CSparseFeatures<ST>*) lhs)->get_num_features() != ((CSparseFeatures<ST>*) rhs)->get_num_features() ) 00042 { 00043 SG_ERROR( "train or test features #dimension mismatch (l:%d vs. r:%d)\n", 00044 ((CSparseFeatures<ST>*) lhs)->get_num_features(),((CSparseFeatures<ST>*)rhs)->get_num_features()); 00045 } 00046 return true; 00047 } 00048 00053 virtual EFeatureClass get_feature_class() { return C_SPARSE; } 00054 00059 virtual EFeatureType get_feature_type(); 00060 00066 virtual const char* get_name() const { 00067 return "SparseDistance"; } 00068 00073 virtual void cleanup()=0; 00074 00081 virtual EDistanceType get_distance_type()=0; 00082 }; 00083 00088 template<> inline EFeatureType CSparseDistance<float64_t>::get_feature_type() { return F_DREAL; } 00089 00094 template<> inline EFeatureType CSparseDistance<uint64_t>::get_feature_type() { return F_ULONG; } 00095 00100 template<> inline EFeatureType CSparseDistance<int32_t>::get_feature_type() { return F_INT; } 00101 00106 template<> inline EFeatureType CSparseDistance<uint16_t>::get_feature_type() { return F_WORD; } 00107 00112 template<> inline EFeatureType CSparseDistance<int16_t>::get_feature_type() { return F_SHORT; } 00113 00118 template<> inline EFeatureType CSparseDistance<uint8_t>::get_feature_type() { return F_BYTE; } 00119 00124 template<> inline EFeatureType CSparseDistance<char>::get_feature_type() { return F_CHAR; } 00125 } // namespace shogun 00126 #endif