ImplicitWeightedSpecFeatures.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-2010 Soeren Sonnenburg
00008  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  * Copyright (C) 2010 Berlin Institute of Technology
00010  */
00011 
00012 #ifndef _IMPLICITSPECFEATURES_H___
00013 #define _IMPLICITSPECFEATURES_H___
00014 
00015 #include <shogun/lib/common.h>
00016 #include <shogun/io/SGIO.h>
00017 #include <shogun/features/DotFeatures.h>
00018 #include <shogun/features/StringFeatures.h>
00019 
00020 namespace shogun
00021 {
00022 
00023 template <class ST> class CStringFeatures;
00024 
00030 class CImplicitWeightedSpecFeatures : public CDotFeatures
00031 {
00032     public:
00034         CImplicitWeightedSpecFeatures();
00035 
00041         CImplicitWeightedSpecFeatures(CStringFeatures<uint16_t>* str, bool normalize=true);
00042 
00044         CImplicitWeightedSpecFeatures(const CImplicitWeightedSpecFeatures & orig);
00045 
00046         virtual ~CImplicitWeightedSpecFeatures();
00047 
00052         virtual CFeatures* duplicate() const;
00053 
00061         virtual int32_t get_dim_feature_space() const;
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,
00089                 float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00090 
00096         virtual int32_t get_nnz_features_for_vector(int32_t num);
00097 
00102         virtual EFeatureType get_feature_type() const;
00103 
00108         virtual EFeatureClass get_feature_class() const;
00109 
00114         virtual int32_t get_num_vectors() const;
00115 
00120         virtual int32_t get_size() const;
00121 
00126         bool set_wd_weights();
00127 
00134         bool set_weights(float64_t* w, int32_t d);
00135 
00136         #ifndef DOXYGEN_SHOULD_SKIP_THIS
00137 
00138         struct wspec_feature_iterator
00139         {
00141             uint16_t* vec;
00143             int32_t vidx;
00145             int32_t vlen;
00147             bool vfree;
00148 
00153             int32_t offs;
00154             int32_t d;
00155             int32_t j;
00156             uint8_t mask;
00157             float64_t alpha;
00159         };
00160         #endif
00161 
00171         virtual void* get_feature_iterator(int32_t vector_index);
00172 
00183         virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator);
00184 
00190         virtual void free_feature_iterator(void* iterator);
00191 
00193         virtual const char* get_name() const { return "ImplicitWeightedSpecFeatures"; }
00194 
00195     protected:
00200         void compute_normalization_const();
00201 
00202     protected:
00204         CStringFeatures<uint16_t>* strings;
00205 
00207         float64_t* normalization_factors;
00209         int32_t num_strings;
00211         int32_t alphabet_size;
00212 
00214         int32_t degree;
00216         int32_t spec_size;
00217 
00219         float64_t* spec_weights;
00220 };
00221 }
00222 #endif // _IMPLICITSPECFEATURES_H___
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation