The present module provides a high-level programming interface, where the 3 most frequent tasks have been packed into complex, but easy-to-use routines.
The API provides routines for the following tasks:
implemented by a particular gnn_node, take a set of input vectors
, and evaluate all (or some) outputs
for a fixed parameter vector
.
implemented by a particular gnn_node, an error criterion
implemented by a gnn_criterion : Basic Criterion Function. and a pattern set (or a subset of)
, evaluate the averaged error
, gradient
and gradient
.
, where
is a vector called the origin,
is a vector called the directional vector, and
is a scalar. Then, compute the averaged error
and the derivative along the given line
.Usually, you should call the evaluation functions giving them the needed buffers, and after then access the its fields in order to obtain the result using the provided macros and functions.
When an evaluation buffer is destroyed, its associated objects, like the gnn_node or gnn_crit used for its allocation, won't be destroyed. These should be deallocated separately. These three type of buffers do not own the associated gnn_node, gnn_dataset : Datasets for Training., and all required structures to build them. This means that these have to be destroyed separately.
Using gnn_eval.
The Evaluations. evaluation interface takes a given model, and a set of inputs, and computes the corresponding outputs.
Example use:
gnn_node *node; gnn_input *input; gnn_output *output; gnn_eval *eval; // Create the needed objects. node = my_new_custom_node (); input = my_new_custom_input (); output = my_new_custom_output (); // Allocate the evaluation buffer. eval = gnn_eval_new (node, input, output); // Compute all estimated outputs: the gnn_node evaluates each // input example and puts the results into the gnn_output. gnn_eval_all (eval); // Now, "output" contains the results. Do something with them. ... // Destroy buffer and objects. gnn_eval_destroy (eval); gnn_node_destroy (node); gnn_input_destroy (input); gnn_output_destroy (output);
Using gnn_grad.
The Evaluations. evaluation interface takes a given model, a criterion and a dataset, and computes the weighted sum of errors
, the weighted sum of the gradient with respect to the inputs
, or the weighted sum of the gradients with respect to the parameters
.
When calling one of the evaluation routines (that is, either by calling gnn_grad_pats or gnn_grad_all), you have to specify how far the computation should be performed. That's the purpose of the last flag parameter:
.
and
.
,
and
.Example use:
double E; gsl_vector *Dx; gnn_node *node; gnn_criterion *crit; gnn_dataset *data; gnn_grad *grad; // Create the needed objects. node = my_new_custom_node (); crit = my_new_custom_criterion (); data = my_new_custom_dataset (); // Allocate the gradient evaluation buffer. grad = gnn_grad_new (node, crit, data); // In this example, we need to compute the gradient with respect // to the inputs. So we will execute the evaluation routine with the // "gnnGradDx" flag. gnn_grad_all (grad, gnnGradDx); // We can retrieve the results now by using the macros. // First, get the weighted error which was also computed. E = GNN_GRAD_E (grad); // Now, get the gradient. First allocate a vector were to store the // result, and then use the macro to access the buffer's internal // Dx vector. Dx = gsl_vector_alloc (GNN_GRAD_INPUT_SIZE (grad)); gsl_vector_memcpy (Dx, GNN_GRAD_DX (grad)); // Do something else here... ... // Destroy buffer and objects. gnn_grad_destroy (grad); gnn_node_destroy (node); gnn_criterion_destroy (crit); gnn_dataset_destroy (data);
Using gnn_line.
The Evaluations. evaluation interface takes an already built Evaluations. buffer plus a direction, and computes the error or the error derivative along the given line.
When calling one of the evaluation routines (that is, either by calling gnn_line_pats or gnn_line_all), you have to specify how far the computation should be performed. That's the purpose of the last flag parameter:
.
and
.Example use:
double E; double DE; gsl_vector *d; gnn_grad *grad; gnn_line *line; // Create the needed objects. grad = my_new_custom_grad (); // In this example, we want to compute the error derivative along // the first parameter. So we have to prepare the corresponding // directional vector. d = gsl_vector_calloc (GNN_GRAD_PARAMETER_SIZE (grad)); gsl_vector_set (d, 0, 1.0); // Allocate the line evaluation buffer. line = gnn_line_new (grad, d); // We have to execute the evaluation routine with the "gnnLineDE" // flag in order to get the derivative computed. gnn_line_all (line, 0.0, gnnLineDE); // Get the results by using the macros. E = GNN_LINE_E (line); DE = GNN_LINE_DE (line); // Of course, the evaluation can be performed at another point which // can be more convenient for the application. gnn_line_all (line, 1.0, gnnLineDE); ... // Do something else here... ... // Destroy buffer and objects. gnn_line_destroy (line); gnn_node_destroy (GNN_GRAD_GET_NODE (grad)); gnn_criterion_destroy (GNN_GRAD_GET_CRITERION (grad)); gnn_dataset_destroy (GNN_GRAD_GET_DATASET (grad)); gnn_grad_destroy (grad);
Defines | |
| #define | GNN_EVAL_GET_NODE(eval) ((eval)->node) |
| Returns a pointer to the associated gnn_node. | |
| #define | GNN_EVAL_GET_INPUT(eval) ((eval)->in) |
| Returns a pointer to the associated gnn_input : Reading and handling of sets of vectors.. | |
| #define | GNN_EVAL_GET_OUTPUT(eval) ((eval)->out) |
| Returns a pointer to the associated gnn_output : Writing sets of vectors.. | |
| #define | GNN_EVAL_INPUT_SIZE(eval) ((eval)->n) |
| Returns the size of the input. | |
| #define | GNN_EVAL_OUTPUT_SIZE(eval) ((eval)->m) |
| Returns the size of the output. | |
| #define | GNN_EVAL_PARAMETER_SIZE(eval) ((eval)->l) |
| Returns the size of the parameter vector. | |
| #define | GNN_EVAL_AMOUNT(eval) ((eval)->P) |
| Returns the amount of examples to be evaluated by the Evaluations.. | |
| #define | GNN_GRAD_GET_NODE(grad) ((grad)->node) |
| Returns a pointer to the associated gnn_node. | |
| #define | GNN_GRAD_GET_INPUT(grad) ((grad)->in) |
| Returns a pointer to the associated gnn_input : Reading and handling of sets of vectors.. | |
| #define | GNN_GRAD_GET_OUTPUT(grad) ((grad)->out) |
| Returns a pointer to the associated gnn_output : Writing sets of vectors.. | |
| #define | GNN_GRAD_INPUT_SIZE(grad) ((grad)->n) |
| Returns the size of the input. | |
| #define | GNN_GRAD_OUTPUT_SIZE(grad) ((grad)->m) |
| Returns the size of the output. | |
| #define | GNN_GRAD_PARAMETER_SIZE(grad) ((grad)->l) |
| Returns the size of the parameter vector. | |
| #define | GNN_GRAD_AMOUNT(grad) ((grad)->P) |
| Returns the amount of examples considered by the Evaluations.. | |
| #define | GNN_GRAD_SUMP(grad) ((grad)->mp) |
| Returns the last pattern weight sum. | |
| #define | GNN_GRAD_SUME(grad) ((grad)->mp * (grad)->me) |
| Returns the sum of the last batch's error. | |
| #define | GNN_GRAD_E(grad) ((grad)->me) |
| Returns the last batch's mean error sum. | |
| #define | GNN_GRAD_DX(grad) ((grad)->mdx) |
| Returns the last batch's mean error sum. | |
| #define | GNN_GRAD_DW(grad) ((grad)->mdw) |
| Returns the last batch's mean error sum. | |
| #define | GNN_LINE_W(line) ((line)->w) |
| Returns the origin of the line evaluations. | |
| #define | GNN_LINE_DIR(line) ((line)->d) |
| Returns the direction of the line evaluations. | |
| #define | GNN_LINE_E(line) ((line)->error) |
| Returns the last computed error along the line evaluation. | |
| #define | GNN_LINE_DE(line) ((line)->derivative) |
| Returns the last computed derivative along the line evaluation. | |
Typedefs | |
| typedef _gnn_eval | gnn_eval |
| Evaluation buffer structure. | |
| typedef _gnn_grad | gnn_grad |
| Error and Gradients Evaluation buffer structure. | |
| typedef enum _gnn_grad_eval | gnn_grad_eval |
| Gradient evaluation flags. | |
| typedef _gnn_line | gnn_line |
| Directional Error and Gradients Evaluation buffer structure. | |
| typedef enum _gnn_line_eval | gnn_line_eval |
| Line evaluation flags. | |
Functions | |
| gnn_eval * | gnn_eval_new (gnn_node *node, gnn_input *in, gnn_output *out) |
| Builds a new buffer for output evaluation. | |
| void | gnn_eval_destroy (gnn_eval *eval) |
| Destroys an evaluation buffer. | |
| int | gnn_eval_pats (gnn_eval *eval, size_t s, size_t n) |
| Computes the outputs for a given input set. | |
| int | gnn_eval_all (gnn_eval *eval) |
| Computes the outputs for a given input set. | |
| gnn_grad * | gnn_grad_new (gnn_node *node, gnn_criterion *crit, gnn_dataset *data) |
| Builds a new buffer for gradient evaluation. | |
| void | gnn_grad_destroy (gnn_grad *grad) |
| Destroys a gradient buffer. | |
| int | gnn_grad_pats (gnn_grad *grad, gnn_grad_eval flag, size_t s, size_t n) |
| Compute the mean cost and gradients. | |
| int | gnn_grad_all (gnn_grad *grad, gnn_grad_eval flag) |
| Compute the mean cost and gradients. | |
| gnn_line * | gnn_line_new (gnn_grad *grad, gsl_vector *direction) |
| Returns a new buffer structure for line evaluations. | |
| void | gnn_line_destroy (gnn_line *line) |
| Destroys a given line evaluation buffer. | |
| int | gnn_line_set_direction (gnn_line *line, const gsl_vector *dir) |
Sets a new direction
for the Evaluations. structure. | |
| const gsl_vector * | gnn_line_get_direction (gnn_line *line) |
Gets the installed directional vector
. | |
| int | gnn_line_set_origin (gnn_line *line, const gsl_vector *origin) |
Sets a new origin
for the Evaluations. structure. | |
| const gsl_vector * | gnn_line_get_origin (gnn_line *line) |
Gets the installed origin vector
. | |
| gnn_grad * | gnn_line_get_grad (gnn_line *line) |
| Gets the installed Evaluations. evaluation buffer. | |
| int | gnn_line_pats (gnn_line *line, double alpha, gnn_line_eval flag, size_t s, size_t n) |
| Compute mean cost and gradients along a direction for a minibatch. | |
| int | gnn_line_all (gnn_line *line, double alpha, gnn_line_eval flag) |
| Compute mean cost and gradients along a direction for a minibatch. | |
|
|
This macro returns the number of examples to be evaluated by the Evaluations. evaluation buffer. Basically, it is the number of examples contained in the associated gnn_input : Reading and handling of sets of vectors. object. Definition at line 98 of file gnn_evaluation.h. |
|
|
Definition at line 60 of file gnn_evaluation.h. |
|
|
Definition at line 53 of file gnn_evaluation.h. |
|
|
Definition at line 67 of file gnn_evaluation.h. |
|
|
Definition at line 74 of file gnn_evaluation.h. |
|
|
Definition at line 81 of file gnn_evaluation.h. |
|
|
Definition at line 88 of file gnn_evaluation.h. |
|
|
This macro returns the number of examples considered in the computation of the weighted values. Basically, it is the number of examples contained in the associated gnn_dataset : Datasets for Training. object. Definition at line 156 of file gnn_evaluation.h. |
|
|
This macro returns the last gradient with respect its parameters, given by
for the last processed minibatch in the given Evaluations. buffer. Definition at line 216 of file gnn_evaluation.h. |
|
|
This macro returns the last gradient with respect its inputs, given by
for the last processed minibatch in the given Evaluations. buffer. Definition at line 206 of file gnn_evaluation.h. |
|
|
This macro returns the last mean error, given by
for the last processed minibatch in the given Evaluations. buffer. Definition at line 196 of file gnn_evaluation.h. |
|
|
Definition at line 118 of file gnn_evaluation.h. |
|
|
Definition at line 111 of file gnn_evaluation.h. |
|
|
Definition at line 125 of file gnn_evaluation.h. |
|
|
Definition at line 132 of file gnn_evaluation.h. |
|
|
Definition at line 139 of file gnn_evaluation.h. |
|
|
Definition at line 146 of file gnn_evaluation.h. |
|
|
This macro returns the last sum of errors, given by
for the last processed minibatch in the given Evaluations. buffer. Definition at line 186 of file gnn_evaluation.h. |
|
|
This macro returns the sum
of the last processed minibatch in the given Evaluations. buffer. Definition at line 176 of file gnn_evaluation.h. |
|
|
This macro returns the value of the computed derivate along the last line evaluation. Definition at line 258 of file gnn_evaluation.h. |
|
|
This macro returns a pointer to the directional vector Definition at line 240 of file gnn_evaluation.h. |
|
|
This macro returns the value of the last computed average error along the last line evaluation. Definition at line 249 of file gnn_evaluation.h. |
|
|
This macro returns a pointer to the origin Definition at line 231 of file gnn_evaluation.h. |
|
|
This structure contains the necessary elements for performing a full dataset evaluation. Definition at line 277 of file gnn_evaluation.h. |
|
|
This structure contains the necessary values and buffers for performing the computation of averaged gradients and errors over datasets. Definition at line 306 of file gnn_evaluation.h. |
|
|
This special datatype is used by the gradient evaluation functions. It tells them how far the batch should be processed, i.e. if it should compute Definition at line 345 of file gnn_evaluation.h. |
|
|
This structure contains the necessary values and buffers for performing the computation of averaged gradients and errors over datasets, evaluated along a given direction, treating the node's function as a one-dimensional function. The structure contains the direction and a error and gradient evaluation buffer (Evaluations.). Definition at line 367 of file gnn_evaluation.h. |
|
|
This special datatype is used by the line evaluation functions. It tells them if they should computed only the error along the given line or if they also should compute the error derivative. Definition at line 388 of file gnn_evaluation.h. |
|
|
This function computes, given a set of input samples, all associated outputs, storing them into the output device provided by the Evaluations. structure. The patterns that are evaluated are those between
Definition at line 418 of file gnn_evaluation.c. |
|
|
Definition at line 355 of file gnn_evaluation.c. |
|
||||||||||||||||
|
This function builds a new Evaluations. buffer structure for computing outputs.
Definition at line 284 of file gnn_evaluation.c. |
|
||||||||||||||||
|
This function computes, given a set of input samples, all associated outputs, storing them into the output device provided by the Evaluations. structure. The patterns that are evaluated are those between
Definition at line 379 of file gnn_evaluation.c. |
|
||||||||||||
|
This function behaves like the Evaluations. function, but it computes the gradients and the error over the whole dataset. That is, it computes:
and
where
Recall that The evaluation flag can be:
// compute all gnn_grad_all (g, gnnGradDw); // now, get them e = GNN_GRAD_E (g); // e is a double dx = GNN_GRAD_DX (g); // dx is a gsl_vector * dw = GNN_GRAD_DW (g); // dw is a gsl_vector * sp = GNN_GRAD_SUMP (g); // sp is a double se = GNN_GRAD_SUME (g); // se is a double
Definition at line 720 of file gnn_evaluation.c. |
|
|
Definition at line 527 of file gnn_evaluation.c. |
|
||||||||||||||||
|
This function builds a new Evaluations. buffer structure for computing gradients.
Definition at line 442 of file gnn_evaluation.c. |
|
||||||||||||||||||||
|
This function computes many things simultaneously in one pass. It builds estimations of the gradients
and
where In order to obtain the results, you should tell the function how far it should process the patterns, using a special flag. The evaluation flag can be:
// compute all gnn_grad_pats (g, gnnGradDw, 10, 20); // now, get them e = GNN_GRAD_E (g); // e is a double dx = GNN_GRAD_DX (g); // dx is a gsl_vector * dw = GNN_GRAD_DW (g); // dw is a gsl_vector * sp = GNN_GRAD_SUMP (g); // sp is a double se = GNN_GRAD_SUME (g); // se is a double The starting index s should be within the valid bounds. The size n of the batch will be adapted if s + n exceeds the valid bounds. That is, e.g. if there are 10 patterns (and so the index of the last pattern to be considered is 9), and s=8 and n=4, then the last pattern in the averaging will be 9, although 8+4=12.
Definition at line 600 of file gnn_evaluation.c. |
|
||||||||||||||||
|
This function behaves like the Evaluations. function, but it computes the error and its derivative along a given line. That is, it performs all evaluations at
where
The flag flag tells the function if it should compute only the error (
The results can be recovered by the macros Evaluations. and Evaluations.:
gnn_grad *grad; gnn_line *line; double error; // build grad and line buffers ... // evaluate all patterns at 1.2 gnn_line_all (line, 1.2, gnnLineE); // get results error = GNN_LINE_E (line);
Definition at line 1072 of file gnn_evaluation.c. |
|
|
This function frees the Evaluations.'s internal buffers and deallocates the structure. The installed Evaluations. error and gradient evaluation buffer won't be destroyed.
Definition at line 806 of file gnn_evaluation.c. |
|
|
This function returns a pointer to the currently used directional buffer
Definition at line 860 of file gnn_evaluation.c. |
|
|
This function returns a buffer for the installed Evaluations. error and gradients evaluation buffer used by the current Evaluations. structure for its line evaluation.
Definition at line 925 of file gnn_evaluation.c. |
|
|
This function returns a pointer to the currently used origin vector
Definition at line 907 of file gnn_evaluation.c. |
|
||||||||||||
|
This function builds a new buffer structure for line evaluations. The direction is given by the direction vector, and the origin is set at the gnn_node's current parameter vector. If the direction is omitted (NULL is given), then it will be a null vector.
Definition at line 747 of file gnn_evaluation.c. |
|
||||||||||||||||||||||||
|
This function behaves like the Evaluations. function, but it computes the error and its derivative along a given line. That is, it performs all evaluations at
where
The flag flag tells the function if it should compute only the error (
The results can be recovered by the macros Evaluations. and Evaluations.:
gnn_grad *grad; gnn_line *line; double error; double derivative; // build grad and line buffers ... // evaluate the patterns 11-30 at 0.5 gnn_line_pats (line, 0.5, gnnLineDE, 11, 30); // get results error = GNN_LINE_E (line); derivative = GNN_LINE_DE (line);
Definition at line 984 of file gnn_evaluation.c. |
|
||||||||||||
|
This function sets a new directional vector
Definition at line 831 of file gnn_evaluation.c. |
|
||||||||||||
|
This function sets a new origin vector
Definition at line 878 of file gnn_evaluation.c. |
1.2.18