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

gnn_node.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *  @file  gnn_node.h
00003  *  @brief gnn_node Header File.
00004  *
00005  *  @date   : 11-08-03 22:45
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_NODE_H_
00026 #define _GNN_NODE_H_
00027 
00028 /******************************************/
00029 /* Include Files                          */
00030 /******************************************/
00031 
00032 #include "gnn_pbundle.h"
00033 
00034 
00035 
00036 /******************************************/
00037 /* Macros                                 */
00038 /******************************************/
00039 
00040 #define GNN_NODE_SUB_INSTALL(_node_, _size_, _status_)            \
00041 {                                                                 \
00042     va_list args;                                                 \
00043     va_start(args, (_size_));                                     \
00044     (_status_) = gnn_node_sub_install ((_node_), (_size_), args); \
00045     va_end(args);                                                 \
00046 }
00047 
00048 
00049 
00050 /******************************************/
00051 /* Typedefs                               */
00052 /******************************************/
00053 
00054 /**
00055  * @brief   gnn_node type definition.
00056  * @ingroup gnn_node_ext
00057  *
00058  * The gnn_node C type for \ref libgnn node implementations.
00059  */
00060 typedef struct _gnn_node gnn_node;
00061 
00062 /**
00063  * @brief gnn_node_f type definition.
00064  * @ingroup gnn_node_ext
00065  *
00066  * This is the type for gnn_node's evaluation functions.
00067  * An example function is:
00068  * \code
00069  * int my_func (gnn_node *node,
00070  *              const gsl_vector *x,
00071  *              const gsl_vector *w,
00072  *              gsl_vector *y)
00073  * {
00074  *     // function implementation
00075  *     ...
00076  * }
00077  * \endcode
00078  */
00079 typedef int
00080         (*gnn_node_f) (gnn_node         *node,
00081                        const gsl_vector *x,
00082                        const gsl_vector *w,
00083                        gsl_vector *y);
00084 
00085 /**
00086  * @brief gnn_node_df type definition.
00087  * @ingroup gnn_node_ext
00088  *
00089  * This is the type for gnn_node's evaluation function gradients.
00090  * An example function is:
00091  * \code
00092  * int my_func_gradient (gnn_node *node,
00093  *                       const gsl_vector *x,
00094  *                       const gsl_vector *w,
00095  *                       const gsl_vector *dy,
00096  *                       gsl_vector       *dw);
00097  * {
00098  *     // function implementation
00099  *     ...
00100  * }
00101  * \endcode
00102  */
00103 typedef int
00104         (*gnn_node_df) (gnn_node         *node,
00105                         const gsl_vector *x,
00106                         const gsl_vector *w,
00107                         const gsl_vector *dy,
00108                         gsl_vector       *dxw);
00109 
00110 /**
00111  * @brief gnn_node_destructor type definition.
00112  * @ingroup gnn_node_ext
00113  *
00114  * This is the type for gnn_node's destroy functions.
00115  * An example function is:
00116  * \code
00117  * void
00118  * my_destroy (gnn_node *node)
00119  * {
00120  *     // function implementation
00121  *     ...
00122  * }
00123  * \endcode
00124  */
00125 typedef void
00126         (*gnn_node_destructor) (gnn_node *layer);
00127 
00128 /**
00129  * @brief   gnn_node Fundamental Structure.
00130  * @ingroup gnn_node_ext
00131  *
00132  * This structure holds the information for a node.
00133  *
00134  * - type: This is a string that holds the name of the node's type.
00135  *         It allows to check a node's type at runtime.
00136  * - n: The size of the input vector \f$x\f$.
00137  * - m: The size of the output vector \f$y\f$.
00138  * - whnd: The node's own parameter handle.
00139  * - whnds: This is a NULL-terminated array of \ref gnn_whnd parameter
00140  *          handles. Every handle appears at most 1 time (i.e.
00141  *          there aren't any handles pointing to the same parameters).
00142  * - x: A pointer to the last evaluated input vector \f$x\f$.
00143  * - destroy: A pointer to the node's destructor, which is invoked
00144  *            when called the \ref gnn_node_destroy function. It should
00145  *            free the additional memory allocated for the specific node type.
00146  * - f: A pointer to the evaluation function, which is called upon execution
00147  *      of \ref gnn_node_eval_f.
00148  * - dw: A pointer to the gradient with respect to its parameters
00149  *       \f$\frac{\partial E}{\partial w_l}\f$, which is called upon execution
00150  *       of \ref gnn_node_eval_dw.
00151  * - dx: A pointer to the gradient with respect to its inputs
00152  *       \f$\frac{\partial E}{\partial x_i}\f$, which is called upon execution
00153  *       of \ref gnn_node_eval_dw.
00154  * - super: A pointer to it's parent node (super), or NULL if the node is
00155  *          the root of the function tree.
00156  * - nsub: The number of children (subnodes) of the current node.
00157  * - sub: An array of pointer of size (nsub) with pointers to the current
00158  *        node's subnodes.
00159  */
00160 struct _gnn_node
00161 {
00162     const char       *type;         /**< The layer's type.                   */
00163     int               n;            /**< The layer's input size \f$n\f$.     */
00164     int               m;            /**< The layer's output size \f$m\f$.    */
00165     
00166     gnn_phandle      *ph;           /**< Pointer to the parameter handle.    */
00167     gnn_pbundle      *pb;           /**< Parameter bundle.                   */
00168 
00169     gsl_vector  x;                  /**< Last input. */
00170     gsl_vector  dy;                 /**< Last dy.    */
00171 
00172     gnn_node_destructor destroy;    /**< Destroy function pointer */
00173     gnn_node_f        f;            /**< Evaluation function \f$F\f$ pointer */
00174     gnn_node_df       dw;           /**< \f$\frac{\partial E}{\partial W}\f$
00175                                          function pointer                    */
00176     gnn_node_df       dx;           /**< \f$\frac{\partial E}{\partial W}\f$
00177                                          function pointer                    */
00178                                          
00179     gnn_node         *super;        /**< Pointer to the supernode.           */
00180     int               nsub;         /**< Number of subnodes.                 */
00181     gnn_node        **sub;          /**< Pointer to the subnode array.       */
00182 };
00183 
00184 
00185 
00186 /******************************************/
00187 /* External Typedefs                      */
00188 /******************************************/
00189 
00190 #ifndef _GNN_NODE_VECTOR_H_
00191     #include "gnn_node_vector.h"
00192 #endif
00193 
00194 
00195 
00196 /******************************************/
00197 /* Public Interface                       */
00198 /******************************************/
00199 
00200 /*************/
00201 /* Basic API */
00202 /*************/
00203 
00204 int
00205 gnn_node_is_root (gnn_node *node);
00206 
00207 const char *
00208 gnn_node_get_type_name (gnn_node *node);
00209 
00210 int
00211 gnn_node_input_get_size (gnn_node *node);
00212 
00213 int
00214 gnn_node_output_get_size (gnn_node *node);
00215 
00216 int
00217 gnn_node_destroy (gnn_node *node);
00218 
00219 int
00220 gnn_node_evaluate_init (gnn_node *node);
00221 
00222 int
00223 gnn_node_evaluate_f (gnn_node         *node,
00224                      const gsl_vector *x,
00225                      gsl_vector       *y);
00226 
00227 int
00228 gnn_node_evaluate_dx (gnn_node         *node,
00229                       const gsl_vector *dy,
00230                       gsl_vector       *dx);
00231 
00232 int
00233 gnn_node_evaluate_dw (gnn_node         *node,
00234                       gsl_vector       *dw);
00235 
00236 
00237 
00238 /*****************/
00239 /* Parameter API */
00240 /*****************/
00241 
00242 int
00243 gnn_node_param_get_size (gnn_node *node);
00244 
00245 int
00246 gnn_node_param_get (gnn_node *node, gsl_vector *w);
00247 
00248 int
00249 gnn_node_param_set (gnn_node *node, const gsl_vector *w);
00250 
00251 int
00252 gnn_node_param_freeze_flags_get (gnn_node *node, gsl_vector_int *f);
00253 
00254 int
00255 gnn_node_param_freeze_flags_set (gnn_node *node, const gsl_vector_int *f);
00256 
00257 int
00258 gnn_node_param_freeze (gnn_node *node, int i);
00259 
00260 int
00261 gnn_node_param_unfreeze (gnn_node *node, int i);
00262 
00263 int
00264 gnn_node_param_is_frozen (gnn_node *node, int i);
00265 
00266 int
00267 gnn_node_param_are_frozen (gnn_node *node);
00268 
00269 int
00270 gnn_node_param_freeze_all (gnn_node *node);
00271 
00272 int
00273 gnn_node_param_unfreeze_all (gnn_node *node);
00274 
00275 int
00276 gnn_node_param_share (const gnn_node *node, gnn_node *client);
00277 
00278 
00279 
00280 /*****************/
00281 /* Extension API */
00282 /*****************/
00283 
00284 int
00285 gnn_node_init (gnn_node           *node,
00286                const char         *type,
00287                gnn_node_f          f,
00288                gnn_node_df         dx,
00289                gnn_node_df         dw,
00290                gnn_node_destructor dest);
00291 
00292 int
00293 gnn_node_set_sizes (gnn_node *node, int n, int m, int l);
00294 
00295 gsl_vector *
00296 gnn_node_local_get_w (gnn_node *node);
00297 
00298 gsl_vector *
00299 gnn_node_local_get_dw (gnn_node *node);
00300 
00301 gsl_vector_int *
00302 gnn_node_local_get_f (gnn_node *node);
00303 
00304 int
00305 gnn_node_local_update (gnn_node *node);
00306 
00307 int
00308 gnn_node_eval_f (gnn_node *node, const gsl_vector *x, gsl_vector *y);
00309 
00310 int
00311 gnn_node_eval_dx (gnn_node *node, const gsl_vector *dy, gsl_vector *dx);
00312 
00313 int
00314 gnn_node_eval_dw (gnn_node *node);
00315 
00316 
00317 
00318 /****************/
00319 /* Subnode API  */
00320 /****************/
00321 
00322 int
00323 gnn_node_sub_install_specific (gnn_node *node, int nsub, ...);
00324 
00325 int
00326 gnn_node_sub_install (gnn_node *node, int nsub, va_list subs);
00327 
00328 int
00329 gnn_node_sub_install_node_vector (gnn_node *node, gnn_node_vector *vector);
00330 
00331 int
00332 gnn_node_sub_get_number (gnn_node *node);
00333 
00334 gnn_node *
00335 gnn_node_sub_get_node_at (gnn_node *node, int i);
00336 
00337 gnn_pbundle *
00338 gnn_node_sub_search_params (gnn_node *node, const char *type);
00339 
00340 
00341 
00342 #endif /* _GNN_NODE_H_ */

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