Skip to content

Commit

Permalink
Merge pull request #317 from frx/streaming_vw
Browse files Browse the repository at this point in the history
StreamingSparseFeatures improvements
  • Loading branch information
Soeren Sonnenburg committed Aug 27, 2011
2 parents a5ad47f + 1acb396 commit 3c81fe4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
18 changes: 18 additions & 0 deletions src/interfaces/modular/Features.i
Expand Up @@ -72,6 +72,24 @@ namespace shogun
%template(StringLongRealFeatures) CStringFeatures<floatmax_t>;
}

/* Templated Class StreamingStringFeatures */
%include <shogun/features/StreamingStringFeatures.h>
namespace shogun
{
%template(StreamingStringBoolFeatures) CStreamingStringFeatures<bool>;
%template(StreamingStringCharFeatures) CStreamingStringFeatures<char>;
%template(StreamingStringByteFeatures) CStreamingStringFeatures<uint8_t>;
%template(StreamingStringShortFeatures) CStreamingStringFeatures<int16_t>;
%template(StreamingStringWordFeatures) CStreamingStringFeatures<uint16_t>;
%template(StreamingStringIntFeatures) CStreamingStringFeatures<int32_t>;
%template(StreamingStringUIntFeatures) CStreamingStringFeatures<uint32_t>;
%template(StreamingStringLongFeatures) CStreamingStringFeatures<int64_t>;
%template(StreamingStringUlongFeatures) CStreamingStringFeatures<uint64_t>;
%template(StreamingStringShortRealFeatures) CStreamingStringFeatures<float32_t>;
%template(StreamingStringRealFeatures) CStreamingStringFeatures<float64_t>;
%template(StreamingStringLongRealFeatures) CStreamingStringFeatures<floatmax_t>;
}

/* Templated Class StringFileFeatures */
%include <shogun/features/StringFileFeatures.h>
namespace shogun
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/modular/Features_includes.i
Expand Up @@ -4,6 +4,7 @@
#include <shogun/features/Features.h>
#include <shogun/features/StreamingFeatures.h>
#include <shogun/features/StringFeatures.h>
#include <shogun/features/StreamingStringFeatures.h>
#include <shogun/features/StringFileFeatures.h>
#include <shogun/features/DotFeatures.h>
#include <shogun/features/StreamingDotFeatures.h>
Expand Down
22 changes: 11 additions & 11 deletions src/shogun/features/StreamingSparseFeatures.h
Expand Up @@ -128,7 +128,7 @@ template <class T> class CStreamingSparseFeatures : public CStreamingDotFeatures

if (current_vector)
{
for (int32_t i=0; i<current_num_features; i++)
for (int32_t i=0; i<current_length; i++)
if (current_vector[i].feat_index==index)
ret += current_vector[i].entry;
}
Expand All @@ -148,7 +148,7 @@ template <class T> class CStreamingSparseFeatures : public CStreamingDotFeatures
*
* Examples must be labelled, otherwise an error occurs.
*
* @return The label as a float32_t.
* @return The label as a float64_t.
*/
virtual float64_t get_label();

Expand Down Expand Up @@ -343,10 +343,10 @@ template <class T> class CStreamingSparseFeatures : public CStreamingDotFeatures
virtual float64_t dense_dot(const float64_t* vec2, int32_t vec2_len)
{
ASSERT(vec2);
if (vec2_len < current_num_features+1)
if (vec2_len < current_num_features)
{
SG_ERROR("dimension of vec2 (=%d) does not match number of features (=%d)\n",
vec2_len, current_num_features+1);
vec2_len, current_num_features);
}

float64_t result=0;
Expand All @@ -370,10 +370,10 @@ template <class T> class CStreamingSparseFeatures : public CStreamingDotFeatures
virtual float32_t dense_dot(const float32_t* vec2, int32_t vec2_len)
{
ASSERT(vec2);
if (vec2_len < current_num_features+1)
if (vec2_len < current_num_features)
{
SG_ERROR("dimension of vec2 (=%d) does not match number of features (=%d)\n",
vec2_len, current_num_features+1);
vec2_len, current_num_features);
}

float32_t result=0;
Expand All @@ -398,10 +398,10 @@ template <class T> class CStreamingSparseFeatures : public CStreamingDotFeatures
virtual void add_to_dense_vec(float64_t alpha, float64_t* vec2, int32_t vec2_len, bool abs_val=false)
{
ASSERT(vec2);
if (vec2_len < current_num_features+1)
if (vec2_len < current_num_features)
{
SG_ERROR("dimension of vec (=%d) does not match number of features (=%d)\n",
vec2_len, current_num_features+1);
vec2_len, current_num_features);
}

SGSparseVectorEntry<T>* sv=current_vector;
Expand Down Expand Up @@ -434,10 +434,10 @@ template <class T> class CStreamingSparseFeatures : public CStreamingDotFeatures
virtual void add_to_dense_vec(float32_t alpha, float32_t* vec2, int32_t vec2_len, bool abs_val=false)
{
ASSERT(vec2);
if (vec2_len < current_num_features+1)
if (vec2_len < current_num_features)
{
SG_ERROR("dimension of vec (=%d) does not match number of features (=%d)\n",
vec2_len, current_num_features+1);
vec2_len, current_num_features);
}

SGSparseVectorEntry<T>* sv=current_vector;
Expand Down Expand Up @@ -711,7 +711,7 @@ bool CStreamingSparseFeatures<T>::get_next_example()
for (int32_t i=0; i<current_length; i++)
{
if (current_vector[i].feat_index > current_num_features)
current_num_features = current_vector[i].feat_index;
current_num_features = current_vector[i].feat_index+1;
}

current_vec_index++;
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/features/StreamingStringFeatures.h
Expand Up @@ -66,7 +66,7 @@ template <class T> class CStreamingStringFeatures : public CStreamingFeatures
*
* Ends the parsing thread. (Waits for pthread_join to complete)
*/
~CStreamingStringFeatures()
virtual ~CStreamingStringFeatures()
{
parser.end_parser();
SG_UNREF(alphabet);
Expand Down

0 comments on commit 3c81fe4

Please sign in to comment.