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 #ifndef CGRADIENTRESULT_H_ 00011 #define CGRADIENTRESULT_H_ 00012 00013 #include <shogun/evaluation/EvaluationResult.h> 00014 #include <shogun/lib/Map.h> 00015 #include <shogun/lib/SGString.h> 00016 00017 namespace shogun 00018 { 00019 00025 class CGradientResult: public CEvaluationResult 00026 { 00027 00028 public: 00029 00030 /*Constructor*/ 00031 CGradientResult(); 00032 00033 /*Destructor*/ 00034 virtual ~CGradientResult(); 00035 00041 virtual const char* get_name() const 00042 { 00043 return "GradientResult"; 00044 } 00045 00051 virtual EEvaluationResultType get_result_type() 00052 { 00053 return GRADIENTEVALUATION_RESULT; 00054 } 00055 00057 SGVector<float64_t> quantity; 00058 00060 CMap<TParameter*, SGVector<float64_t> > gradient; 00061 00063 CMap<TParameter*, CSGObject*> parameter_dictionary; 00064 00066 index_t total_variables; 00067 00071 void print_result() 00072 { 00073 SG_SPRINT("Quantity: ["); 00074 00075 for (index_t i = 0; i < quantity.vlen; i++) 00076 SG_SPRINT("%f, ", quantity[i]); 00077 00078 SG_SPRINT("] "); 00079 00080 SG_SPRINT("Gradient: ["); 00081 00082 for (index_t i = 0; i < gradient.get_num_elements(); i++) 00083 { 00084 char* name = gradient.get_node_ptr(i)->key->m_name; 00085 for (index_t j = 0; j < gradient.get_element_ptr(i)->vlen; j++) 00086 SG_SPRINT("%s: %f, ", (*gradient.get_element_ptr(i))[j], name); 00087 } 00088 SG_SPRINT("]\n"); 00089 00090 SG_SPRINT("Total Variables: %i\n", total_variables); 00091 00092 } 00093 }; 00094 00095 } /* namespace shogun */ 00096 00097 #endif /* CGRADIENTRESULT_H_ */