DotFeatures.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 _DOTFEATURES_H___
00013 #define _DOTFEATURES_H___
00014 
00015 #include "lib/common.h"
00016 #include "lib/Time.h"
00017 #include "lib/Mathematics.h"
00018 #include "features/Features.h"
00019 
00020 namespace shogun
00021 {
00043 class CDotFeatures : public CFeatures
00044 {
00045     public:
00046 
00051         CDotFeatures(int32_t size=0) : CFeatures(size), combined_weight(1.0)
00052         {
00053             set_property(FP_DOT);
00054         }
00055 
00057         CDotFeatures(const CDotFeatures & orig) :
00058             CFeatures(orig), combined_weight(orig.combined_weight)  {}
00059 
00064         CDotFeatures(CFile* loader) : CFeatures(loader) {}
00065 
00066         virtual ~CDotFeatures() { }
00067 
00075         virtual int32_t get_dim_feature_space()=0;
00076 
00083         virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2)=0;
00084 
00091         virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len)=0;
00092 
00101         virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false)=0;
00102 
00116         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);
00117 
00129         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);
00130 
00133         static void* dense_dot_range_helper(void* p);
00134 
00142         virtual int32_t get_nnz_features_for_vector(int32_t num)=0;
00143 
00148         inline float64_t get_combined_feature_weight() { return combined_weight; }
00149 
00154         inline void set_combined_feature_weight(float64_t nw) { combined_weight=nw; }
00155 
00163         virtual void get_feature_matrix(float64_t** dst, int32_t* num_feat, int32_t* num_vec);
00164 
00172         virtual void get_feature_vector(float64_t** dst, int32_t* len, int32_t num);
00173 
00175         void benchmark_add_to_dense_vector(int32_t repeats=5);
00176 
00178         void benchmark_dense_dot_range(int32_t repeats=5);
00179 
00189         virtual void* get_feature_iterator(int32_t vector_index)=0;
00190 
00201         virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator)=0;
00202 
00208         virtual void free_feature_iterator(void* iterator)=0;
00209 
00210     protected:
00217         inline void display_progress(int32_t start, int32_t stop, int32_t v)
00218         {
00219             int32_t num_vectors=stop-start;
00220             int32_t i=v-start;
00221 
00222             if ( (i% (num_vectors/100+1))== 0)
00223                 SG_PROGRESS(v, 0.0, num_vectors-1);
00224         }
00225 
00226 #ifdef HAVE_BOOST_SERIALIZATION
00227         friend class ::boost::serialization::access;
00228         // When the class Archive corresponds to an output archive, the
00229         // & operator is defined similar to <<.  Likewise, when the class Archive
00230         // is a type of input archive the & operator is defined similar to >>.
00231         template<class Archive>
00232             void serialize(Archive & ar, const unsigned int archive_version)
00233             {
00234 
00235                 SG_DEBUG("archiving DotFeatures\n");
00236 
00237                 ar & ::boost::serialization::base_object<CFeatures>(*this);
00238                 ar & combined_weight;
00239 
00240                 SG_DEBUG("done with DotFeatures\n");
00241             }
00242 
00243 #endif //HAVE_BOOST_SERIALIZATION
00244 
00245     protected:
00246 
00248         float64_t combined_weight;
00249 };
00250 }
00251 #endif // _DOTFEATURES_H___
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation