StreamingDotFeatures.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) 2011 Shashwat Lal Das
00008  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
00009  */
00010 #ifndef _STREAMING_DOTFEATURES__H__
00011 #define _STREAMING_DOTFEATURES__H__
00012 
00013 #include <shogun/lib/common.h>
00014 #include <shogun/lib/Time.h>
00015 #include <shogun/mathematics/Math.h>
00016 #include <shogun/features/StreamingFeatures.h>
00017 #include <shogun/features/DotFeatures.h>
00018 #include <shogun/io/StreamingFile.h>
00019 
00020 namespace shogun
00021 {
00044 class CStreamingDotFeatures : public CStreamingFeatures
00045 {
00046 
00047     virtual void init() { };
00048 
00049     virtual void init(CStreamingFile *file, bool is_labelled, int32_t size) { };
00050 
00051 public:
00053     CStreamingDotFeatures()
00054         : CStreamingFeatures()
00055     {
00056         init();
00057         set_property(FP_STREAMING_DOT);
00058     }
00059 
00067     CStreamingDotFeatures(CStreamingFile* file, bool is_labelled, int32_t size)
00068         : CStreamingFeatures()
00069     {
00070         init(file, is_labelled, size);
00071         set_property(FP_STREAMING_DOT);
00072     }
00073 
00086     CStreamingDotFeatures(CDotFeatures* dot_features, float64_t* lab=NULL)
00087     {
00088         SG_NOTIMPLEMENTED;
00089         return;
00090     }
00091 
00092     virtual ~CStreamingDotFeatures() { }
00093 
00100     virtual float32_t dot(CStreamingDotFeatures* df)=0;
00101 
00107     virtual float32_t dense_dot(const float32_t* vec2, int32_t vec2_len)=0;
00108 
00126     virtual void dense_dot_range(float32_t* output, float32_t* alphas, float32_t* vec, int32_t dim, float32_t b, int32_t num_vec=0)
00127     {
00128         ASSERT(num_vec>=0);
00129 
00130         int32_t counter=0;
00131         start_parser();
00132         while (get_next_example())
00133         {
00134             if (alphas)
00135                 output[counter]=alphas[counter]*dense_dot(vec, dim)+b;
00136             else
00137                 output[counter]=dense_dot(vec, dim)+b;
00138 
00139             release_example();
00140 
00141             counter++;
00142             if ((counter>=num_vec) && (num_vec>0))
00143                 break;
00144         }
00145         end_parser();
00146     }
00147 
00155     virtual void add_to_dense_vec(float32_t alpha, float32_t* vec2, int32_t vec2_len, bool abs_val=false)=0;
00156 
00165     inline virtual void expand_if_required(float32_t*& vec, int32_t &len)
00166     {
00167         int32_t dim = get_dim_feature_space();
00168         if (dim > len)
00169         {
00170             vec = SG_REALLOC(float32_t, vec, dim);
00171             memset(&vec[len], 0, (dim-len) * sizeof(float32_t));
00172             len = dim;
00173         }
00174     }
00175 
00184     inline virtual void expand_if_required(float64_t*& vec, int32_t &len)
00185     {
00186         int32_t dim = get_dim_feature_space();
00187         if (dim > len)
00188         {
00189             vec = SG_REALLOC(float64_t, vec, dim);
00190             memset(&vec[len], 0, (dim-len) * sizeof(float64_t));
00191             len = dim;
00192         }
00193     }
00194 
00202     virtual int32_t get_dim_feature_space() const=0;
00203 
00210     virtual void* get_feature_iterator()
00211     {
00212         SG_NOTIMPLEMENTED;
00213         return NULL;
00214     }
00215 
00222     virtual int32_t get_nnz_features_for_vector()
00223     {
00224         SG_NOTIMPLEMENTED;
00225         return -1;
00226     }
00227 
00238     virtual bool get_next_feature(int32_t& index, float32_t& value, void* iterator)
00239     {
00240         SG_NOTIMPLEMENTED;
00241         return false;
00242     }
00243 
00249     virtual void free_feature_iterator(void* iterator)
00250     {
00251         SG_NOTIMPLEMENTED;
00252         return;
00253     }
00254 
00255 
00256 protected:
00257 
00259     float32_t combined_weight;
00260 };
00261 }
00262 #endif // _STREAMING_DOTFEATURES__H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation