Skip to content

Commit

Permalink
Merge pull request #181 from frx/streaming_1
Browse files Browse the repository at this point in the history
OnlineLinearMachine minor modifications
  • Loading branch information
Soeren Sonnenburg committed Jul 7, 2011
2 parents 37fcfdc + b93b623 commit e5e175f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/libshogun/lib/InputParser.h
Expand Up @@ -337,6 +337,11 @@ namespace shogun
template <class T>
void CInputParser<T>::start_parser()
{
if (is_running())
{
SG_SERROR("Parser thread is already running! Multiple parse threads not supported.\n");
}

pthread_create(&parse_thread, NULL, parse_loop_entry_point, this);
}

Expand Down
32 changes: 29 additions & 3 deletions src/libshogun/machine/OnlineLinearMachine.cpp
Expand Up @@ -43,8 +43,34 @@ bool COnlineLinearMachine::save(FILE* dstfile)

CLabels* COnlineLinearMachine::apply()
{
SG_NOTIMPLEMENTED;
return NULL;
ASSERT(features);
ASSERT(features->has_property(FP_STREAMING_DOT));

DynArray<float64_t>* labels_dynarray=new DynArray<float64_t>();
int32_t num_labels=0;

features->start_parser();
while (features->get_next_example())
{
float64_t current_lab=features->dense_dot(w, w_dim) + bias;

labels_dynarray->append_element(current_lab);
num_labels++;

features->release_example();
}
features->end_parser();

float64_t* labels_array=new float64_t[num_labels];
for (int32_t i=0; i<num_labels; i++)
{
labels_array[i]=(*labels_dynarray)[i];
}

CLabels* labels_object=new CLabels(labels_array, num_labels);
SG_REF(labels_object);

return labels_object;
}

CLabels* COnlineLinearMachine::apply(CFeatures* data)
Expand All @@ -62,7 +88,7 @@ float64_t COnlineLinearMachine::apply(float64_t* vec, int32_t len)
return CMath::dot(vec, w, len)+bias;
}

float64_t COnlineLinearMachine::apply_to_this_example()
float64_t COnlineLinearMachine::apply_to_current_example()
{
return features->dense_dot(w, w_dim)+bias;
}
17 changes: 1 addition & 16 deletions src/libshogun/machine/OnlineLinearMachine.h
Expand Up @@ -65,21 +65,6 @@ class COnlineLinearMachine : public CMachine
dst_dims=w_dim;
}

/** get w (swig compatible)
*
* @param dst_w store w in this argument
* @param dst_dims dimension of w
*/
inline void get_w(float64_t** dst_w, int32_t* dst_dims)
{
ASSERT(dst_w && dst_dims);
ASSERT(w && w_dim>0);
*dst_dims=w_dim;
*dst_w=(float64_t*) SG_MALLOC(sizeof(float64_t)*(*dst_dims));
ASSERT(*dst_w);
memcpy(*dst_w, w, sizeof(float64_t) * (*dst_dims));
}

/** get w
*
* @return weight vector
Expand Down Expand Up @@ -180,7 +165,7 @@ class COnlineLinearMachine : public CMachine
*
* @return classified label
*/
virtual float64_t apply_to_this_example();
virtual float64_t apply_to_current_example();

/** get features
*
Expand Down

0 comments on commit e5e175f

Please sign in to comment.