SHOGUN  v2.0.0
 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  * Copyright (C) 2012 Jacob Walker
8  */
9 
14 
15 
16 using namespace shogun;
17 
19  NULL, NULL, NULL, NULL, true)
20 {
21 
22 }
23 
25  CLabels* labels, CEvaluation* evaluation_crit, bool autolock) :
26  CMachineEvaluation(machine, features, labels, NULL, evaluation_crit, true)
27 {
28  init();
29 }
30 
31 void CGradientEvaluation::init()
32 {
33  m_diff = NULL;
34 
35  SG_ADD((CSGObject**)&m_diff, "differentiable_function",
36  "Differentiable Function", MS_NOT_AVAILABLE);
37 }
38 
40 {
41  SG_UNREF(m_diff);
42 }
43 
45 {
46  CGradientResult* result = new CGradientResult();
47 
48  SGVector<float64_t> quan = m_diff->get_quantity();
49 
50  result->gradient = m_diff->get_gradient(result->parameter_dictionary);
51 
52  result->quantity = quan.clone();
53 
54  result->total_variables = 0;
55 
56  for (index_t i = 0; i < result->gradient.get_num_elements(); i++)
57  {
58  shogun::CMapNode<TParameter*, SGVector<float64_t> >* node =
59  result->gradient.get_node_ptr(i);
60 
61  result->total_variables += node->data.vlen;
62  }
63 
64 
65  SG_REF(result);
66  return result;
67 }
68 

SHOGUN Machine Learning Toolbox - Documentation