Charles Colbourn > AI-NNFlex > AI::NNFlex::Backprop

Download:
ai-nnflex/AI-NNFlex-0.24.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source  

NAME ^

AI::NNFlex::Backprop - a fast, pure perl backprop Neural Net simulator

SYNOPSIS ^

 use AI::NNFlex::Backprop;

 my $network = AI::NNFlex::Backprop->new(config parameter=>value);

 $network->add_layer(nodes=>x,activationfunction=>'function');

 $network->init(); 



 use AI::NNFlex::Dataset;

 my $dataset = AI::NNFlex::Dataset->new([
                        [INPUTARRAY],[TARGETOUTPUT],
                        [INPUTARRAY],[TARGETOUTPUT]]);

 my $sqrError = 10;

 while ($sqrError >0.01)

 {

        $sqrError = $dataset->learn($network);

 }

 $network->lesion({'nodes'=>PROBABILITY,'connections'=>PROBABILITY});

 $network->dump_state(filename=>'badgers.wts');

 $network->load_state(filename=>'badgers.wts');

 my $outputsRef = $dataset->run($network);

 my $outputsRef = $network->output(layer=>2,round=>1);

DESCRIPTION ^

AI::NNFlex::Backprop is a class to generate feedforward, backpropagation neural nets. It inherits various constructs from AI::NNFlex & AI::NNFlex::Feedforward, but is documented here as a standalone.

The code should be simple enough to use for teaching purposes, but a simpler implementation of a simple backprop network is included in the example file bp.pl. This is derived from Phil Brierleys freely available java code at www.philbrierley.com.

AI::NNFlex::Backprop leans towards teaching NN and cognitive modelling applications. Future modules are likely to include more biologically plausible nets like DeVries & Principes Gamma model.

Full documentation for AI::NNFlex::Dataset can be found in the modules own perldoc. It's documented here for convenience only.

CONSTRUCTOR ^

AI::NNFlex::Backprop->new( parameter => value );

Parameters:

        randomweights=>MAXIMUM VALUE FOR INITIAL WEIGHT

        fixedweights=>WEIGHT TO USE FOR ALL CONNECTIONS

        debug=>[LIST OF CODES FOR MODULES TO DEBUG]

        learningrate=>the learning rate of the network

        momentum=>the momentum value (momentum learning only)

        round=>0 or 1 - 1 sets the network to round output values to
                nearest of 1, -1 or 0

        fahlmanconstant=>0.1

The following parameters are optional:

 randomweights

 fixedweights

 debug

 round

 momentum

 fahlmanconstant

If randomweights is not specified the network will default to a random value from 0 to 1.

If momentum is not specified the network will default to vanilla (non momentum) backprop.

The Fahlman constant modifies the slope of the error curve. 0.1 is the standard value for everything, and speeds the network up immensely. If no Fahlman constant is set, the network will default to 0.1

AI::NNFlex::Dataset

 new (  [[INPUT VALUES],[OUTPUT VALUES],
        [INPUT VALUES],[OUTPUT VALUES],..])

INPUT VALUES

These should be comma separated values. They can be applied to the network with ::run or ::learn

OUTPUT VALUES

These are the intended or target output values. Comma separated. These will be used by ::learn

METHODS ^

This is a short list of the main methods implemented in AI::NNFlex::Backprop.

AI::NNFlex::Backprop

add_layer

 Syntax:

 $network->add_layer(   nodes=>NUMBER OF NODES IN LAYER,
                        persistentactivation=>RETAIN ACTIVATION BETWEEN PASSES,
                        decay=>RATE OF ACTIVATION DECAY PER PASS,
                        randomactivation=>MAXIMUM STARTING ACTIVATION,
                        threshold=>NYI,
                        activationfunction=>"ACTIVATION FUNCTION",
                        errorfunction=>'ERROR TRANSFORMATION FUNCTION',
                        randomweights=>MAX VALUE OF STARTING WEIGHTS);

The activation function must be defined in AI::NNFlex::Mathlib. Valid predefined activation functions are tanh & linear.

The error transformation function defines a transform that is done on the error value. It must be a valid function in AI::NNFlex::Mathlib. Using a non linear transformation function on the error value can sometimes speed up training.

The following parameters are optional:

 persistentactivation

 decay

 randomactivation

 threshold

 errorfunction

 randomweights

init

 Syntax:

 $network->init();

Initialises connections between nodes, sets initial weights and loads external components. Implements connections backwards and forwards from each node in each layer to each node in the preceeding and following layers, and initialises weights values on all connections.

lesion

 $network->lesion ({'nodes'=>PROBABILITY,'connections'=>PROBABILITY})

 Damages the network.

PROBABILITY

A value between 0 and 1, denoting the probability of a given node or connection being damaged.

Note: this method may be called on a per network, per node or per layer basis using the appropriate object.

AN::NNFlex::Dataset

learn

 $dataset->learn($network)

'Teaches' the network the dataset using the networks defined learning algorithm. Returns sqrError;

run

 $dataset->run($network)

Runs the dataset through the network and returns a reference to an array of output patterns.

EXAMPLES ^

See the code in ./examples. For any given version of NNFlex, xor.pl will contain the latest functionality.

PREREQs ^

None. NNFlex::Backprop should run OK on any version of Perl 5 >.

ACKNOWLEDGEMENTS ^

Phil Brierley, for his excellent free java code, that solved my backprop problem

Dr Martin Le Voi, for help with concepts of NN in the early stages

Dr David Plaut, for help with the project that this code was originally intended for.

Graciliano M.Passos for suggestions & improved code (see SEE ALSO).

Dr Scott Fahlman, whose very readable paper 'An empirical study of learning speed in backpropagation networks' (1988) has driven many of the improvements made so far.

SEE ALSO ^

 AI::NNFlex

 AI::NNEasy - Developed by Graciliano M.Passos 
 Shares some common code with NNFlex. 

TODO ^

CHANGES ^

COPYRIGHT ^

Copyright (c) 2004-2005 Charles Colbourn. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

CONTACT ^

 charlesc@nnflex.g0n.net
syntax highlighting: