The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Neural_groups.c.PL -- generation of GANN group types

DESCRIPTION

This simple script takes as its input a special description of groups (in the distribution, the file grouptypes) and outputs xsub code that implements the group types described. The idea is to eliminate as much common code between the groups as possible and make it easy to change the framework where the groups are actually used.

Also, this makes it easy to define groups with different perceptive fields for different neurons without spending too much effort on each type of group. For example, the relatively complex XYConvolution1 group requires only 60 lines of code in this format instead of the over 100 lines of code and 30 lines of declarations in several different files without the compiler. Also, barring changes to the group compiler, the actual perl bindings of the groups can be changed without affecting the group code.

The group type description file is actually an executable perl script that calls the functions provided by Neural_groups.c.PL to generate different groups.

The groups are declared by calling the GANN_DECLARE_GROUP function. This function takes two arguments, first the name of the group and then a hash containing some parameters (hereafter called group parameters). The exact contents of this hash are in a flux. Currently, they are

n_igroups

If defined, the number of expected input groups / sections. 0 = same as not defined, zero inputs. >0 = exactly this number of groups. -1 = any number of groups larger than zero.

n_ilattices

If defined, this group will also get this many lattices as input.

n_neurons

Similar to n_igroups but for number of neurons. Alternately, this can be set to the string value "LATTICE3D" which means that the user should specify the x, y and z dimensions for a lattice. The value of the NNEURONS C macro will work also in this case.

activation

If defined as nonzero, this group has an activation function.

datas

A hash containing zero or more group data elements (for example number of neurons ...) NOT YET IMPLEMENTED

nweights

A code snippet for calculating the number of neurons. The result should be stored in gann_nwts.

gradient

What type of groups this generally is. The string value BACKPROP is all that is currently implemented. With BACKPROP, you must define the parameter backprop_activation_loop.

backprop_activation_loop

This is a code snippet which is actually executed twice in different contexts: it should contain for each neuron in the group three commands, INIT_BACKPROP, STD_BACKPROP(wtind), PAUSE_BACKPROP, CONTINUE_BACKPROP and FINISH_BACKPROP. See the grouptypes file for examples.

As noted, some of these parameters contain C code. In order to avoid clashes in variable names, all names beginning with gann_ are considered reserved. The index i is defined at the beginning of each function and is not used by the compiler itself. The macros defined by the group compiler are

UOUT(i)

the ith unit output vector element.

UIN(i)

the ith unit inputs element.

NINGROUPS, NNINGROUP(i), IGROUPELEM(i,e)

These are defined only if n_igroups group parameter is defined and not equal to zero. NINGROUPS is the number of input groups, NNINGROUP(i) is the number of neurons in the input group i and IGROUPELEM(i,e) is the eth element in the input group i.

NNEURONS

The number of neurons. (taken from n_neurons group parameter which is evaluated at group creation time)

BUGS

The current implementation is inefficient: by forcing the use of IGROUPELEM vectorization and compiler optimization is hindered. I have not yet discovered a good fix for all this.

The whole thing should be modularized: the lattices as currently implemented are ugly hacks. An object oriented approach would be preferable.