00001 /*************************************************************************** 00002 * @file gnn_conjugate_gradient.h 00003 * @brief Conjugate Gradient Trainer Header File. 00004 * 00005 * @date : 07-09-03 12:08, 13-09-03 18:41 00006 * @author : Pedro Ortega C. <peortega@dcc.uchile.cl> 00007 * Copyright 2003 Pedro Ortega C. 00008 ****************************************************************************/ 00009 /* 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00023 */ 00024 00025 #ifndef _GNN_CONJUGATE_GRADIENT_H_ 00026 #define _GNN_CONJUGATE_GRADIENT_H_ 00027 00028 00029 00030 /******************************************/ 00031 /* Include Files */ 00032 /******************************************/ 00033 00034 #include "gnn_line_search.h" 00035 #include "gnn_trainer.h" 00036 00037 00038 00039 /******************************************/ 00040 /* Typedefs and Definitions */ 00041 /******************************************/ 00042 00043 /** 00044 * @brief Default precision for line search procedures. 00045 * @ingroup gnn_conjugate_gradient_doc 00046 * 00047 * This constant defines the tolerance for the line search procedure used by 00048 * the conjugate gradients algorithm. 00049 */ 00050 #define GNN_CONJUGATE_GRADIENT_TOL 0.0001 00051 00052 /** 00053 * @brief Default bracketing step taken by the line search procedures. 00054 * @ingroup gnn_conjugate_gradient_doc 00055 * 00056 * This constant defines the initial step taken by the bracketing algorithm 00057 * to search the minimum along the line. 00058 */ 00059 #define GNN_CONJUGATE_GRADIENT_STEP 0.1 00060 00061 /** 00062 * @brief Default restart. 00063 * @ingroup gnn_conjugate_gradient_doc 00064 * 00065 * This constant defines the default number of iterations that the conjugate 00066 * gradients algorithm takes before restarting the algorithm. 00067 */ 00068 #define GNN_CONJUGATE_GRADIENT_RESTART 100 00069 00070 /** 00071 * @brief Default line search procedure. 00072 * @ingroup gnn_conjugate_gradient_doc 00073 * 00074 * This is the default line search procedure used by the conjugate gradients 00075 * algorithm. 00076 */ 00077 #define GNN_CONJUGATE_GRADIENT_ALPHA gnn_line_search_brent 00078 00079 /** 00080 * @brief Default \f$\beta\f$. 00081 * @ingroup gnn_conjugate_gradient_doc 00082 * 00083 * This defines the default method used for the \f$\beta\f$ parameter in the 00084 * conjugate gradients method. 00085 */ 00086 #define GNN_CONJUGATE_GRADIENT_BETA gnn_conjugate_gradient_polak_ribiere 00087 00088 /** 00089 * @brief Type for \f$\beta\f$ evaluation procedures. 00090 * @ingroup gnn_conjugate_gradient_doc 00091 * 00092 * This type defines the form of the procedures for computing the \f$\beta\f$ 00093 * coefficient used by the conjugate gradients method. 00094 */ 00095 typedef double (*gnn_conjugate_gradient_beta) (gnn_trainer *trainer); 00096 00097 /** 00098 * @brief Conjugate gradients trainer structure. 00099 * @ingroup gnn_conjugate_gradient_doc 00100 * 00101 * This type extends the basic \ref gnn_trainer structure for the conjugate 00102 * gradients trainer. 00103 */ 00104 typedef struct _gnn_conjugate_gradient gnn_conjugate_gradient; 00105 00106 struct _gnn_conjugate_gradient 00107 { 00108 gnn_trainer trainer; 00109 gsl_vector *gnew; /**< new gradient vector */ 00110 gsl_vector *gold; /**< old gradient vector */ 00111 gsl_vector *buf; /**< buffer for operations */ 00112 00113 gnn_line *line; /**< line search buffers */ 00114 00115 gnn_conjugate_gradient_beta beta; /**< \f$beta\f$ function */ 00116 gnn_line_search_type alpha; /**< line search procedure */ 00117 00118 double step; /**< Initial step taken to bracket search interval */ 00119 double tol; /**< Required precision for line search procedure */ 00120 00121 size_t iteration; /**< Number of the current iteration */ 00122 size_t restart; /**< Number of iterations required to restart */ 00123 }; 00124 00125 00126 00127 /******************************************/ 00128 /* Public Interface */ 00129 /******************************************/ 00130 00131 gnn_trainer * 00132 gnn_conjugate_gradient_new (gnn_node *node, 00133 gnn_criterion *crit, 00134 gnn_dataset *data); 00135 00136 double 00137 gnn_conjugate_gradient_polak_ribiere (gnn_trainer *trainer); 00138 00139 double 00140 gnn_conjugate_gradient_hestenes_stiefel (gnn_trainer *trainer); 00141 00142 double 00143 gnn_conjugate_gradient_fletcher_reeves (gnn_trainer *trainer); 00144 00145 00146 00147 int 00148 gnn_conjugate_gradient_set_tol (gnn_trainer *trainer, double tol); 00149 00150 double 00151 gnn_conjugate_gradient_get_tol (gnn_trainer *trainer); 00152 00153 int 00154 gnn_conjugate_gradient_set_step (gnn_trainer *trainer, double step); 00155 00156 double 00157 gnn_conjugate_gradient_get_step (gnn_trainer *trainer); 00158 00159 int 00160 gnn_conjugate_gradient_set_restart (gnn_trainer *trainer, size_t restart); 00161 00162 size_t 00163 gnn_conjugate_gradient_get_restart (gnn_trainer *trainer); 00164 00165 int 00166 gnn_conjugate_gradient_set_line_search (gnn_trainer *trainer, 00167 gnn_line_search_type lsearch); 00168 00169 gnn_line_search_type 00170 gnn_conjugate_gradient_get_alpha (gnn_trainer *trainer); 00171 00172 int 00173 gnn_conjugate_gradient_set_beta (gnn_trainer *trainer, 00174 gnn_conjugate_gradient_beta beta); 00175 00176 gnn_conjugate_gradient_beta 00177 gnn_conjugate_gradient_get_beta (gnn_trainer *trainer); 00178 00179 00180 #endif /* _GNN_CONJUGATE_GRADIENT_H_ */ 00181 00182 00183
1.2.18