SHOGUN  4.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>
15 
16 using namespace shogun;
17 
19 : CMachine(), w_dim(0), w(NULL), bias(0), features(NULL)
20 {
21  m_parameters->add_vector(&w, &w_dim, "w", "Parameter vector w.");
22  SG_ADD(&bias, "bias", "Bias b.", MS_NOT_AVAILABLE);
23  SG_ADD((CSGObject**) &features, "features",
24  "Feature object.", MS_NOT_AVAILABLE);
25 }
26 
28 {
29  // It is possible that a derived class may have already
30  // called SG_FREE() on the weight vector
31  if (w != NULL)
32  SG_FREE(w);
34 }
35 
37 {
38  SGVector<float64_t> outputs = apply_get_outputs(data);
39  return new CBinaryLabels(outputs);
40 }
41 
43 {
44  SGVector<float64_t> outputs = apply_get_outputs(data);
45  return new CRegressionLabels(outputs);
46 }
47 
49 {
50  if (data)
51  {
52  if (!data->has_property(FP_STREAMING_DOT))
53  SG_ERROR("Specified features are not of type CStreamingDotFeatures\n")
54 
56  }
57 
60 
61  DynArray<float64_t>* labels_dynarray=new DynArray<float64_t>();
62  int32_t num_labels=0;
63 
65  while (features->get_next_example())
66  {
67  float64_t current_lab=features->dense_dot(w, w_dim) + bias;
68 
69  labels_dynarray->append_element(current_lab);
70  num_labels++;
71 
73  }
75 
76  SGVector<float64_t> labels_array(num_labels);
77  for (int32_t i=0; i<num_labels; i++)
78  labels_array.vector[i]=(*labels_dynarray)[i];
79 
80  delete labels_dynarray;
81  return labels_array;
82 }
83 
85 {
86  return CMath::dot(vec, w, len)+bias;
87 }
88 
90 {
91  return features->dense_dot(w, w_dim)+bias;
92 }
93 
95 {
96  if (data)
97  {
98  if (!data->has_property(FP_STREAMING_DOT))
99  SG_ERROR("Specified features are not of type CStreamingDotFeatures\n")
101  }
102  start_train();
104  while (features->get_next_example())
105  {
108  }
109 
110  features->end_parser();
111  stop_train();
112 
113  return true;
114 }

SHOGUN Machine Learning Toolbox - Documentation