00001 /*************************************************************************** 00002 * @file gnn_bfgs.h 00003 * @brief gnn_bfgs Header File. 00004 * 00005 * @date : 05-10-03 01:05 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_BFGS_H_ 00026 #define _GNN_BFGS_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_bfgs_doc 00046 * 00047 * This constant defines the tolerance for the line search procedure used by 00048 * the conjugate gradients algorithm. 00049 */ 00050 #define GNN_BFGS_TOL 0.0001 00051 00052 /** 00053 * @brief Default bracketing step taken by the line search procedures. 00054 * @ingroup gnn_bfgs_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_BFGS_STEP 0.1 00060 00061 /** 00062 * @brief Default restart. 00063 * @ingroup gnn_bfgs_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_BFGS_RESTART 100 00069 00070 /** 00071 * @brief Default line search procedure. 00072 * @ingroup gnn_bfgs_doc 00073 * 00074 * This is the default line search procedure used by the conjugate gradients 00075 * algorithm. 00076 */ 00077 #define GNN_BFGS_ALPHA gnn_line_search_brent 00078 00079 /** 00080 * @brief Type for \f$\beta\f$ evaluation procedures. 00081 * @ingroup gnn_bfgs_doc 00082 * 00083 * This type defines the form of the procedures for computing the \f$\beta\f$ 00084 * coefficient used by the conjugate gradients method. 00085 */ 00086 typedef double (*gnn_bfgs_beta) (gnn_trainer *trainer); 00087 00088 /** 00089 * @brief Conjugate gradients trainer structure. 00090 * @ingroup gnn_bfgs_doc 00091 * 00092 * This type extends the basic \ref gnn_trainer structure for the conjugate 00093 * gradients trainer. 00094 */ 00095 typedef struct _gnn_bfgs gnn_bfgs; 00096 00097 struct _gnn_bfgs 00098 { 00099 gnn_trainer trainer; 00100 gsl_vector *wnew; /**< new parameter vector */ 00101 gsl_vector *wold; /**< old parameter vector */ 00102 gsl_vector *gnew; /**< new gradient vector */ 00103 gsl_vector *gold; /**< old gradient vector */ 00104 gsl_vector *u; /**< auxiliary vector */ 00105 gsl_vector *v; /**< auxiliary vector */ 00106 gsl_vector *p; /**< auxiliary vector */ 00107 gsl_vector *q; /**< auxiliary vector */ 00108 gsl_matrix *G; /**< inverse Hessian approximation */ 00109 00110 gsl_matrix_view Uview; /**< matrix view of auxiliary vector */ 00111 gsl_matrix_view Vview; /**< matrix view of auxiliary vector */ 00112 gsl_matrix_view Pview; /**< matrix view of auxiliary vector */ 00113 gsl_matrix_view Qview; /**< matrix view of auxiliary vector */ 00114 gsl_matrix *U; /**< matrix pointer to auxiliary vector */ 00115 gsl_matrix *V; /**< matrix pointer to auxiliary vector */ 00116 gsl_matrix *P; /**< matrix pointer to auxiliary vector */ 00117 gsl_matrix *Q; /**< matrix pointer to auxiliary vector */ 00118 00119 gnn_line *line; /**< line search buffers */ 00120 00121 gnn_line_search_type alpha; /**< line search procedure */ 00122 00123 double step; /**< Initial step taken to bracket search interval */ 00124 double tol; /**< Required precision for line search procedure */ 00125 00126 size_t iteration; /**< Number of the current iteration */ 00127 size_t restart; /**< Number of iterations required to restart */ 00128 }; 00129 00130 00131 00132 /******************************************/ 00133 /* Public Interface */ 00134 /******************************************/ 00135 00136 gnn_trainer * 00137 gnn_bfgs_new (gnn_node *node, gnn_criterion *crit, gnn_dataset *data); 00138 00139 int 00140 gnn_bfgs_set_tol (gnn_trainer *trainer, double tol); 00141 00142 double 00143 gnn_bfgs_get_tol (gnn_trainer *trainer); 00144 00145 int 00146 gnn_bfgs_set_step (gnn_trainer *trainer, double step); 00147 00148 double 00149 gnn_bfgs_get_step (gnn_trainer *trainer); 00150 00151 int 00152 gnn_bfgs_set_restart (gnn_trainer *trainer, size_t restart); 00153 00154 size_t 00155 gnn_bfgs_get_restart (gnn_trainer *trainer); 00156 00157 int 00158 gnn_bfgs_set_line_search (gnn_trainer *trainer, 00159 gnn_line_search_type lsearch); 00160 00161 gnn_line_search_type 00162 gnn_bfgs_get_alpha (gnn_trainer *trainer); 00163 00164 00165 00166 #endif /* _GNN_BFGS_H_ */ 00167 00168 00169
1.2.18