SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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         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, 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 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         virtual EFeatureType get_feature_type() const
00138         {
00139             return F_UNKNOWN;
00140         }
00141 
00146         virtual EFeatureClass get_feature_class() const
00147         {
00148             return C_WD;
00149         }
00150 
00151         virtual int32_t get_num_vectors() const
00152         {
00153             return num_strings;
00154         }
00155 
00158         void set_normalization_const(float64_t n=0);
00159 
00161         inline float64_t get_normalization_const()
00162         {
00163             return normalization_const;
00164         }
00165 
00166         #ifndef DOXYGEN_SHOULD_SKIP_THIS
00167 
00168         struct hashed_wd_transposed_feature_iterator
00169         {
00171             uint16_t* vec;
00173             int32_t vidx;
00175             int32_t vlen;
00177             bool vfree;
00178 
00180             int32_t index;
00181 
00182         };
00183         #endif
00184 
00194         virtual void* get_feature_iterator(int32_t vector_index);
00195 
00206         virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator);
00207 
00213         virtual void free_feature_iterator(void* iterator);
00214 
00216         virtual const char* get_name() const { return "HashedWDFeaturesTransposed"; }
00217 
00218     protected:
00219 
00221         void set_wd_weights();
00222 
00224         static void* dense_dot_range_helper(void* p);
00225 
00226     protected:
00228         CStringFeatures<uint8_t>* strings;
00229 
00231         SGString<uint8_t>* transposed_strings;
00232 
00234         int32_t degree;
00236         int32_t start_degree;
00238         int32_t from_degree;
00240         int32_t string_length;
00242         int32_t num_strings;
00244         int32_t alphabet_size;
00246         int32_t w_dim;
00248         int32_t partial_w_dim;
00250         float64_t* wd_weights;
00252         uint32_t mask;
00254         int32_t m_hash_bits;
00255 
00257         float64_t normalization_const;
00258 };
00259 }
00260 #endif // _HASHEDWDFEATURESTRANSPOSED_H___
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation