SHOGUN
v2.0.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Copyright (C) 2012 Jacob Walker 00008 */ 00009 00010 #include <shogun/evaluation/GradientEvaluation.h> 00011 #include <shogun/evaluation/GradientResult.h> 00012 #include <shogun/evaluation/Evaluation.h> 00013 #include <shogun/evaluation/EvaluationResult.h> 00014 00015 00016 using namespace shogun; 00017 00018 CGradientEvaluation::CGradientEvaluation() : CMachineEvaluation(NULL, 00019 NULL, NULL, NULL, NULL, true) 00020 { 00021 00022 } 00023 00024 CGradientEvaluation::CGradientEvaluation(CMachine* machine, CFeatures* features, 00025 CLabels* labels, CEvaluation* evaluation_crit, bool autolock) : 00026 CMachineEvaluation(machine, features, labels, NULL, evaluation_crit, true) 00027 { 00028 init(); 00029 } 00030 00031 void CGradientEvaluation::init() 00032 { 00033 m_diff = NULL; 00034 00035 SG_ADD((CSGObject**)&m_diff, "differentiable_function", 00036 "Differentiable Function", MS_NOT_AVAILABLE); 00037 } 00038 00039 CGradientEvaluation::~CGradientEvaluation() 00040 { 00041 SG_UNREF(m_diff); 00042 } 00043 00044 CEvaluationResult* CGradientEvaluation::evaluate() 00045 { 00046 CGradientResult* result = new CGradientResult(); 00047 00048 SGVector<float64_t> quan = m_diff->get_quantity(); 00049 00050 result->gradient = m_diff->get_gradient(result->parameter_dictionary); 00051 00052 result->quantity = quan.clone(); 00053 00054 result->total_variables = 0; 00055 00056 for (index_t i = 0; i < result->gradient.get_num_elements(); i++) 00057 { 00058 shogun::CMapNode<TParameter*, SGVector<float64_t> >* node = 00059 result->gradient.get_node_ptr(i); 00060 00061 result->total_variables += node->data.vlen; 00062 } 00063 00064 00065 SG_REF(result); 00066 return result; 00067 } 00068