StreamingFileFromSparseFeatures.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_FILEFROMSPARSE_H__
00011 #define __STREAMING_FILEFROMSPARSE_H__
00012 
00013 #include <shogun/io/StreamingFileFromFeatures.h>
00014 #include <shogun/features/SparseFeatures.h>
00015 
00016 namespace shogun
00017 {
00022 template <class T> class CStreamingFileFromSparseFeatures: public CStreamingFileFromFeatures
00023 {
00024 public:
00028     CStreamingFileFromSparseFeatures();
00029 
00035     CStreamingFileFromSparseFeatures(CSparseFeatures<T>* feat);
00036 
00043     CStreamingFileFromSparseFeatures(CSparseFeatures<T>* feat, float64_t* lab);
00044 
00048     virtual ~CStreamingFileFromSparseFeatures();
00049 
00058     virtual void get_sparse_vector(SGSparseVectorEntry<T>* &vec, int32_t &len);
00059 
00069     virtual void get_sparse_vector_and_label(SGSparseVectorEntry<T>* &vec, int32_t &len, float64_t &label);
00070 
00076     void reset_stream()
00077     {
00078         vector_num = 0;
00079     }
00080 
00082     inline virtual const char* get_name() const
00083     {
00084         return "StreamingFileFromSparseFeatures";
00085 
00086     }
00087 
00088 private:
00092     void init();
00093 
00094 protected:
00096     CSparseFeatures<T>* features;
00097 
00099     int32_t vector_num;
00100 
00101 };
00102 
00103 template <class T>
00104 CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures()
00105     : CStreamingFileFromFeatures()
00106 {
00107     init();
00108 }
00109 
00110 template <class T>
00111 CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures(CSparseFeatures<T>* feat)
00112     : CStreamingFileFromFeatures(feat)
00113 {
00114     init();
00115 }
00116 
00117 template <class T>
00118 CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures(CSparseFeatures<T>* feat, float64_t* lab)
00119     : CStreamingFileFromFeatures(feat,lab)
00120 {
00121     init();
00122 }
00123 
00124 template <class T>
00125 CStreamingFileFromSparseFeatures<T>::~CStreamingFileFromSparseFeatures()
00126 {
00127 }
00128 
00129 template <class T>
00130 void CStreamingFileFromSparseFeatures<T>::init()
00131 {
00132     vector_num=0;
00133 }
00134 
00135 /* Functions to return the vector from the SparseFeatures object */
00136 template <class T>
00137 void CStreamingFileFromSparseFeatures<T>::get_sparse_vector
00138 (SGSparseVectorEntry<T>*& vector, int32_t& len)
00139 {
00140     if (vector_num >= features->get_num_vectors())
00141     {
00142         vector=NULL;
00143         len=-1;
00144         return;
00145     }
00146 
00147     SGSparseVector<T> vec=
00148             ((CSparseFeatures<T>*)this)->get_sparse_feature_vector(vector_num);
00149     vector=vec.features;
00150     len=vec.num_feat_entries;
00151 
00152     /* TODO. check if vector needs to be freed? */
00153 
00154     vector_num++;
00155 }
00156 
00157 /* Functions to return the vector from the SparseFeatures object */
00158 template <class T>
00159 void CStreamingFileFromSparseFeatures<T>::get_sparse_vector_and_label
00160 (SGSparseVectorEntry<T>*& vector, int32_t& len, float64_t& label)
00161 {
00162     get_sparse_vector(vector, len);
00163     label=labels[vector_num];
00164 }
00165 
00166 }
00167 #endif //__STREAMING_FILEFROMSPARSE_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation