SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 }

SHOGUN Machine Learning Toolbox - Documentation