|
AI::NeuralNet::SOM - Perl extension for Kohonen Maps |
AI::NeuralNet::SOM - Perl extension for Kohonen Maps
use AI::NeuralNet::SOM::Rect;
my $nn = new AI::NeuralNet::SOM::Rect (output_dim => "5x6",
input_dim => 3);
$nn->initialize;
$nn->train (30,
[ 3, 2, 4 ],
[ -1, -1, -1 ],
[ 0, 4, -3]);
my @mes = $nn->train (30, ...); # learn about the smallest errors
# during training
print $nn->as_data; # dump the raw data print $nn->as_string; # prepare a somehow formatted string
use AI::NeuralNet::SOM::Torus; # similar to above
use AI::NeuralNet::SOM::Hexa;
my $nn = new AI::NeuralNet::SOM::Hexa (output_dim => 6,
input_dim => 4);
$nn->initialize ( [ 0, 0, 0, 0 ] ); # all get this value
$nn->value (3, 2, [ 1, 1, 1, 1 ]); # change value for a neuron print $nn->value (3, 2);
$nn->label (3, 2, 'Danger'); # add a label to the neuron print $nn->label (3, 2);
This package is a stripped down implementation of the Kohonen Maps (self organizing maps). It is NOT meant as demonstration or for use together with some visualisation software. And while it is not (yet) optimized for speed, some consideration has been given that it is not overly slow.
Particular emphasis has been given that the package plays nicely with others. So no use of files, no arcane dependencies, etc.
The basic idea is that the neural network consists of a 2-dimensional array of N-dimensional vectors. When the training is started these vectors may be complete random, but over time the network learns from the sample data, also N-dimensional vectors.
Slowly, the vectors in the network will try to approximate the sample vectors fed in. If in the sample vectors there were clusters, then these clusters will be neighbourhoods within the rectangle.
Technically, you have reduced your dimension from N to 2.
The constructor takes arguments:
input_dim : (mandatory, no default)learning_rate: (optional, default 0.1)sigma0: (optional, defaults to radius)NOTE: Do not choose 1 as the log function is used on this value.
Subclasses will (re)define some of these parameters and add others:
Example:
my $nn = new AI::NeuralNet::SOM::Rect (output_dim => "5x6",
input_dim => 3);
You need to initialize all vectors in the map before training. There are several options how this is done:
$nn->initialize ( [ 0, 0, 0 ] );
The training uses the list of sample vectors to make the network learn. Each vector is simply a reference to an array of values. Individual vectors are
The epoch parameter controls how many vectors are processed.
Example:
$nn->train (30,
[ 3, 2, 4 ],
[ -1, -1, -1 ],
[ 0, 4, -3]);
This method finds the best matching unit, i.e. that neuron which is closest to the vector passed in. The method returns the coordinates and the actual distance.
This method takes a number of vectors and produces the mean distance, i.e. the average error
which the SOM makes when finding the bmus for the vectors. At least one vector must be passed in.
Obviously, the longer you let your SOM be trained, the smaller the error should become.
Finds all neighbors of (X, Y) with a distance smaller than SIGMA. Returns a list reference of (X, Y, distance) triples.
Returns the output dimensions of the map as passed in at constructor time.
Returns the radius of the map. Different topologies interpret this differently.
This method returns a reference to the map data. See the appropriate subclass of the data representation.
$nn->value ($x, $y, $val)
Set or get the current vector value for a particular neuron. The neuron is addressed via its coordinates.
$nn->label ($x, $y, $label)
Set or get the label for a particular neuron. The neuron is addressed via its coordinates
This methods creates a pretty-print version of the current vectors.
This methods creates a string containing the raw vector data, row by row. This can be fed into gnuplot, for instance.
examples provided in the
distribution. It uses the PDL manpage (for speed and scalability, but the
results are not as good as I had thought.
examples. It uses
Storable to directly dump the data structure onto disk. Storage and
retrieval is quite fast.
input_dim you
specified and your vectors should be having.
Bugs should always be submitted via the CPAN bug tracker
L<http://rt.cpan.org/Public/Search/Simple.html?q=AI%3A%3ANeuralNet%3A%3ASOM>
http://www.ai-junkie.com/ann/som/som1.html
Robert Barta, <rho@devc.at>
Copyright (C) 2007 by Robert Barta
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
|
AI::NeuralNet::SOM - Perl extension for Kohonen Maps |