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 
00038 class CCombinedDotFeatures : public CDotFeatures
00039 {
00040     public:
00042         CCombinedDotFeatures();
00043 
00045         CCombinedDotFeatures(const CCombinedDotFeatures & orig);
00046 
00048         virtual ~CCombinedDotFeatures();
00049 
00050         inline virtual int32_t get_num_vectors()
00051         {
00052             return num_vectors;
00053         }
00054 
00059         inline virtual int32_t get_dim_feature_space()
00060         {
00061             return  num_dimensions;
00062         }
00063 
00070         virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2);
00071 
00078         virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00079 
00088         virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00089 
00095         virtual int32_t get_nnz_features_for_vector(int32_t num);
00096 
00101         inline virtual EFeatureType get_feature_type()
00102         {
00103             return F_DREAL;
00104         }
00105 
00110         inline virtual EFeatureClass get_feature_class()
00111         {
00112             return C_COMBINED_DOT;
00113         }
00114 
00115         inline virtual int32_t get_size()
00116         {
00117             return sizeof(float64_t);
00118         }
00119 
00124         virtual CFeatures* duplicate() const;
00125 
00127         void list_feature_objs();
00128 
00133         inline CDotFeatures* get_first_feature_obj()
00134         {
00135             CDotFeatures* f=feature_list->get_first_element();
00136             SG_REF(f);
00137             return f;
00138         }
00139 
00145         inline CDotFeatures* get_first_feature_obj(CListElement<CDotFeatures*>*&current)
00146         {
00147             CDotFeatures* f=feature_list->get_first_element(current);
00148             SG_REF(f);
00149             return f;
00150         }
00151 
00156         inline CDotFeatures* get_next_feature_obj()
00157         {
00158             CDotFeatures* f=feature_list->get_next_element();
00159             SG_REF(f);
00160             return f;
00161         }
00162 
00168         inline CDotFeatures* get_next_feature_obj(CListElement<CDotFeatures*>*&current)
00169         {
00170             CDotFeatures* f=feature_list->get_next_element(current);
00171             SG_REF(f);
00172             return f;
00173         }
00174 
00179         inline CDotFeatures* get_last_feature_obj()
00180         {
00181             CDotFeatures* f=feature_list->get_last_element();
00182             SG_REF(f);
00183             return f;
00184         }
00185 
00191         inline bool insert_feature_obj(CDotFeatures* obj)
00192         {
00193             ASSERT(obj);
00194             SG_REF(obj);
00195             bool result=feature_list->insert_element(obj);
00196             update_dim_feature_space_and_num_vec();
00197             return result;
00198         }
00199 
00205         inline bool append_feature_obj(CDotFeatures* obj)
00206         {
00207             ASSERT(obj);
00208             SG_REF(obj);
00209             bool result=feature_list->append_element(obj);
00210             update_dim_feature_space_and_num_vec();
00211             return result;
00212         }
00213 
00218         inline bool delete_feature_obj()
00219         {
00220             CDotFeatures* f=feature_list->delete_element();
00221             if (f)
00222             {
00223                 SG_UNREF(f);
00224                 update_dim_feature_space_and_num_vec();
00225                 return true;
00226             }
00227             else
00228                 return false;
00229         }
00230 
00235         inline int32_t get_num_feature_obj()
00236         {
00237             return feature_list->get_num_elements();
00238         }
00239 
00245         virtual void get_subfeature_weights(float64_t** weights, int32_t* num_weights);
00246 
00252         virtual void set_subfeature_weights(
00253             float64_t* weights, int32_t num_weights);
00254 
00256         inline virtual const char* get_name() const { return "CombinedDotFeatures"; }
00257 
00258     protected:
00260         void update_dim_feature_space_and_num_vec();
00261 
00262     protected:
00264         CList<CDotFeatures*>* feature_list;
00265 
00267         int32_t num_vectors;
00269         int32_t num_dimensions;
00270 };
00271 #endif // _DOTFEATURES_H___

SHOGUN Machine Learning Toolbox - Documentation