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

gnn_evaluation.h File Reference

#include <gsl/gsl_matrix.h>
#include "gnn_node.h"
#include "gnn_criterion.h"
#include "gnn_dataset.h"
#include "gnn_output.h"

Include dependency graph for gnn_evaluation.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  _gnn_eval
struct  _gnn_grad
struct  _gnn_line

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_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.


Enumerations

enum  _gnn_grad_eval { gnnGradE, gnnGradDx, gnnGradDw }
enum  _gnn_line_eval { gnnLineE, gnnLineDE }

Functions

gnn_evalgnn_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_gradgnn_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_linegnn_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_gradgnn_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.


Define Documentation

#define GNN_GRAD_SUMP grad       ((grad)->mp)
 

This macro returns the sum

of the last processed minibatch in the given Evaluations. buffer.

Definition at line 176 of file gnn_evaluation.h.


Enumeration Type Documentation

enum _gnn_grad_eval
 

Enumeration values:
gnnGradE 
gnnGradDx 
gnnGradDw 

Definition at line 347 of file gnn_evaluation.h.

enum _gnn_line_eval
 

Enumeration values:
gnnLineE 
gnnLineDE 

Definition at line 390 of file gnn_evaluation.h.


Function Documentation

int gnn_eval_all gnn_eval   eval
 

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 and .

Parameters:
eval  A pointer to a Evaluations..
s  The index of the first input sample to be evaluated.
n  The amount of samples to be evaluated.
Returns:
Returns 0 if suceeded.

Definition at line 418 of file gnn_evaluation.c.

void gnn_eval_destroy gnn_eval   eval
 

Parameters:
eval  A pointer a Evaluations. buffer.

Definition at line 355 of file gnn_evaluation.c.

gnn_eval* gnn_eval_new gnn_node   node,
gnn_input   in,
gnn_output   out
 

This function builds a new Evaluations. buffer structure for computing outputs.

Parameters:
node  A pointer to a gnn_node.
in  A pointer to a gnn_input : Reading and handling of sets of vectors. input sampler.
out  A pointer to a gnn_output : Writing sets of vectors. output device.
Returns:
Returns a pointer to a new buffer structure of NULL if failed.

Definition at line 284 of file gnn_evaluation.c.

int gnn_eval_pats gnn_eval   eval,
size_t    s,
size_t    n
 

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 and .

Parameters:
eval  A pointer to a Evaluations..
s  The index of the first input sample to be evaluated.
n  The amount of samples to be evaluated.
Returns:
Returns 0 if suceeded.

Definition at line 379 of file gnn_evaluation.c.

int gnn_grad_all gnn_grad   grad,
gnn_grad_eval    flag
 

This function behaves like the gnn_grad_pats function, but it computes the gradients and the error over the whole dataset. That is, it computes:

and

where is the -th pattern's weight, is the gradient with respect to the inputs evaluated at the -th pattern, is the gradient with respect to the parameters evaluated at the -th pattern, and is the cost/error for the -th output.

Recall that is the number of patterns contained in the dataset.

The evaluation flag can be:

  • gnnGradE : only compute mean error .
  • gnnGradDx : compute and .
  • gnnGradDw : compute and and
The computed values can be retrieved directly from the Evaluations. buffer:
 // 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
Parameters:
grad  A pointer to a Evaluations..
flag  The evaluation flag.
Returns:
Returns 0 if suceeded.

Definition at line 720 of file gnn_evaluation.c.

void gnn_grad_destroy gnn_grad   grad
 

Parameters:
grad  A pointer a Evaluations. buffer.

Definition at line 527 of file gnn_evaluation.c.

gnn_grad* gnn_grad_new gnn_node   node,
gnn_criterion   crit,
gnn_dataset   data
 

This function builds a new Evaluations. buffer structure for computing gradients.

Parameters:
node  A pointer to a gnn_node.
crit  A pointer to a gnn_criterion : Basic Criterion Function..
data  A pointer to a gnn_dataset : Datasets for Training..
Returns:
Returns a pointer to a new buffer structure of NULL if failed.

Definition at line 442 of file gnn_evaluation.c.

int gnn_grad_pats gnn_grad   grad,
gnn_grad_eval    flag,
size_t    s,
size_t    n
 

This function computes many things simultaneously in one pass. It builds estimations of the gradients and and the cost by averaging over the n patterns starting at s. That is, this function computes:

and

where is the -th pattern's weight, is the gradient with respect to the inputs evaluated at the -th pattern, is the gradient with respect to the parameters evaluated at the -th pattern, and is the cost/error for the -th output.

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:

  • gnnGradE : only compute mean error .
  • gnnGradDx : compute and .
  • gnnGradDw : compute and and
