SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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 
00089         virtual bool init(CFeatures* lhs, CFeatures* rhs)
00090         {
00091             if (this->parallel->get_num_threads()!=1)
00092             {
00093                 SG_WARNING("Enforcing to use only one thread due to restrictions of directors\n")
00094                 this->parallel->set_num_threads(1);
00095             }
00096             return CDistance::init(lhs, rhs);
00097         }
00098 
00100         virtual void cleanup()
00101         {
00102 
00103         }
00104 
00109         virtual int32_t get_num_vec_lhs()
00110         {
00111             return CDistance::get_num_vec_lhs();
00112         }
00113 
00118         virtual int32_t get_num_vec_rhs()
00119         {
00120             return CDistance::get_num_vec_rhs();
00121         }
00122 
00127         virtual void set_num_vec_lhs(int32_t num)
00128         {
00129             num_lhs=num;
00130         }
00131 
00136         virtual void set_num_vec_rhs(int32_t num)
00137         {
00138             num_rhs=num;
00139         }
00140 
00145         virtual bool has_features()
00146         {
00147             if (!external_features)
00148                 return CDistance::has_features();
00149             else
00150                 return true;
00151         }
00152 
00154         virtual void remove_lhs_and_rhs()
00155         {
00156             CDistance::remove_lhs_and_rhs();
00157         }
00158 
00160         virtual void remove_lhs()
00161         {
00162             CDistance::remove_lhs();
00163         }
00164 
00166         virtual void remove_rhs()
00167         {
00168             CDistance::remove_rhs();
00169         }
00170 
00175         virtual EDistanceType get_distance_type() { return D_DIRECTOR; }
00176 
00181         virtual EFeatureType get_feature_type() { return F_ANY; }
00182 
00187         virtual EFeatureClass get_feature_class() { return C_ANY; }
00188 
00193         virtual const char* get_name() const { return "DirectorDistance"; }
00194 
00200         virtual void set_precompute_matrix(bool flag)
00201         {
00202             CDistance::set_precompute_matrix(flag);
00203         }
00204 
00205     protected:
00209         virtual float64_t compute(int32_t x, int32_t y)
00210         {
00211             return distance_function(x, y);
00212         }
00213 
00214     protected:
00215         /* */
00216         bool external_features;
00217 };
00218 
00219 }
00220 
00221 #endif /* USE_SWIG_DIRECTORS */
00222 #endif /* _DIRECTORDISTANCE_H___ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation