AI-NeuralNet-SOM
view release on metacpan or search on metacpan
0.06 Fri May 23 10:23:29 CEST 2008
- fix: label '0' in label method (tom fawcett)
- fix: value '0' in value method (rho)
0.05 Mi 16. Jan 20:58:19 CET 2008
- improvement of documentation
- training now holds sigma and l constant during an epoch, but applies ALL vectors (exactly once)
0.04 17. Jun CEST 2007
- added labels get/set
- added mean_error function
0.03 Do 14. Jun 21:07:54 CEST 2007
- added output_dim method
- added ::Torus subclass of ::Rect
0.02 Sa 9. Jun 17:55:23 CEST 2007
- split ::SOM.pm into ::SOM::Rect and ::SOM::Hexa
- added more features for initialization
- factored out vector computation into ::SOM::Utils
lib/AI/NeuralNet/SOM.pm view on Meta::CPAN
overly slow.
Particular emphasis has been given that the package plays nicely with
others. So no use of files, no arcane dependencies, etc.
=head2 Scenario
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 completely random, but over time the network learns
from the sample data, which is a set of 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 (or
whatever topology you are using).
Technically, you have reduced your dimension from N to 2.
=head1 INTERFACE
######
use Data::Dumper;
{
use AI::NeuralNet::SOM::Rect; # any non-abstract subclass should do
my $nn = new AI::NeuralNet::SOM::Rect (output_dim => "5x6",
input_dim => 3,
);
$nn->value ( 1, 1, [ 1, 1, 1 ] );
ok (eq_array ($nn->value ( 1, 1),
[ 1, 1, 1 ]), 'value set/get');
$nn->label ( 1, 1, 'rumsti' );
is ($nn->label ( 1, 1), 'rumsti', 'label set/get');
is ($nn->label ( 1, 0), undef, 'label set/get');
}
{
my $nn = new AI::NeuralNet::SOM::Rect (output_dim => "5x6",
input_dim => 3);
$nn->initialize;
my @vs = ([ 3, 2, 4 ], [ -1, -1, -1 ], [ 0, 4, -3]);
my $me = $nn->mean_error (@vs);
is ($nn->{_Y}, 6, 'Y');
is ($nn->{_Z}, 3, 'Z');
is ($nn->radius, 2.5, 'radius');
is ($nn->output_dim, "5x6", 'output dim');
}
{
my $nn = new AI::NeuralNet::SOM::Torus (output_dim => "5x6",
input_dim => 3);
ok (eq_set ( $nn->neighbors (1, 0, 0),
[
[ 0, 0, '0' ],
[ 0, 1, '1' ],
[ 0, 5, '1' ],
[ 1, 0, '1' ],
[ 4, 0, '1' ]
]), 'neighbors 4+1');
ok (eq_set ( $nn->neighbors (1, 3, 2),
[
[ 2, 2, '1' ],
[ 3, 1, '1' ],
[ 3, 2, '0' ],
[ 3, 3, '1' ],
[ 4, 2, '1' ]
]), 'neighbors 4+1');
}
{
( run in 1.323 second using v1.01-cache-2.11-cpan-49f99fa48dc )