SHOGUN
v2.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
evaluation
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
10
#include <
shogun/evaluation/GradientEvaluation.h
>
11
#include <
shogun/evaluation/GradientResult.h
>
12
#include <
shogun/evaluation/Evaluation.h
>
13
#include <
shogun/evaluation/EvaluationResult.h
>
14
15
16
using namespace
shogun;
17
18
CGradientEvaluation::CGradientEvaluation
() :
CMachineEvaluation
(NULL,
19
NULL, NULL, NULL, NULL, true)
20
{
21
22
}
23
24
CGradientEvaluation::CGradientEvaluation
(
CMachine
* machine,
CFeatures
* features,
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
39
CGradientEvaluation::~CGradientEvaluation
()
40
{
41
SG_UNREF
(m_diff);
42
}
43
44
CEvaluationResult
*
CGradientEvaluation::evaluate
()
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