Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
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
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
00153
00154 vector_num++;
00155 }
00156
00157
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__