HashedWDFeaturesTransposed.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 _HASHEDWDFEATURESTRANSPOSED_H___
00012 #define _HASHEDWDFEATURESTRANSPOSED_H___
00013 
00014 #include <shogun/lib/common.h>
00015 #include <shogun/features/DotFeatures.h>
00016 #include <shogun/features/StringFeatures.h>
00017 #include <shogun/lib/Hash.h>
00018 
00019 namespace shogun
00020 {
00021 template <class ST> class CStringFeatures;
00022 
00028 class CHashedWDFeaturesTransposed : public CDotFeatures
00029 {
00030     public:
00032         CHashedWDFeaturesTransposed();
00033 
00042         CHashedWDFeaturesTransposed(CStringFeatures<uint8_t>* str, int32_t start_order,
00043                 int32_t order,  int32_t from_order, int32_t hash_bits=12);
00044 
00046         CHashedWDFeaturesTransposed(const CHashedWDFeaturesTransposed & orig);
00047 
00049         virtual ~CHashedWDFeaturesTransposed();
00050 
00058         inline virtual int32_t get_dim_feature_space() const
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 
00091         virtual void dense_dot_range(float64_t* output, int32_t start, int32_t stop, float64_t* alphas, float64_t* vec, int32_t dim, float64_t b);
00092 
00104         virtual void dense_dot_range_subset(int32_t* sub_index, int32_t num, float64_t* output, float64_t* alphas, float64_t* vec, int32_t dim, float64_t b);
00105 
00106 
00115         virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00116 
00122         virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00123         {
00124             return w_dim/alphabet_size;
00125         }
00126 
00131         virtual CFeatures* duplicate() const;
00132 
00137         inline virtual EFeatureType get_feature_type()
00138         {
00139             return F_UNKNOWN;
00140         }
00141 
00146         inline virtual EFeatureClass get_feature_class()
00147         {
00148             return C_WD;
00149         }
00150 
00151         inline virtual int32_t get_num_vectors() const
00152         {
00153             return num_strings;
00154         }
00155 
00156         inline virtual int32_t get_size()
00157         {
00158             return sizeof(float64_t);
00159         }
00160 
00163         void set_normalization_const(float64_t n=0);
00164 
00166         inline float64_t get_normalization_const()
00167         {
00168             return normalization_const;
00169         }
00170 
00171         #ifndef DOXYGEN_SHOULD_SKIP_THIS
00172 
00173         struct hashed_wd_transposed_feature_iterator
00174         {
00176             uint16_t* vec;
00178             int32_t vidx;
00180             int32_t vlen;
00182             bool vfree;
00183 
00185             int32_t index;
00186 
00187         };
00188         #endif
00189 
00199         virtual void* get_feature_iterator(int32_t vector_index);
00200 
00211         virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator);
00212 
00218         virtual void free_feature_iterator(void* iterator);
00219 
00221         inline virtual const char* get_name() const { return "HashedWDFeaturesTransposed"; }
00222 
00223     protected:
00224 
00226         void set_wd_weights();
00227         static void* dense_dot_range_helper(void* p);
00228 
00229     protected:
00231         CStringFeatures<uint8_t>* strings;
00232 
00234         SGString<uint8_t>* transposed_strings;
00235 
00237         int32_t degree;
00239         int32_t start_degree;
00241         int32_t from_degree;
00243         int32_t string_length;
00245         int32_t num_strings;
00247         int32_t alphabet_size;
00249         int32_t w_dim;
00251         int32_t partial_w_dim;
00253         float64_t* wd_weights;
00255         uint32_t mask;
00257         int32_t m_hash_bits;
00258 
00260         float64_t normalization_const;
00261 };
00262 }
00263 #endif // _HASHEDWDFEATURESTRANSPOSED_H___
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation