StreamingFileFromSimpleFeatures.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_FILEFROMSIMPLE_H__
00011 #define __STREAMING_FILEFROMSIMPLE_H__
00012 
00013 #include <shogun/io/StreamingFileFromFeatures.h>
00014 #include <shogun/features/SimpleFeatures.h>
00015 
00016 namespace shogun
00017 {
00027 template <class T> class CStreamingFileFromSimpleFeatures: public CStreamingFileFromFeatures
00028 {
00029 public:
00033     CStreamingFileFromSimpleFeatures();
00034 
00040     CStreamingFileFromSimpleFeatures(CSimpleFeatures<T>* feat);
00041 
00048     CStreamingFileFromSimpleFeatures(CSimpleFeatures<T>* feat, float64_t* lab);
00049 
00053     virtual ~CStreamingFileFromSimpleFeatures();
00054 
00063     virtual void get_vector(T* &vec, int32_t &len);
00064 
00074     virtual void get_vector_and_label(T* &vec, int32_t &len, float64_t &label);
00075 
00081     void reset_stream()
00082     {
00083         vector_num = 0;
00084     }
00085 
00087     inline virtual const char* get_name() const
00088     {
00089         return "StreamingFileFromSimpleFeatures";
00090 
00091     }
00092 
00093 private:
00097     void init();
00098 
00099 protected:
00100 
00102     CSimpleFeatures<T>* features;
00103 
00105     int32_t vector_num;
00106 
00107 };
00108 
00109 template <class T>
00110 CStreamingFileFromSimpleFeatures<T>::CStreamingFileFromSimpleFeatures()
00111     : CStreamingFileFromFeatures()
00112 {
00113     init();
00114 }
00115 
00116 template <class T>
00117 CStreamingFileFromSimpleFeatures<T>::CStreamingFileFromSimpleFeatures(CSimpleFeatures<T>* feat)
00118     : CStreamingFileFromFeatures()
00119 {
00120     ASSERT(feat);
00121     features=feat;
00122 
00123     init();
00124 }
00125 
00126 template <class T>
00127 CStreamingFileFromSimpleFeatures<T>::CStreamingFileFromSimpleFeatures(CSimpleFeatures<T>* feat, float64_t* lab)
00128     : CStreamingFileFromFeatures()
00129 {
00130     ASSERT(feat);
00131     ASSERT(lab);
00132     features=feat;
00133     labels=lab;
00134 
00135     init();
00136 }
00137 
00138 template <class T>
00139 CStreamingFileFromSimpleFeatures<T>::~CStreamingFileFromSimpleFeatures()
00140 {
00141 }
00142 
00143 template <class T>
00144 void CStreamingFileFromSimpleFeatures<T>::init()
00145 {
00146     vector_num=0;
00147 }
00148 
00149 /* Functions to return the vector from the SimpleFeatures object
00150  * If the class is of type T, specialize this function to work for
00151  * vectors of that type. */
00152 template <class T>
00153 void CStreamingFileFromSimpleFeatures<T>::get_vector(T*& vector, int32_t& num_feat)
00154 {
00155     if (vector_num >= features->get_num_vectors())
00156     {
00157         vector=NULL;
00158         num_feat=-1;
00159         return;
00160     }
00161 
00162     SGVector<T> sg_vector=
00163         features->get_feature_vector(vector_num);
00164 
00165     vector = sg_vector.vector;
00166     num_feat = sg_vector.vlen;;
00167     vector_num++;
00168 
00169 }
00170 
00171 /* Functions to return the vector from the SimpleFeatures object with label */
00172 template <class T>
00173 void CStreamingFileFromSimpleFeatures<T>::get_vector_and_label
00174 (T*& vector, int32_t& num_feat, float64_t& label)
00175 {
00176     if (vector_num >= features->get_num_vectors())
00177     {
00178         vector=NULL;
00179         num_feat=-1;
00180         return;
00181     }
00182 
00183     SGVector<T> sg_vector
00184         =features->get_feature_vector(vector_num);
00185 
00186     vector = sg_vector.vector;
00187     num_feat = sg_vector.vlen;
00188     label = labels[vector_num];
00189 
00190     vector_num++;
00191 }
00192 
00193 }
00194 #endif //__STREAMING_FILEFROMSIMPLE_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation