SHOGUN  3.2.1
 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>
14 
15 using namespace shogun;
16 
18 : CMachine(), w_dim(0), w(NULL), bias(0), features(NULL)
19 {
20  m_parameters->add_vector(&w, &w_dim, "w", "Parameter vector w.");
21  SG_ADD(&bias, "bias", "Bias b.", MS_NOT_AVAILABLE);
22  SG_ADD((CSGObject**) &features, "features",
23  "Feature object.", MS_NOT_AVAILABLE);
24 }
25 
27 {
28  // It is possible that a derived class may have already
29  // called SG_FREE() on the weight vector
30  if (w != NULL)
31  SG_FREE(w);
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  DynArray<float64_t>* labels_dynarray=new DynArray<float64_t>();
61  int32_t num_labels=0;
62 
64  while (features->get_next_example())
65  {
66  float64_t current_lab=features->dense_dot(w, w_dim) + bias;
67 
68  labels_dynarray->append_element(current_lab);
69  num_labels++;
70 
72  }
74 
75  SGVector<float64_t> labels_array(num_labels);
76  for (int32_t i=0; i<num_labels; i++)
77  labels_array.vector[i]=(*labels_dynarray)[i];
78 
79  delete labels_dynarray;
80  return labels_array;
81 }
82 
84 {
85  return SGVector<float32_t>::dot(vec, w, len)+bias;
86 }
87 
89 {
90  return features->dense_dot(w, w_dim)+bias;
91 }
92 
94 {
95  if (data)
96  {
97  if (!data->has_property(FP_STREAMING_DOT))
98  SG_ERROR("Specified features are not of type CStreamingDotFeatures\n")
100  }
101  start_train();
103  while (features->get_next_example())
104  {
107  }
108 
109  features->end_parser();
110  stop_train();
111 
112  return true;
113 }

SHOGUN Machine Learning Toolbox - Documentation