SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LinearMachine.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 
20  m_parameters->add_vector(&w, &w_dim, "w", "Parameter vector w.");
21  m_parameters->add(&bias, "bias", "Bias b.");
22  m_parameters->add((CSGObject**) &features, "features", "Feature object.");
23 
24 }
25 
27 {
28  SG_FREE(w);
30 }
31 
32 bool CLinearMachine::load(FILE* srcfile)
33 {
36  return false;
37 }
38 
39 bool CLinearMachine::save(FILE* dstfile)
40 {
43  return false;
44 }
45 
47 {
48  if (!features)
49  return NULL;
50 
51  int32_t num=features->get_num_vectors();
52  ASSERT(num>0);
54 
55  float64_t* out=SG_MALLOC(float64_t, num);
56  features->dense_dot_range(out, 0, num, NULL, w, w_dim, bias);
57 
58  return new CLabels(SGVector<float64_t>(out,num));
59 }
60 
62 {
63  if (!data)
64  SG_ERROR("No features specified\n");
65  if (!data->has_property(FP_DOT))
66  SG_ERROR("Specified features are not of type CDotFeatures\n");
67  set_features((CDotFeatures*) data);
68  return apply();
69 }

SHOGUN Machine Learning Toolbox - Documentation