HashedWDFeatures.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) 2010 Soeren Sonnenburg
00008  * Copyright (C) 2010 Berlin Institute of Technology
00009  */
00010 
00011 #ifndef _HASHEDWDFEATURES_H___
00012 #define _HASHEDWDFEATURES_H___
00013 
00014 #include "lib/common.h"
00015 #include "features/DotFeatures.h"
00016 #include "features/StringFeatures.h"
00017 #include "lib/Hash.h"
00018 
00019 namespace shogun
00020 {
00021 template <class ST> class CStringFeatures;
00022 
00028 class CHashedWDFeatures : public CDotFeatures
00029 {
00030     public:
00032         CHashedWDFeatures(void);
00033 
00042         CHashedWDFeatures(CStringFeatures<uint8_t>* str, int32_t start_order,
00043                 int32_t order,  int32_t from_order, int32_t hash_bits=12);
00044 
00046         CHashedWDFeatures(const CHashedWDFeatures & orig);
00047 
00049         virtual ~CHashedWDFeatures();
00050 
00058         inline virtual int32_t get_dim_feature_space()
00059         {
00060             return w_dim;
00061         }
00062 
00070         virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, 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 inline int32_t get_nnz_features_for_vector(int32_t num)
00096         {
00097             int32_t vlen=-1;
00098             bool free_vec;
00099             uint8_t* vec=strings->get_feature_vector(num, vlen, free_vec);
00100             strings->free_feature_vector(vec, num, free_vec);
00101             return degree*vlen;
00102         }
00103 
00105         struct hashed_wd_feature_iterator
00106         {
00108             uint16_t* vec;
00110             int32_t vidx;
00112             int32_t vlen;
00114             bool vfree;
00115 
00117             int32_t index;
00118 
00119         };
00120 
00130         virtual void* get_feature_iterator(int32_t vector_index)
00131         {
00132             SG_NOTIMPLEMENTED;
00133             return NULL;
00134         }
00135 
00146         virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator)
00147         {
00148             SG_NOTIMPLEMENTED;
00149             return NULL;
00150         }
00151 
00157         virtual void free_feature_iterator(void* iterator)
00158         {
00159             SG_NOTIMPLEMENTED;
00160         }
00161 
00166         virtual CFeatures* duplicate() const;
00167 
00172         inline virtual EFeatureType get_feature_type()
00173         {
00174             return F_UNKNOWN;
00175         }
00176 
00181         inline virtual EFeatureClass get_feature_class()
00182         {
00183             return C_WD;
00184         }
00185 
00186         inline virtual int32_t get_num_vectors()
00187         {
00188             return num_strings;
00189         }
00190 
00191         inline virtual int32_t get_size()
00192         {
00193             return sizeof(float64_t);
00194         }
00195 
00198         void set_normalization_const(float64_t n=0);
00199 
00201         inline float64_t get_normalization_const()
00202         {
00203             return normalization_const;
00204         }
00205 
00207         inline virtual const char* get_name() const { return "HashedWDFeatures"; }
00208 
00209     protected:
00210 
00212         void set_wd_weights();
00213 
00214     protected:
00216         CStringFeatures<uint8_t>* strings;
00217 
00219         int32_t degree;
00221         int32_t start_degree;
00223         int32_t from_degree;
00225         int32_t string_length;
00227         int32_t num_strings;
00229         int32_t alphabet_size;
00231         int32_t w_dim;
00233         int32_t partial_w_dim;
00235         float64_t* wd_weights;
00237         uint32_t mask;
00239         int32_t m_hash_bits;
00240 
00242         float64_t normalization_const;
00243 };
00244 }
00245 #endif // _HASHEDWDFEATURES_H___
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation