SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GradientEvaluation.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) 2013 Roman Votyakov
8  * Copyright (C) 2012 Jacob Walker
9  */
10 
13 
14 using namespace shogun;
15 
17 {
18  init();
19 }
20 
22  CLabels* labels, CEvaluation* evaluation_crit, bool autolock) :
23  CMachineEvaluation(machine, features, labels, NULL, evaluation_crit, autolock)
24 {
25  init();
26 }
27 
28 void CGradientEvaluation::init()
29 {
30  m_diff=NULL;
31  m_parameter_dictionary=NULL;
32 
33  SG_ADD((CSGObject**)&m_diff, "differentiable_function", "Differentiable "
34  "function", MS_AVAILABLE);
35 }
36 
38 {
39  SG_UNREF(m_diff);
40  SG_UNREF(m_parameter_dictionary);
41 }
42 
43 void CGradientEvaluation::update_parameter_dictionary()
44 {
45  SG_UNREF(m_parameter_dictionary);
46 
47  m_parameter_dictionary=new CMap<TParameter*, CSGObject*>();
48  m_diff->build_gradient_parameter_dictionary(m_parameter_dictionary);
49  SG_REF(m_parameter_dictionary);
50 }
51 
53 {
55  update_parameter_dictionary();
56 
57  // create gradient result object
58  CGradientResult* result=new CGradientResult();
59  SG_REF(result);
60 
61  // set function value
62  result->set_value(m_diff->get_value());
63 
65  m_parameter_dictionary);
66 
67  // set gradient and parameter dictionary
68  result->set_gradient(gradient);
69  result->set_paramter_dictionary(m_parameter_dictionary);
70 
71  SG_UNREF(gradient);
72 
74 
75  return result;
76 }
virtual void update_parameter_hash()
Definition: SGObject.cpp:250
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual SGVector< float64_t > get_value()=0
virtual void set_value(SGVector< float64_t > value)
virtual CMap< TParameter *, SGVector< float64_t > > * get_gradient(CMap< TParameter *, CSGObject * > *parameters)=0
#define SG_REF(x)
Definition: SGObject.h:51
A generic learning machine interface.
Definition: Machine.h:143
virtual void set_gradient(CMap< TParameter *, SGVector< float64_t > > *gradient)
virtual CEvaluationResult * evaluate()
virtual void set_paramter_dictionary(CMap< TParameter *, CSGObject * > *parameter_dictionary)
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
void build_gradient_parameter_dictionary(CMap< TParameter *, CSGObject * > *dict)
Definition: SGObject.cpp:1244
Abstract class that contains the result generated by the MachineEvaluation class. ...
Machine Evaluation is an abstract class that evaluates a machine according to some criterion...
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
Container class that returns results from GradientEvaluation. It contains the function value as well ...
The class Features is the base class of all feature objects.
Definition: Features.h:68
#define SG_ADD(...)
Definition: SGObject.h:81
virtual bool parameter_hash_changed()
Definition: SGObject.cpp:264
Class Evaluation, a base class for other classes used to evaluate labels, e.g. accuracy of classifica...
Definition: Evaluation.h:40
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
Definition: SGObject.h:36

SHOGUN Machine Learning Toolbox - Documentation