A criterion is a special structure used for measuring the quality of a given model. It implements a function
that takes two input vectors
and
as arguments, and computes a cost value
that should be minimized during training.
Normally,
measures the error or distance between the vectors
and
. This is important, because when modelling, the aim is to minimize the error of the Model, that is, the estimation
should be similar to the desired output
.
In order to use the criterion during training, which is almost always an optimization process which uses the gradient
, the function's gradient with respect to
, that is,
, should be available.
libgnn provides a common structure for criterions with the gnn_criterion : Basic Criterion Function. and its associated functions. The gnn_criterion : Basic Criterion Function. data type is a generic structure, which needs to be extended in order to be usable. Basically, the structure should be equipped with an evaluation function and a gradient evaluation function.
To create a new criterion, you have two options:
gnn_criterion *crit; crit = gnn_mean_square_new (10);
All criterion conform to a common interface, which is:
and a target
.
for the last evaluated
and
vectors.The 3 specific functions are of the following types:
and
.
Another different form of a gnn_criterion : Basic Criterion Function. is a regularizator. It performs a regularization of the error function, in the form:
where
is an error criterion, called the "subcriterion" in libgnn, and
is a regularization term. The scalar
is called the regularization coefficient, which determines the extent in which the regularization term affects the overall resulting error
. Regularization do limit the gnn_node's function complexity in order to perform better in generalization. A regularization term usually penalizes the curvature of the output mapping. Some of them (e.g. Weight Decay) depend directly on the values of the function's parameters. They do coexist with a gnn_criterion : Basic Criterion Function., and need an error function upon construction.
Modules | |
| gnn_cross_entropy : Cross-Entropy Error Criterion. | |
| Cross Entropy Error function. | |
| gnn_mse : Mean-Square-Error Criterion. | |
| Mean Square Error function. | |
| gnn_msre : Mean-Square-Relative-Error Criterion. | |
| Mean Square Relative Error function. | |
| gnn_weight_decay : Weight Decay Regularization. | |
| Weight Decay Regularization. | |
| gnn_weight_elimination : Weight Elimination Regularization. | |
| Weight Elimination Regularization. | |
Typedefs | |
| typedef _gnn_criterion | gnn_criterion |
| The datatype for criterions. | |
| typedef double(* | gnn_criterion_e )(gnn_criterion *crit, const gsl_vector *y, const gsl_vector *t) |
| The datatype for criterions evaluation functions. | |
| typedef int(* | gnn_criterion_dy )(gnn_criterion *crit, const gsl_vector *y, const gsl_vector *t, gsl_vector *dy) |
The datatype for
. | |
| typedef void(* | gnn_criterion_destructor )(gnn_criterion *crit) |
| The datatype for destructors for criterion extensions. | |
Functions | |
| int | gnn_criterion_init (gnn_criterion *crit, const char *type, size_t size, gnn_criterion_e e, gnn_criterion_dy dy, gnn_criterion_destructor destroy) |
| Initializes a gnn_criterion : Basic Criterion Function.. | |
| size_t | gnn_criterion_get_size (gnn_criterion *crit) |
| Returns a criterion's size. | |
| const char * | gnn_criterion_get_type (gnn_criterion *crit) |
| Returns the name of the criterion. | |
| double | gnn_criterion_evaluate_e (gnn_criterion *crit, const gsl_vector *y, const gsl_vector *t) |
| Evaluates the criterion. | |
| int | gnn_criterion_evaluate_dy (gnn_criterion *crit, gsl_vector *dy) |
| Evaluates the criterion's gradient. | |
| int | gnn_criterion_eval_dy (gnn_criterion *crit, gsl_vector *dy) |
| Evaluates the criterion's gradient. | |
| void | gnn_criterion_destroy (gnn_criterion *crit) |
| Destroys the criterion. | |
|
|
This is the datatype on which all implementations of criterions build on. It basically contains buffers for intermediate values and three pointers for the criterion's methods. Definition at line 48 of file gnn_criterion.h. |
|
|
This datatype defines the form for gnn_criterion : Basic Criterion Function.'s destructors. If your specific implementation of a gnn_criterion : Basic Criterion Function. has additional resources, then they (and nothing else) should be freed by this function, and then return. Definition at line 89 of file gnn_criterion.h. |
|
|
This datatype defines the form for gnn_criterion : Basic Criterion Function.'s Definition at line 75 of file gnn_criterion.h. |
|
|
This datatype defines the form for gnn_criterion : Basic Criterion Function.'s evaluation functions. It takes a pointer to the current criterion, the vectors Definition at line 60 of file gnn_criterion.h. |
|
|
This function destroys a given criterion structure by freeing its memory. It will call the specific destroy function (if any) for the criterion, which was previosly installed. Then it frees the fields of gnn_criterion : Basic Criterion Function. and the structure itself.
Definition at line 365 of file gnn_criterion.c. |
|
||||||||||||
|
This function evaluates the criterion's gradient with respect to the last evaluated estimation
This function calls the criterion's specific gradient function.
Definition at line 345 of file gnn_criterion.c. |
|
||||||||||||
|
This function evaluates the criterion's gradient with respect to the last evaluated estimation
Definition at line 309 of file gnn_criterion.c. |
|
||||||||||||||||
|
This function evaluates the criterion for the given vectors "y" and "t", which are (usually) the Models output It will call the specific evaluation function for the criterion, which was previosly installed.
Definition at line 279 of file gnn_criterion.c. |
|
|
This functions returns the size
Definition at line 237 of file gnn_criterion.c. |
|
|
This functions returns a string which identifies uniquely the current criterion's type.
Definition at line 255 of file gnn_criterion.c. |
|
||||||||||||||||||||||||||||
|
This function initializes a gnn_criterion : Basic Criterion Function. by setting its size and installing the specific functions for It is mandatory to provide:
In example, suppose you want to implement a criterion called "my_criterion" and that you have already coded the evaluation function and the gradient function, which you called "my_criterion_e" and "my_criterion_dy" respectivelly. Your criterion doesn't need any additional data to compute them, so you didn't extend the basic gnn_criterion : Basic Criterion Function.. Then, the code would be a template for the constructor: gnn_criterion * my_criterion_new (size_t size) { int status; gnn_criterion *crit; // allocate memory for the criterion crit = (gnn_criterion *) malloc (sizeof (gnn_criterion)); // initialize status = gnn_criterion_init (crit, "my criterion", size, my_criterion_e, my_criterion_dy, my_criterion_destroy); if (status) print_an_error_message_and_return_null (); // return return crit; }
Definition at line 181 of file gnn_criterion.c. |
1.2.18