SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
13 
14 using namespace shogun;
15 
17 : CMachine(), w_dim(0), w(NULL), bias(0), features(NULL)
18 {
19  m_parameters->add_vector(&w, &w_dim, "w", "Parameter vector w.");
20  SG_ADD(&bias, "bias", "Bias b.", MS_NOT_AVAILABLE);
21  SG_ADD((CSGObject**) &features, "features",
22  "Feature object.", MS_NOT_AVAILABLE);
23 }
24 
26 {
27  // It is possible that a derived class may have already
28  // called SG_FREE() on the weight vector
29  if (w != NULL)
30  SG_FREE(w);
32 }
33 
35 {
36  SGVector<float64_t> outputs = apply_get_outputs(data);
37  return new CBinaryLabels(outputs);
38 }
39 
41 {
42  SGVector<float64_t> outputs = apply_get_outputs(data);
43  return new CRegressionLabels(outputs);
44 }
45 
47 {
48  if (data)
49  {
50  if (!data->has_property(FP_STREAMING_DOT))
51  SG_ERROR("Specified features are not of type CStreamingDotFeatures\n")
52 
54  }
55 
58 
59  DynArray<float64_t>* labels_dynarray=new DynArray<float64_t>();
60  int32_t num_labels=0;
61 
63  while (features->get_next_example())
64  {
65  float64_t current_lab=features->dense_dot(w, w_dim) + bias;
66 
67  labels_dynarray->append_element(current_lab);
68  num_labels++;
69 
71  }
73 
74  SGVector<float64_t> labels_array(num_labels);
75  for (int32_t i=0; i<num_labels; i++)
76  labels_array.vector[i]=(*labels_dynarray)[i];
77 
78  delete labels_dynarray;
79  return labels_array;
80 }
81 
83 {
84  return SGVector<float32_t>::dot(vec, w, len)+bias;
85 }
86 
88 {
89  return features->dense_dot(w, w_dim)+bias;
90 }
91 
93 {
94  if (data)
95  {
96  if (!data->has_property(FP_STREAMING_DOT))
97  SG_ERROR("Specified features are not of type CStreamingDotFeatures\n")
99  }
100  start_train();
102  while (features->get_next_example())
103  {
106  }
107 
108  features->end_parser();
109  stop_train();
110 
111  return true;
112 }

SHOGUN Machine Learning Toolbox - Documentation