AI-NeuralNet-FastSOM
view release on metacpan or search on metacpan
* \--Vector---+---NV
* \--NV
*
* References
* ==========
*
* Each of Rect, Map, Array, and Vector contains a member 'ref' which is
* an SV* pointing to an RV. The RV can be returned directly to perl-land
* after being blessed into its respective class.
*
* The RV references an SV containing an IV. The IV is set to the base
* address of its component structure. This is so the class code can know
* which instance of the class is being referred to on callback.
*
* The reference count of the SV has its initial reference count set to one,
* representing its parents ownership. If a parent dies or a perl-land
* reference is taken of any componenet, its reference count should
* be adjusted accordingly.
*
* When the count reaches zero perl will call the classes DESTROY method,
* at which point we can decrease the reference count on each child and
* free the component structure.
*
* The intent of all this reference count tom-foolery is to keep the
* component structures from disappearing from underneath perl-land
t/orig/som.t view on Meta::CPAN
######
#use Data::Dumper;
{
use AI::NeuralNet::FastSOM::Rect; # any non-abstract subclass should do
my $nn = new AI::NeuralNet::FastSOM::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::FastSOM::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);
t/orig/torus.t view on Meta::CPAN
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::FastSOM::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');
}
{
ok( $v != $a, 'vector unique' );
my $v2 = $nn3->map->[0]->[0];
is( $v, $v2, 'vector eq' );
my $v3 = $nn2->map->[0][0];
is( $v, $v3, 'vector shorter' );
my $m = $nn->map;
$m->[0][0][0] = 3.245;
is( $m->[0][0][0], 3.245, 'element set' );
$m->[0][0][0] = 1.25;
is( $m->[0][0][0], 1.25, 'element reset' );
$m->[0][0][1] = 4.8;
is( $m->[0][0][1], 4.8, 'element set z' );
$m->[0][0][1] = 2.6;
is( $m->[0][0][1], 2.6, 'element reset z' );
$m->[0][1][0] = 8.9;
is( $m->[0][1][0], 8.9, 'element set y' );
$m->[0][1][0] = 1.2;
is( $m->[0][1][0], 1.2, 'element reset y' );
$m->[1][0][0] = 5.4;
is( $m->[1][0][0], 5.4, 'element set z' );
$m->[1][0][0] = 3.23;
is( $m->[1][0][0], 3.23, 'element reset z');
$m->[4][5][2] = 2.29;
is( $m->[4][5][2], 2.29, 'last element set' );
is( $m->[-1][5][2], 2.29, 'negative x' );
is( $m->[4][-1][2], 2.29, 'negative y' );
is( $m->[4][5][-1], 2.29, 'negative z' );
is( $m->[-1][-1][-1], 2.29, 'negative all' );
}
{
my $nn = AI::NeuralNet::FastSOM::Rect->new(
output_dim => '5x6',
input_dim => 3
my $nn = AI::NeuralNet::FastSOM::Rect->new(
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'
);
# unsupported, for now (rik)
# $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 = AI::NeuralNet::FastSOM::Rect->new(
output_dim => "5x6",
input_dim => 3,
);
$nn->initialize;
my @vs = ([ 3, 2, 4 ], [ -1, -1, -1 ], [ 0, 4, -3]);
is( $nn->output_dim, "5x6", 'output dim' );
}
{
my $nn = AI::NeuralNet::FastSOM::Torus->new(
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 0.889 second using v1.01-cache-2.11-cpan-49f99fa48dc )