24 parser.set_free_vector_after_release(
false);
29 bool is_labelled, int32_t size) :
32 init(file, is_labelled, size);
34 parser.set_free_vector_after_release(
false);
41 REQUIRE(dense_features,
"%s::CStreamingDenseFeatures(): Features needed!\n")
49 init(file, is_labelled, size);
51 parser.set_free_vector_after_release(
false);
52 parser.set_free_vectors_on_destruct(
false);
58 SG_DEBUG(
"entering %s::~CStreamingDenseFeatures()\n", get_name())
60 current_vector.vector=NULL;
61 current_vector.vlen=0;
62 SG_DEBUG(
"leaving %s::~CStreamingDenseFeatures()\n", get_name())
70 if (parser.is_running())
73 parser.init(working_file, has_labels, 1);
74 parser.set_free_vector_after_release(
false);
75 parser.set_free_vectors_on_destruct(
false);
76 parser.start_parser();
83 ASSERT(vec2_len==current_vector.vlen)
86 for (int32_t i=0; i<current_vector.vlen; i++)
87 result+=current_vector[i]*vec2[i];
95 ASSERT(vec2_len==current_vector.vlen)
98 for (int32_t i=0; i<current_vector.vlen; i++)
99 result+=current_vector[i]*vec2[i];
107 ASSERT(vec2_len==current_vector.vlen)
111 for (int32_t i=0; i<current_vector.vlen; i++)
112 vec2[i]+=alpha*CMath::abs(current_vector[i]);
116 for (int32_t i=0; i<current_vector.vlen; i++)
117 vec2[i]+=alpha*current_vector[i];
124 ASSERT(vec2_len==current_vector.vlen)
128 for (int32_t i=0; i<current_vector.vlen; i++)
129 vec2[i]+=alpha*CMath::abs(current_vector[i]);
133 for (int32_t i=0; i<current_vector.vlen; i++)
134 vec2[i]+=alpha*current_vector[i];
140 return current_vector.vlen;
151 parser.set_read_vector(&CStreamingFile::get_vector);
157 parser.set_read_vector_and_label(&CStreamingFile::get_vector_and_label);
160 #define GET_FEATURE_TYPE(f_type, sg_type) \ 161 template<> EFeatureType CStreamingDenseFeatures<sg_type>::get_feature_type() const \ 179 #undef GET_FEATURE_TYPE 182 void CStreamingDenseFeatures<T>::init()
188 current_vector.vector=NULL;
189 current_vector.vlen=-1;
195 void CStreamingDenseFeatures<T>::init(CStreamingFile* file,
bool is_labelled,
199 has_labels=is_labelled;
202 parser.init(file, is_labelled, size);
209 if (!parser.is_running())
224 ret_value=(bool)parser.get_next_example(current_vector.vector,
225 current_vector.vlen, current_label);
234 return current_vector;
242 return current_label;
248 parser.finalize_example();
254 return current_vector.vlen;
267 return CMath::dot(current_vector.vector, other_vector.
vector, current_vector.vlen);
276 if (len1!=current_vector.vlen)
278 "Lengths %d and %d not equal while computing dot product!\n", len1, current_vector.vlen);
286 return current_vector.vlen;
300 SG_DEBUG(
"Streaming %d elements\n", num_elements)
302 REQUIRE(num_elements>0,
"Requested number of feature vectors (%d) must be " 303 "positive\n", num_elements);
308 for (
index_t i=0; i<num_elements; ++i)
311 if (!get_next_example())
313 SG_WARNING(
"Ran out of streaming data, reallocating matrix and " 331 SG_DEBUG(
"Allocating %dx%d matrix\n",
332 current_vector.vlen, num_elements);
333 matrix=
SGMatrix<T>(current_vector.vlen, num_elements);
341 "Dimension of streamed vector (%d) does not match " 342 "dimensions of previous vectors (%d)\n",
346 sg_memcpy(&matrix.
matrix[current_vector.vlen*i], vec.vector,
Class CStreamingFileFromDenseFeatures is a derived class of CStreamingFile which creates an input sou...
This class implements streaming features with dense feature vectors.
T dot(const SGVector< T > &a, const SGVector< T > &b)
#define GET_FEATURE_TYPE(f_type, sg_type)
virtual void reset_stream()
EFeatureClass
shogun feature class
A Streaming File access class.
virtual EFeatureClass get_feature_class() const =0
Streaming features that support dot products among other operations.
virtual void end_parser()
all of classes and functions are contained in the shogun namespace
The class Features is the base class of all feature objects.
CStreamingDenseFeatures()
virtual void start_parser()
virtual EFeatureType get_feature_type() const =0