Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

gnn_criterion.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *  @file gnn_criterion.h
00003  *  @brief Basic Structure for Criterions.
00004  *
00005  *  @date   : 24-08-03 19:28
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_CRITERION_H_
00026 #define _GNN_CRITERION_H_
00027 
00028 /******************************************/
00029 /* Include Files                          */
00030 /******************************************/
00031 
00032 #include "gnn_globals.h"
00033 
00034 
00035 
00036 /******************************************/
00037 /* Typedefs                               */
00038 /******************************************/
00039 
00040 /**
00041  * @brief The datatype for criterions.
00042  * @ingroup gnn_criterion_doc
00043  *
00044  * This is the datatype on which all implementations of criterions build on.
00045  * It basically contains buffers for intermediate values and three pointers
00046  * for the criterion's methods.
00047  */
00048 typedef struct _gnn_criterion gnn_criterion;
00049 
00050 /**
00051  * @brief The datatype for criterions evaluation functions.
00052  * @ingroup gnn_criterion_doc
00053  *
00054  * This datatype defines the form for \ref gnn_criterion's evaluation functions.
00055  * It takes a pointer to the current criterion, the vectors \f$y\f$ (model
00056  * output/estimation) and \f$t\f$ (desired target value). The function should
00057  * return a real value (double) that provides an adecuate optimization
00058  * criterion. Remember that \ref gnn_trainer's minimize the criterions.
00059  */
00060 typedef double (*gnn_criterion_e) (gnn_criterion *crit,
00061                                    const gsl_vector *y,
00062                                    const gsl_vector *t);
00063 
00064 /**
00065  * @brief The datatype for \f$\frac{\partial E}{\partial y}\f$.
00066  * @ingroup gnn_criterion_doc
00067  *
00068  * This datatype defines the form for \ref gnn_criterion's
00069  * \f$\frac{\partial E}{\partial y}\f$ gradient evaluation functions.
00070  * It takes a pointer to the current criterion, the vectors \f$y\f$ (model
00071  * output/estimation) and \f$t\f$ (desired target value). The function should
00072  * ADD the resulting gradient onto the values stored in the buffer pointed
00073  * by "dy".
00074  */
00075 typedef int (*gnn_criterion_dy) (gnn_criterion *crit,
00076                                  const gsl_vector *y,
00077                                  const gsl_vector *t,
00078                                  gsl_vector * dy);
00079 
00080 /**
00081  * @brief The datatype for destructors for criterion extensions.
00082  * @ingroup gnn_criterion_doc
00083  *
00084  * This datatype defines the form for \ref gnn_criterion's destructors.
00085  * If your specific implementation of a \ref gnn_criterion has additional
00086  * resources, then they (and nothing else) should be freed by this function,
00087  * and then return.
00088  */
00089 typedef void (*gnn_criterion_destructor) (gnn_criterion *crit);
00090 
00091 struct _gnn_criterion
00092 {
00093     const char      *type;    /**< The criterion's type.                     */
00094     size_t           m;       /**< The size \f$m\f$ of the estimaton and the
00095                                    target vectors \f$y\f$ and \f$t\f$.       */
00096 
00097     const gsl_vector *y;      /**< Pointer to the last evaluated output.     */
00098     const gsl_vector *t;      /**< Pointer to the last evaluated target.     */
00099 
00100     gnn_criterion_e  e;               /**< Pointer to the criterion
00101                                            evaluation function.              */
00102     gnn_criterion_dy dy;              /**< Pointer to the gradient
00103                                            evaluation function.              */
00104     gnn_criterion_destructor destroy; /**< Pointer to the criterion
00105                                            destructor function.              */
00106 };
00107 
00108 
00109 
00110 /******************************************/
00111 /* Public Interface                       */
00112 /******************************************/
00113 
00114 int
00115 gnn_criterion_init (gnn_criterion *crit,
00116                     const char    *type,
00117                     size_t         size,
00118                     gnn_criterion_e          e,
00119                     gnn_criterion_dy         dy,
00120                     gnn_criterion_destructor destroy);
00121 
00122 size_t
00123 gnn_criterion_get_size (gnn_criterion *crit);
00124 
00125 const char *
00126 gnn_criterion_get_type (gnn_criterion *crit);
00127 
00128 double
00129 gnn_criterion_evaluate_e (gnn_criterion *crit,
00130                           const gsl_vector *y,
00131                           const gsl_vector *t);
00132 
00133 int
00134 gnn_criterion_evaluate_dy (gnn_criterion *crit,
00135                            gsl_vector *dy);
00136 
00137 void
00138 gnn_criterion_destroy (gnn_criterion *crit);
00139 
00140 int
00141 gnn_criterion_eval_dy (gnn_criterion *crit,
00142                        gsl_vector *dy);
00143 
00144 
00145 
00146 #endif /* _GNN_CRITERION_H_ */
00147 
00148 
00149 

Generated on Sun Jun 13 20:50:11 2004 for libgnn Gradient Retropropagation Machine Library by doxygen1.2.18