SHOGUN  6.1.3
OnlineLinearMachine.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
12 #include <shogun/base/Parameter.h>
16 
17 #include <vector>
18 
19 using namespace shogun;
20 
22 : CMachine(), bias(0), features(NULL)
23 {
24  SG_ADD(&m_w, "m_w", "Parameter vector w.", MS_NOT_AVAILABLE);
25  SG_ADD(&bias, "bias", "Bias b.", MS_NOT_AVAILABLE);
26  SG_ADD((CSGObject**) &features, "features",
27  "Feature object.", MS_NOT_AVAILABLE);
28 }
29 
31 {
33 }
34 
36 {
37  SGVector<float64_t> outputs = apply_get_outputs(data);
38  return new CBinaryLabels(outputs);
39 }
40 
42 {
43  SGVector<float64_t> outputs = apply_get_outputs(data);
44  return new CRegressionLabels(outputs);
45 }
46 
48 {
49  if (data)
50  {
51  if (!data->has_property(FP_STREAMING_DOT))
52  SG_ERROR("Specified features are not of type CStreamingDotFeatures\n")
53 
55  }
56 
59 
60  std::vector<float64_t> labels;
62  while (features->get_next_example())
63  {
64  float64_t current_lab=features->dense_dot(m_w.vector, m_w.vlen) + bias;
65 
66  labels.push_back(current_lab);
68  }
70 
71  SGVector<float64_t> labels_array(labels.size());
72  sg_memcpy(labels_array.vector, labels.data(), sizeof(float64_t)*labels.size());
73 
74  return labels_array;
75 }
76 
78 {
79  SGVector<float32_t> wrap(vec, len, false);
80  return linalg::dot(wrap, m_w)+bias;
81 }
82 
84 {
86 }
87 
89 {
90  if (data)
91  {
92  if (!data->has_property(FP_STREAMING_DOT))
93  SG_ERROR("Specified features are not of type CStreamingDotFeatures\n")
95  }
96  start_train();
98  while (features->get_next_example())
99  {
102  }
103 
104  features->end_parser();
105  stop_train();
106 
107  return true;
108 }
virtual CRegressionLabels * apply_regression(CFeatures *data=NULL)
Real Labels are real-valued labels.
virtual void start_parser()=0
virtual float32_t dense_dot(const float32_t *vec2, int32_t vec2_len)=0
#define SG_ERROR(...)
Definition: SGIO.h:128
T dot(const SGVector< T > &a, const SGVector< T > &b)
T wrap(const T &value)
Definition: some.h:151
A generic learning machine interface.
Definition: Machine.h:151
virtual void set_features(CStreamingDotFeatures *feat)
virtual bool get_next_example()=0
#define ASSERT(x)
Definition: SGIO.h:176
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:124
virtual bool train_machine(CFeatures *data=NULL)
virtual float32_t apply_to_current_example()
double float64_t
Definition: common.h:60
virtual float64_t apply_one(int32_t vec_idx)
get output for example "vec_idx"
Streaming features that support dot products among other operations.
float float32_t
Definition: common.h:59
#define SG_UNREF(x)
Definition: SGObject.h:53
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual void end_parser()=0
CStreamingDotFeatures * features
The class Features is the base class of all feature objects.
Definition: Features.h:69
virtual void release_example()=0
virtual float64_t get_label()=0
Binary Labels for binary classification.
Definition: BinaryLabels.h:37
virtual CBinaryLabels * apply_binary(CFeatures *data=NULL)
#define SG_ADD(...)
Definition: SGObject.h:93
bool has_property(EFeatureProperty p) const
Definition: Features.cpp:295
virtual void train_example(CStreamingDotFeatures *feature, float64_t label)
SGVector< float64_t > apply_get_outputs(CFeatures *data)
index_t vlen
Definition: SGVector.h:571

SHOGUN Machine Learning Toolbox - Documentation