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 }
bool has_property(EFeatureProperty p)
Definition: Features.cpp:337
virtual void dense_dot_range(float64_t *output, int32_t start, int32_t stop, float64_t *alphas, float64_t *vec, int32_t dim, float64_t b)
Definition: DotFeatures.cpp:62
#define SG_RESET_LOCALE
Definition: SGIO.h:67
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:35
virtual int32_t get_num_vectors() const =0
#define SG_ERROR(...)
Definition: SGIO.h:75
Parameter * m_parameters
Definition: SGObject.h:297
Features that support dot products among other operations.
Definition: DotFeatures.h:41
#define SG_SET_LOCALE_C
Definition: SGIO.h:66
A generic learning machine interface.
Definition: Machine.h:96
virtual int32_t get_dim_feature_space() const =0
void add(bool *param, const char *name, const char *description="")
Definition: Parameter.cpp:23
#define ASSERT(x)
Definition: SGIO.h:102
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:76
virtual bool save(FILE *dstfile)
double float64_t
Definition: common.h:56
virtual bool load(FILE *srcfile)
#define SG_FREE(ptr)
Definition: memory.h:39
CDotFeatures * features
#define SG_UNREF(x)
Definition: SGObject.h:45
void add_vector(bool **param, index_t *length, const char *name, const char *description="")
Definition: Parameter.cpp:306
The class Features is the base class of all feature objects.
Definition: Features.h:56
virtual void set_features(CDotFeatures *feat)
virtual CLabels * apply()
#define SG_MALLOC(type, len)
Definition: memory.h:36

SHOGUN Machine Learning Toolbox - Documentation