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 CGRADIENTMODELSELECTION_H_ 00011 #define CGRADIENTMODELSELECTION_H_ 00012 00013 #include <shogun/modelselection/ParameterCombination.h> 00014 #include <shogun/modelselection/ModelSelection.h> 00015 #include <shogun/base/DynArray.h> 00016 #include <shogun/evaluation/GradientResult.h> 00017 00018 00019 namespace shogun 00020 { 00021 00026 class CGradientModelSelection: public CModelSelection 00027 { 00028 00029 public: 00030 00035 CGradientModelSelection(CModelSelectionParameters* model_parameters, 00036 CMachineEvaluation* machine_eval); 00037 00039 CGradientModelSelection(); 00040 00042 virtual ~CGradientModelSelection(); 00043 00050 virtual CParameterCombination* select_model(bool print_state=false); 00051 00057 virtual const char* get_name() const {return "GradientModelSelection";} 00058 00063 void set_max_evaluations(int m) {m_max_evaluations = m;} 00064 00069 int get_max_evaluations() {return m_max_evaluations;} 00070 00076 void set_grad_tolerance(float64_t t) {m_grad_tolerance = t;} 00077 00083 float64_t get_grad_tolerance() {return m_grad_tolerance;} 00084 00085 private: 00086 00101 static double nlopt_function(unsigned n, const double *x, double *grad, 00102 void *func_data); 00103 00104 void test_gradients(); 00105 00107 void init(); 00108 00109 protected: 00110 00113 struct nlopt_package 00114 { 00116 shogun::CMachineEvaluation* m_machine_eval; 00117 00119 shogun::CParameterCombination* m_current_combination; 00120 00122 bool print_state; 00123 }; 00124 00126 int m_max_evaluations; 00127 00129 float64_t m_grad_tolerance; 00130 00132 CParameterCombination* m_current_combination; 00133 00134 }; 00135 00136 } 00137 00138 #endif /* CGRADIENTMODELSELECTION_H_ */