The computed values can be retrieved directly from the Evaluations. buffer:
 // 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.

Parameters:
grad  A pointer to a Evaluations..
flag  The evaluation flag.
s  The index of the first pattern in the dataset to be considered in the averaging.
n  The amount of patterns to be considered.
Returns:
Returns 0 if suceeded.

Definition at line 600 of file gnn_evaluation.c.

int gnn_line_all gnn_line   line,
double    alpha,
gnn_line_eval    flag
 

This function behaves like the gnn_grad_pats function, but it computes the error and its derivative along a given line. That is, it performs all evaluations at

where are the node's current parameters, is a scalar and is a given direction, treating the function as it where just a one-dimensional function. All patterns are used for this evaluation.

The flag flag tells the function if it should compute only the error (gnnLineE) or the error with its derivative along the line (gnnLineDE). The approximated derivative is apropiately scaled in order to match the real derivative:

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);

Warning:
A line evaluation modifies the gnn_node's internal parameters. In order to recover the original vector, call this function with .
Parameters:
line  A pointer to a Evaluations..
alpha  The scalar .
flag  The evaluation flag.
Returns:
Returns 0 if suceeded.

Definition at line 1072 of file gnn_evaluation.c.

void gnn_line_destroy gnn_line   line
 

This function frees the Evaluations.'s internal buffers and deallocates the structure. The installed Evaluations. error and gradient evaluation buffer won't be destroyed.

Parameters:
line  A pointer to a Evaluations..

Definition at line 806 of file gnn_evaluation.c.

const gsl_vector* gnn_line_get_direction gnn_line   line
 

This function returns a pointer to the currently used directional buffer used by the Evaluations. buffer for its line evaluations.

Parameters:
line  A pointer to a Evaluations..
Returns:
Returns a pointer to the directional vector.

Definition at line 860 of file gnn_evaluation.c.

gnn_grad* gnn_line_get_grad gnn_line   line
 

This function returns a buffer for the installed Evaluations. error and gradients evaluation buffer used by the current Evaluations. structure for its line evaluation.

Parameters:
line  A pointer to a Evaluations..
Returns:
Returns a pointer to the internal Evaluations. structure.

Definition at line 925 of file gnn_evaluation.c.

const gsl_vector* gnn_line_get_origin gnn_line   line
 

This function returns a pointer to the currently used origin vector by the Evaluations. for its line evaluations.

Parameters:
line  A pointer to a Evaluations..
Returns:
Returns a pointer to the origin vector.

Definition at line 907 of file gnn_evaluation.c.

gnn_line* gnn_line_new gnn_grad   grad,
gsl_vector *    direction
 

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.

Parameters:
grad  A pointer to a Evaluations..
direction  A pointer to a gsl_vector.
Returns:
Returns a pointer to the new Evaluations. buffer or NULL if failed.

Definition at line 747 of file gnn_evaluation.c.

int gnn_line_pats gnn_line   line,
double    alpha,
gnn_line_eval    flag,
size_t    s,
size_t    n
 

This function behaves like the gnn_grad_pats function, but it computes the error and its derivative along a given line. That is, it performs all evaluations at

where are the node's current parameters, is a scalar and is a given direction, treating the function as it where just a one-dimensional function. The patterns starting at s and ending at s+n are used for the averaging.

The flag flag tells the function if it should compute only the error (gnnLineE) or the error with its derivative along the line (gnnLineDE). The approximated derivative is apropiately scaled in order to match the real derivative:

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);

Warning:
A line evaluation modifies the gnn_node's internal parameters. In order to recover the original vector, call this function with .
Parameters:
line  A pointer to a Evaluations..
alpha  The scalar .
flag  The evaluation flag.
s  The first pattern index .
n  The size of the minibatch .
Returns:
Returns 0 if suceeded.

Definition at line 984 of file gnn_evaluation.c.

int gnn_line_set_direction gnn_line   line,
const gsl_vector *    dir
 

This function sets a new directional vector for the line evaluation buffer. The vector should be of the correct size.

Parameters:
line  A pointer to a Evaluations..
dir  A pointer to a gsl_vector.
Returns:
Returns 0 if succeeded.

Definition at line 831 of file gnn_evaluation.c.

int gnn_line_set_origin gnn_line   line,
const gsl_vector *    origin
 

This function sets a new origin vector for the line evaluation buffer. The vector should be of the correct size.

Parameters:
line  A pointer to a Evaluations..
origin  A pointer to a gsl_vector.
Returns:
Returns 0 if succeeded.

Definition at line 878 of file gnn_evaluation.c.


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