CombinedDotFeatures.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) 2009 Soeren Sonnenburg
00008  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _COMBINEDDOTFEATURES_H___
00012 #define _COMBINEDDOTFEATURES_H___
00013 
00014 #include "lib/common.h"
00015 #include "lib/List.h"
00016 #include "features/DotFeatures.h"
00017 #include "features/Features.h"
00018 
00019 namespace shogun
00020 {
00021 class CFeatures;
00022 template <class T> class CList;
00023 template <class T> class CListElement;
00043 class CCombinedDotFeatures : public CDotFeatures
00044 {
00045     public:
00047         CCombinedDotFeatures();
00048 
00050         CCombinedDotFeatures(const CCombinedDotFeatures & orig);
00051 
00053         virtual ~CCombinedDotFeatures();
00054 
00055         inline virtual int32_t get_num_vectors()
00056         {
00057             return num_vectors;
00058         }
00059 
00064         inline virtual int32_t get_dim_feature_space()
00065         {
00066             return  num_dimensions;
00067         }
00068 
00075         virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2);
00076 
00083         virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00084 
00093         virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00094 
00100         virtual int32_t get_nnz_features_for_vector(int32_t num);
00101 
00106         inline virtual EFeatureType get_feature_type()
00107         {
00108             return F_DREAL;
00109         }
00110 
00115         inline virtual EFeatureClass get_feature_class()
00116         {
00117             return C_COMBINED_DOT;
00118         }
00119 
00120         inline virtual int32_t get_size()
00121         {
00122             return sizeof(float64_t);
00123         }
00124 
00129         virtual CFeatures* duplicate() const;
00130 
00132         void list_feature_objs();
00133 
00138         inline CDotFeatures* get_first_feature_obj()
00139         {
00140             CDotFeatures* f=feature_list->get_first_element();
00141             SG_REF(f);
00142             return f;
00143         }
00144 
00150         inline CDotFeatures* get_first_feature_obj(CListElement<CDotFeatures*>*&current)
00151         {
00152             CDotFeatures* f=feature_list->get_first_element(current);
00153             SG_REF(f);
00154             return f;
00155         }
00156 
00161         inline CDotFeatures* get_next_feature_obj()
00162         {
00163             CDotFeatures* f=feature_list->get_next_element();
00164             SG_REF(f);
00165             return f;
00166         }
00167 
00173         inline CDotFeatures* get_next_feature_obj(CListElement<CDotFeatures*>*&current)
00174         {
00175             CDotFeatures* f=feature_list->get_next_element(current);
00176             SG_REF(f);
00177             return f;
00178         }
00179 
00184         inline CDotFeatures* get_last_feature_obj()
00185         {
00186             CDotFeatures* f=feature_list->get_last_element();
00187             SG_REF(f);
00188             return f;
00189         }
00190 
00196         inline bool insert_feature_obj(CDotFeatures* obj)
00197         {
00198             ASSERT(obj);
00199             SG_REF(obj);
00200             bool result=feature_list->insert_element(obj);
00201             update_dim_feature_space_and_num_vec();
00202             return result;
00203         }
00204 
00210         inline bool append_feature_obj(CDotFeatures* obj)
00211         {
00212             ASSERT(obj);
00213             SG_REF(obj);
00214             bool result=feature_list->append_element(obj);
00215             update_dim_feature_space_and_num_vec();
00216             return result;
00217         }
00218 
00223         inline bool delete_feature_obj()
00224         {
00225             CDotFeatures* f=feature_list->delete_element();
00226             if (f)
00227             {
00228                 SG_UNREF(f);
00229                 update_dim_feature_space_and_num_vec();
00230                 return true;
00231             }
00232             else
00233                 return false;
00234         }
00235 
00240         inline int32_t get_num_feature_obj()
00241         {
00242             return feature_list->get_num_elements();
00243         }
00244 
00250         virtual void get_subfeature_weights(float64_t** weights, int32_t* num_weights);
00251 
00257         virtual void set_subfeature_weights(
00258             float64_t* weights, int32_t num_weights);
00259 
00261         inline virtual const char* get_name() const { return "CombinedDotFeatures"; }
00262 
00263     protected:
00265         void update_dim_feature_space_and_num_vec();
00266 
00267     protected:
00269         CList<CDotFeatures*>* feature_list;
00270 
00272         int32_t num_vectors;
00274         int32_t num_dimensions;
00275 };
00276 }
00277 #endif // _DOTFEATURES_H___

SHOGUN Machine Learning Toolbox - Documentation