DirectorDistance.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  * Copyright (C) 2012 Evgeniy Andreev (gsomix)
00008  */
00009 
00010 #ifndef _DIRECTORDISTANCE_H___
00011 #define _DIRECTORDISTANCE_H___
00012 
00013 #ifdef USE_SWIG_DIRECTORS
00014 #include <shogun/lib/common.h>
00015 #include <shogun/lib/DataType.h>
00016 #include <shogun/distance/Distance.h>
00017 
00018 namespace shogun
00019 {
00020 
00021 #define IGNORE_IN_CLASSLIST
00022 IGNORE_IN_CLASSLIST class CDirectorDistance : public CDistance
00023 {
00024     public:
00025         /* default constructor */
00026         CDirectorDistance(bool is_external_features) 
00027         : CDistance(), external_features(is_external_features)
00028         {
00029 
00030         }   
00031 
00033         virtual ~CDirectorDistance()
00034         {
00035             cleanup();
00036         }
00037 
00038         virtual float64_t distance_function(int32_t x, int32_t y)
00039         {
00040             SG_ERROR("Distance function of Director Distance needs to be overridden.\n");
00041             return 0;
00042         }
00043 
00051         virtual float64_t distance(int32_t idx_a, int32_t idx_b)
00052         {
00053             if (idx_a < 0 || idx_b <0)
00054                 return 0;
00055 
00056             if (!external_features)
00057                 CDistance::distance(idx_a, idx_b);
00058             else
00059                 return compute(idx_a, idx_b);
00060         }
00061 
00075         virtual float64_t distance_upper_bounded(int32_t idx_a, int32_t idx_b, float64_t upper_bound)
00076         {
00077             return CDistance::distance(idx_a, idx_b);
00078         }
00079 
00087         virtual float64_t* get_distance_matrix_real(int32_t &m, int32_t &n, float64_t* target)
00088         {
00089             return CDistance::get_distance_matrix_real(m, n, target);
00090         }
00091 
00099         virtual float32_t* get_distance_matrix_shortreal(int32_t &m, int32_t &n, float32_t* target)
00100         {
00101             return CDistance::get_distance_matrix_shortreal(m, n, target);
00102         }
00103 
00113         virtual bool init(CFeatures* lhs, CFeatures* rhs)
00114         {
00115             if (this->parallel->get_num_threads()!=1)
00116             {
00117                 SG_WARNING("Enforcing to use only one thread due to restrictions of directors\n");
00118                 this->parallel->set_num_threads(1);
00119             }
00120             return CDistance::init(lhs, rhs);
00121         }
00122 
00124         virtual void cleanup()
00125         {
00126             
00127         }
00128 
00133         virtual int32_t get_num_vec_lhs()
00134         {
00135             return CDistance::get_num_vec_lhs();
00136         }
00137 
00142         virtual int32_t get_num_vec_rhs()
00143         {
00144             return CDistance::get_num_vec_rhs();
00145         }
00146 
00151         virtual void set_num_vec_lhs(int32_t num)
00152         {
00153             num_lhs=num;
00154         }
00155 
00160         virtual void set_num_vec_rhs(int32_t num)
00161         {
00162             num_rhs=num;
00163         }
00164 
00169         virtual bool has_features()
00170         {
00171             if (!external_features)
00172                 return CDistance::has_features();
00173             else
00174                 return true;
00175         }
00176 
00178         virtual void remove_lhs_and_rhs()
00179         {
00180             CDistance::remove_lhs_and_rhs();
00181         }
00182 
00184         virtual void remove_lhs()
00185         {
00186             CDistance::remove_lhs();
00187         }
00188 
00190         virtual void remove_rhs()
00191         {
00192             CDistance::remove_rhs();
00193         }
00194 
00199         virtual EDistanceType get_distance_type() { return D_DIRECTOR; }
00200 
00205         virtual EFeatureType get_feature_type() { return F_ANY; }
00206 
00211         virtual EFeatureClass get_feature_class() { return C_ANY; }
00212 
00217         virtual const char* get_name() const { return "DirectorDistance"; }
00218 
00224         virtual void set_precompute_matrix(bool flag)
00225         {
00226             CDistance::set_precompute_matrix(flag);
00227         }
00228 
00229     protected:
00233         virtual float64_t compute(int32_t x, int32_t y)
00234         {
00235             return distance_function(x, y);
00236         }
00237 
00238     protected:
00239         /* */
00240         bool external_features;
00241 };
00242 
00243 }
00244 
00245 #endif /* USE_SWIG_DIRECTORS */
00246 #endif /* _DIRECTORDISTANCE_H___ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation