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

gnn_node.h File Reference

#include "gnn_pbundle.h"
#include "gnn_node_vector.h"

Include dependency graph for gnn_node.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_node
 gnn_node Fundamental Structure. More...


Defines

#define GNN_NODE_SUB_INSTALL(_node_, _size_, _status_)

Typedefs

typedef _gnn_node gnn_node
 gnn_node type definition.

typedef int(* gnn_node_f )(gnn_node *node, const gsl_vector *x, const gsl_vector *w, gsl_vector *y)
 gnn_node_f type definition.

typedef int(* gnn_node_df )(gnn_node *node, const gsl_vector *x, const gsl_vector *w, const gsl_vector *dy, gsl_vector *dxw)
 gnn_node_df type definition.

typedef void(* gnn_node_destructor )(gnn_node *layer)
 gnn_node_destructor type definition.


Functions

int gnn_node_is_root (gnn_node *node)
 Check if node is root node.

const char * gnn_node_get_type_name (gnn_node *node)
 Get the node's type.

int gnn_node_input_get_size (gnn_node *node)
 Get the node's input size.

int gnn_node_output_get_size (gnn_node *node)
 Get the node's output size.

int gnn_node_destroy (gnn_node *node)
 Destroys the current node.

int gnn_node_evaluate_init (gnn_node *node)
 Initializes the evaluations.

int gnn_node_evaluate_f (gnn_node *node, const gsl_vector *x, gsl_vector *y)
 Evaluates the output of the function recursively.

int gnn_node_evaluate_dx (gnn_node *node, const gsl_vector *dy, gsl_vector *dx)
 Evaluates the gradient .

int gnn_node_evaluate_dw (gnn_node *node, gsl_vector *dw)
 Evaluates the gradient .

int gnn_node_param_get_size (gnn_node *node)
 Returns the size of the parameter vector.

int gnn_node_param_get (gnn_node *node, gsl_vector *w)
 Get the node's parameters.

int gnn_node_param_set (gnn_node *node, const gsl_vector *w)
 Sets new values for the parameter vector.

int gnn_node_param_freeze_flags_get (gnn_node *node, gsl_vector_int *f)
 Get the freeze flags.

int gnn_node_param_freeze_flags_set (gnn_node *node, const gsl_vector_int *f)
 Sets new freeze flags.

int gnn_node_param_freeze (gnn_node *node, int i)
 Freeze the i-th parameter.

int gnn_node_param_unfreeze (gnn_node *node, int i)
 Unfreeze the i-th parameter.

int gnn_node_param_is_frozen (gnn_node *node, int i)
 Check if the i-th parameter is frozen.

int gnn_node_param_are_frozen (gnn_node *node)
 Check if all the node's parameters are frozen.

int gnn_node_param_freeze_all (gnn_node *node)
 Freeze all parameters.

int gnn_node_param_unfreeze_all (gnn_node *node)
 Unfreeze all parameters.

int gnn_node_param_share (const gnn_node *node, gnn_node *client)
 Share the node's parameters.

int gnn_node_init (gnn_node *node, const char *type, gnn_node_f f, gnn_node_df dx, gnn_node_df dw, gnn_node_destructor dest)
 Initializes a gnn_node structure.

int gnn_node_set_sizes (gnn_node *node, int n, int m, int l)
 Set the node's sizes.

gsl_vector * gnn_node_local_get_w (gnn_node *node)
 Get local parameters.

gsl_vector * gnn_node_local_get_dw (gnn_node *node)
 Get local parameter gradients.

gsl_vector_int * gnn_node_local_get_f (gnn_node *node)
 Get local parameters frozen flags.

int gnn_node_local_update (gnn_node *node)
 Get local parameters.

int gnn_node_eval_f (gnn_node *node, const gsl_vector *x, gsl_vector *y)
 Evaluates the output of the function recursively.

int gnn_node_eval_dx (gnn_node *node, const gsl_vector *dy, gsl_vector *dx)
 Evaluates recursively.

int gnn_node_eval_dw (gnn_node *node)
 Evaluates recursively.

int gnn_node_sub_install_specific (gnn_node *node, int nsub,...)
 Install subnodes.

int gnn_node_sub_install (gnn_node *node, int nsub, va_list subs)
 Install subnodes.

int gnn_node_sub_install_node_vector (gnn_node *node, gnn_node_vector *vector)
 Install the nodes in the node vector as subnodes.

int gnn_node_sub_get_number (gnn_node *node)
 Get the number of subnodes.

gnn_nodegnn_node_sub_get_node_at (gnn_node *node, int i)
 Get's the node's i-th subnode.

gnn_pbundlegnn_node_sub_search_params (gnn_node *node, const char *type)
 Get all subnodes of a given type.


Define Documentation

#define GNN_NODE_SUB_INSTALL _node_,
_size_,
_status_   
 

Value:

{                                                                 \
    va_list args;                                                 \
    va_start(args, (_size_));                                     \
    (_status_) = gnn_node_sub_install ((_node_), (_size_), args); \
    va_end(args);                                                 \
}

Definition at line 40 of file gnn_node.h.


Typedef Documentation

typedef struct _gnn_node gnn_node
 

The gnn_node C type for libgnn node implementations.

Definition at line 60 of file gnn_node.h.

typedef void(* gnn_node_destructor)(gnn_node *layer)
 

This is the type for gnn_node's destroy functions. An example function is:

 void
 my_destroy (gnn_node *node)
 {
     // function implementation
     ...
 }

Definition at line 126 of file gnn_node.h.

typedef int(* gnn_node_df)(gnn_node *node, const gsl_vector *x, const gsl_vector *w, const gsl_vector *dy, gsl_vector *dxw)
 

This is the type for gnn_node's evaluation function gradients. An example function is:

 int my_func_gradient (gnn_node *node,
                       const gsl_vector *x,
                       const gsl_vector *w,
                       const gsl_vector *dy,
                       gsl_vector       *dw);
 {
     // function implementation
     ...
 }

Definition at line 104 of file gnn_node.h.

typedef int(* gnn_node_f)(gnn_node *node, const gsl_vector *x, const gsl_vector *w, gsl_vector *y)
 

This is the type for gnn_node's evaluation functions. An example function is:

 int my_func (gnn_node *node,
              const gsl_vector *x,
              const gsl_vector *w,
              gsl_vector *y)
 {
     // function implementation
     ...
 }

Definition at line 80 of file gnn_node.h.


Function Documentation

int gnn_node_destroy gnn_node   node
 

This function detroys the node given as a parameter: it calls first the installed destructor and the gnn_node Extension API to destroy itself.

This is a virtual function: the specific destruction of the node is given by the installed gnn_node::destroy function, and the destruction of the underlying's node structure by itself is performed by gnn_node Extension API.

Warning:
Only root nodes can be destroyed.
Parameters:
node  A pointer to an gnn_node.
Returns:
Returns 0 if succeeded.

Definition at line 500 of file gnn_node.c.

int gnn_node_eval_dw gnn_node   node
 

This function calls the installed gnn_node::dw function with the appropiate arguments.

This function should only be called from construction node's evaluation functions. If you want to evaluate it from outside, you should call \gnn_node_eval_dw instead, which initiates the recursion parameters appropiatelly.

Parameters:
node  A pointer to an gnn_node.
Returns:
Returns 0 if suceeded.

Definition at line 1425 of file gnn_node.c.

int gnn_node_eval_dx gnn_node   node,
const gsl_vector *    dy,
gsl_vector *    dx
 

This function calls the installed gnn_node::dx function with the appropiate arguments.

This function should only be called from construction node's evaluation functions. If you want to evaluate it from outside, you should call \gnn_node_eval_dx instead, which initiates the recursion parameters appropiatelly.

Parameters:
node  A pointer to an gnn_node.
dx  A gsl_vector, where the result should be placed.
Returns:
Returns 0 if suceeded.

Definition at line 1388 of file gnn_node.c.

int gnn_node_eval_f gnn_node   node,
const gsl_vector *    x,
gsl_vector *    y
 

This function calls the installed gnn_node::f function with the appropiate arguments.

This function should only be called from construction node's evaluation functions. If you want to evaluate it from outside, you should call \gnn_node_eval_f instead, which initiates the recursion parameters appropiatelly.

Parameters:
node  A pointer to an gnn_node.
x  The input vector to be evaluated.
y  A gsl_vector, where the result should be placed.
Returns:
Returns 0 if suceeded.

Definition at line 1354 of file gnn_node.c.

int gnn_node_evaluate_dw gnn_node   node,
gsl_vector *    dw
 

This function computes of the node's function. First, it sets the appropiate values for initiating the recursive evaluation, and then calls gnn_node_eval_dw.

@warning: The gradient will be evaluated at , where is the last evaluated input vector, and is the last parameter vector. Also, it will use the last given for its error-backpropagation. In other words, the buffers used for both gnn_node_evaluate_f and gnn_node_evaluate_dx shouldn't have changed!

Parameters:
node  A pointer to an gnn_node.
dw  A gsl_vector, where the result should be placed.
Returns:
Returns 0 if suceeded.

Definition at line 653 of file gnn_node.c.

int gnn_node_evaluate_dx gnn_node   node,
const gsl_vector *    dy,
gsl_vector *    dx
 

This function computes of the node's function. First, it sets the appropiate values for initiating the recursive evaluation, and then calls gnn_node_eval_dx.

@warning: The gradient will be evaluated at , where is the last evaluated input vector, and is the last parameter vector. That is, the last values given at gnn_node_evaluate_f.

Parameters:
node  A pointer to an gnn_node.
dy  The vector.
dx  A gsl_vector, where the result should be placed.
Returns:
Returns 0 if suceeded.

Definition at line 609 of file gnn_node.c.

int gnn_node_evaluate_f gnn_node   node,
const gsl_vector *    x,
gsl_vector *    y
 

This function computes the output of the node's function. First, it sets the appropiate values for initiating the recursive evaluation, and then calls gnn_node_eval_f.

@warning: If you want to compute , then you should not change the content of the input buffer .

Parameters:
node  A pointer to an gnn_node.
x  The input vector of the correct size that should be evaluated.
y  A gsl_vector, where the result should be placed.
Returns:
Returns 0 if suceeded.

Definition at line 538 of file gnn_node.c.

int gnn_node_evaluate_init gnn_node   node
 

This function initializes the gradient evaluation routines. It should be called before gnn_node_eval_f, for every single pattern or input evaluation. The complete sequence for evaluations is:

Parameters:
node  A pointer to an gnn_node.
Returns:
Returns 0 if suceeded.

Definition at line 579 of file gnn_node.c.

const char* gnn_node_get_type_name gnn_node   node
 

This function returns the node's type: an unique string which identifies a node's type.

Generally speaking, the type depends on which constructor function was used to instantiate the node. Per example, gnn_weight_new () creates a "gnn_weight" node, gnn_tanh_new () creates a "gnn_tanh" node.

The returned string is owned by the node and should not be freed or manipulated in any other way.

Parameters:
node  A gnn_node.
Returns:
A string containing n integer identifying the layer's type.

Definition at line 440 of file gnn_node.c.

int gnn_node_init gnn_node   node,
const char *    type,
gnn_node_f    f,
gnn_node_df    dx,
gnn_node_df    dw,
gnn_node_destructor    dest
 

This function initializes a gnn_node structure. The memory for the structure should be allocated manually. The sizes should be set after calling this function.

An example of its use is the following:

   gnn_node *
   gnn_mifunction (int input_size, int output_size, int param_size)
   {
        gnn_node *node;

        node = (gnn_node *) malloc (sizeof (*node));
        gnn_node_init ( node,
                        "gnn_mifunction",
                        gnn_mifunction_f,
                        gnn_mifunction_dx,
                        gnn_mifunction_dw,
                        gnn_mifunction_dest);

        gnn_node_set_sizes (input_size, output_size, param_size);

        // initialize the rest
        ...

If one of the function pointers is NULL, then it installs the default functions:

Parameters:
node  A pointer to the node to be initialized.
type  A string containing the name of the layer's type. The node will build a copy.
f  A pointer to the evaluation function.
dx  A pointer to the function.
dw  A pointer to the function.
dest  A pointer to the destroy function.
Returns:
0 on success.

Definition at line 1183 of file gnn_node.c.

int gnn_node_input_get_size gnn_node   node
 

This function returns the size of the input vector that the current node's function demands for computing its output .

Parameters:
node  A pointer to an gnn_node.
Returns:
The input size.

Definition at line 458 of file gnn_node.c.

int gnn_node_is_root gnn_node   node
 

This function returns 1 if the current node is a root node, or 0 if not.

Parameters:
node  A gnn_node.
Returns:
1 if root node, 0 if not.

Definition at line 413 of file gnn_node.c.

gsl_vector* gnn_node_local_get_dw gnn_node   node
 

This function returns a pointer to the node's own parameters gradient . The returning vector is the gradient itself and its values can be freely changed. When finished, call gnn_node_local_update.

Parameters:
node  A pointer to an gnn_node.
Returns:
Returns a pointer to the internal vector.

Definition at line 1292 of file gnn_node.c.

gsl_vector_int* gnn_node_local_get_f gnn_node   node
 

This function returns a pointer to the node's own parameters frozen flags. The returning vector is the flags vector itself and its values can be freely changed. When finished, call gnn_node_local_update.

The values should be binary: 0 means that the parameter is free, and 1 (non-zero) means that the parameter is frozen (fixed).

Parameters:
node  A pointer to an gnn_node.
Returns:
Returns a pointer to the internal flags vector.

Definition at line 1313 of file gnn_node.c.

gsl_vector* gnn_node_local_get_w gnn_node   node
 

This function returns a pointer to the node's own parameters. The returning vector is the parameter vector itself and its values can be freely changed. When finished, call gnn_node_local_update.

Parameters:
node  A pointer to an gnn_node.
Returns:
Returns a pointer to the internal parameter vector .

Definition at line 1272 of file gnn_node.c.

int gnn_node_local_update gnn_node   node
 

This function updates the local parameters and its changes. This function should be called after any change in the parameters to make them effective.

Parameters:
node  A pointer to an gnn_node.
Returns:
Returns a pointer to the internal parameter vector .

Definition at line 1330 of file gnn_node.c.

int gnn_node_output_get_size gnn_node   node
 

This function returns the size of the output vector that the current node's function computes.

Parameters:
node  A pointer to an gnn_node.
Returns:
The output size.

Definition at line 475 of file gnn_node.c.

int gnn_node_param_are_frozen gnn_node   node
 

This function returns 1 if all parameters are frozen.

Parameters:
node  A pointer to an gnn_node.
Returns:
Returns 1 if frozen, 0 if not.

Definition at line 912 of file gnn_node.c.

int gnn_node_param_freeze gnn_node   node,
int    i
 

This function freezes the i-th parameter.

Parameters:
node  A pointer to an gnn_node.
i  The index of the parameter to be frozen.
Returns:
Returns 0 if suceeded.

Definition at line 862 of file gnn_node.c.

int gnn_node_param_freeze_all gnn_node   node
 

This function freezes all the node's parameters.

Parameters:
node  A pointer to an gnn_node.
Returns:
Returns 0 if suceeded.

Definition at line 931 of file gnn_node.c.

int gnn_node_param_freeze_flags_get gnn_node   node,
gsl_vector_int *    f
 

This function fills the given integer vector f with the node's freeze flags.

Implementation Note: The parameter vector is build with the node's parameter bundle.

Parameters:
node  A pointer to an gnn_node.
f  A gsl_vector_int sufficiently large to store the values.
Returns:
Returns 0 if suceeded.

Definition at line 826 of file gnn_node.c.

int gnn_node_param_freeze_flags_set gnn_node   node,
const gsl_vector_int *    f
 

This function sets new freeze flags for the node. They should be given as a gsl_vector_int, where 1=freeze and 0=free-parameter.

Parameters:
node  A pointer to an gnn_node.
f  A gsl_vector_int containing the new values for the parameter vector.
Returns:
Returns 0 if suceeded.

Definition at line 845 of file gnn_node.c.

int gnn_node_param_get gnn_node   node,
gsl_vector *    w
 

This function fills the input buffer w with the node's parameter values.

Implementation Note: The parameter vector is build with the node's parameter bundle.

Parameters:
node  A pointer to an gnn_node.
w  A gsl_vector sufficiently large to store the values.
Returns:
Returns 0 if suceeded.

Definition at line 786 of file gnn_node.c.

int gnn_node_param_get_size gnn_node   node
 

This function returns , the size of the parameter vector.

Parameters:
node  A pointer to an gnn_node.
Returns:
The size of the parameter vector .

Definition at line 766 of file gnn_node.c.

int gnn_node_param_is_frozen gnn_node   node,
int    i
 

This function returns 1 if the i-th parameter is frozen.

Parameters:
node  A pointer to an gnn_node.
i  The index of the parameter to be checked.
Returns:
Returns 1 if frozen, 0 if not.

Definition at line 896 of file gnn_node.c.

int gnn_node_param_set gnn_node   node,
const gsl_vector *    w
 

This function sets new values for the node's parameter vector. The new values are taken by the buffer w (of the correct size) given as input argument.

Parameters:
node  A pointer to an gnn_node.
w  A gsl_vector containing the new values for the parameter vector.
Returns:
Returns 0 if suceeded.

Definition at line 805 of file gnn_node.c.

int gnn_node_param_share const gnn_node   node,
gnn_node   client
 

This function share the node's parameters with the client node.

@warning: This function should be called on nodes that aren't connected only.

Parameters:
node  A pointer to an gnn_node.
client  A pointer to an gnn_node.
Returns:
Returns 0 if suceeded.

Definition at line 966 of file gnn_node.c.

int gnn_node_param_unfreeze gnn_node   node,
int    i
 

This function unfreezes the i-th parameter.

Parameters:
node  A pointer to an gnn_node.
i  The index of the parameter to be unfrozen.
Returns:
Returns 0 if suceeded.

Definition at line 879 of file gnn_node.c.

int gnn_node_param_unfreeze_all gnn_node   node
 

This function unfreezes all the node's parameters.

Parameters:
node  A pointer to an gnn_node.
Returns:
Returns 0 if suceeded.

Definition at line 947 of file gnn_node.c.

int gnn_node_set_sizes gnn_node   node,
int    n,
int    m,
int    l
 

This function sets the node's sizes for its input, output and parameter vector. It should be called after calling the gnn_node_init (and the gnn_node_sub_install in case of a constructor node) function.

Warning:
It is not allowed to call this function twice for the same node.
Parameters:
node  A pointer to an gnn_node.
n  The size of the node's input.
m  The size of the node's output.
l  The size of the node's parameter vector.
Returns:
Returns 0 if succeeded.

Definition at line 1241 of file gnn_node.c.

gnn_node* gnn_node_sub_get_node_at gnn_node   node,
int    i
 

This function returns a pointer to the i-th subnode.

Parameters:
node  A pointer to an gnn_node.
i  The index of the subnode to be retrieved.
Returns:
The pointer to the i-th subnode or NULL if failed.

Definition at line 1676 of file gnn_node.c.

int gnn_node_sub_get_number gnn_node   node
 

This function returns the number of direct subnodes of the node.

Parameters:
node  A pointer to an gnn_node.
Returns:
Returns the number of subnodes.

Definition at line 1659 of file gnn_node.c.

int gnn_node_sub_install gnn_node   node,
int    nsub,
va_list    subs
 

This function installs the given nodes as subnodes.

Parameters:
node  A pointer to an gnn_node.
nsub  The number of subnodes in the list.
subs  A va_list (C Standard Library) containing pointers to the subnodes to be installed.
Returns:
Returns 0 if suceeded.

Definition at line 1554 of file gnn_node.c.

int gnn_node_sub_install_node_vector gnn_node   node,
gnn_node_vector   vector
 

This function installs the non-NULL nodes in the node vector as subnodes.

Parameters:
node  A pointer to an gnn_node.
vector  A pointer to a gnn_node_vector.
Returns:
Returns 0 if suceeded.

Definition at line 1600 of file gnn_node.c.

int gnn_node_sub_install_specific gnn_node   node,
int    nsub,
...   
 

This function installs the given nodes as subnodes.

Parameters:
node  A pointer to an gnn_node.
nsub  The number of subnodes.
...  A list of subnodes to be installed.
Returns:
Returns 0 if suceeded.

Definition at line 1527 of file gnn_node.c.

gnn_pbundle* gnn_node_sub_search_params gnn_node   node,
const char *    type
 

This function searches the whole node three for nodes of the given type, and returns a parameter bundle of all their parameters.

Parameters:
node  A pointer to an gnn_node.
type  A string containing the type of the subnodes to be retrieved.
Returns:
A gnn_pbundle.

Definition at line 1697 of file gnn_node.c.


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