AI-ANN

 view release on metacpan or  search on metacpan

t/02_network_basic.t  view on Meta::CPAN

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

$network=new AI::ANN ('inputs'=>1, 'data'=>[{ iamanoutput => 1, inputs => {0 => 1}, neurons => {}}], 'maxvalue' => 10);

ok(defined $network, "new() works");
ok($network->isa("AI::ANN"), "Right class");

ok($out=$network->execute([1]), "executed and still alive");

is($#{$out}, 0, "execute() output for a single neuron is the right length");
is($out->[0], 1, "execute() output for a single neuron has the correct value");

($inputs, $neurons, $outputs) = $network->get_state();

is($#{$inputs}, 0, "get_state inputs is correct length");
is($inputs->[0], 1, "get_state inputs returns correct element 0");

is($#{$neurons}, 0, "get_state neurons is correct length");

t/02_network_basic.t  view on Meta::CPAN


is($#{$outputs}, 0, "get_state outputs is correct length");
is($outputs->[0], 1, "get_state outputs returns correct element 0");

$network=new AI::ANN ('inputs'=>1, 'data'=>[{ iamanoutput => 0, inputs => {0 => 2}, neurons => {}},
                       { iamanoutput => 1, inputs => {}, neurons => {0 => 2}}], 'maxvalue' => 10);

ok(defined $network, "new() works");
ok($network->isa("AI::ANN"), "Right class");

ok($out=$network->execute([1]), "executed and still alive");

is($#{$out}, 0, "execute() output for two neurons is the right length");
is($out->[0], 4, "execute() output for two neurons has the correct value");

($inputs, $neurons, $outputs) = $network->get_state();

is($#{$inputs}, 0, "get_state inputs is correct length");
is($inputs->[0], 1, "get_state inputs returns correct element 0");

is($#{$neurons}, 1, "get_state neurons is correct length");

t/03_evolver_basic.t  view on Meta::CPAN

# This test basically works by crossing a network with itself and making sure nothing changes

$network1=new AI::ANN ('inputs'=>1, 'data'=>[{ iamanoutput => 1, inputs => {0 => 1}, neurons => {}}]);
$network2=new AI::ANN ('inputs'=>1, 'data'=>[{ iamanoutput => 1, inputs => {0 => 1}, neurons => {}}]);

ok(defined $network1, "new() works");
ok($network1->isa("AI::ANN"), "Right class");
ok(defined $network2, "new() works");
ok($network2->isa("AI::ANN"), "Right class");

ok($out=$network1->execute([1]), "executed and still alive");

is($#{$out}, 0, "execute() output for a single neuron is the right length before crossover");
is($out->[0], 1, "execute() output for a single neuron has the correct value before crossover");

ok($out=$network2->execute([1]), "executed and still alive");

is($#{$out}, 0, "execute() output for a single neuron is the right length before crossover");
is($out->[0], 1, "execute() output for a single neuron has the correct value before crossover");

$evolver=new AI::ANN::Evolver ({});

ok(defined $evolver, "new() works");
ok($evolver->isa("AI::ANN::Evolver"), "Right class");

$network3=$evolver->crossover($network1, $network2);

ok(defined $network3, "crossover() works");
ok($network3->isa("AI::ANN"), "Right class");

ok($out=$network3->execute([1]), "executed and still alive");

is($#{$out}, 0, "execute() output for a single neuron is the right length after crossover");
is($out->[0], 1, "execute() output for a single neuron has the correct value after crossover");

($inputs, $neurons, $outputs) = $network3->get_state();

is($#{$inputs}, 0, "get_state inputs is correct length");
is($inputs->[0], 1, "get_state inputs returns correct element 0");

is($#{$neurons}, 0, "get_state neurons is correct length");

t/03_evolver_basic.t  view on Meta::CPAN

                            { iamanoutput => 1, inputs => {}, neurons => {0 => 2, 1 => 1}, eta_inputs => {}, eta_neurons => {0 => 0.4, 1 => 0.6}}, 
                            { iamanoutput => 1, inputs => {}, neurons => {0 => 3}, eta_inputs => {}, eta_neurons => {0 => 0.8}}]);
$network2=new AI::ANN ('inputs'=>1,
		   'data'=>[{ iamanoutput => 0, inputs => {0 => 1}, neurons => {}},
                            { iamanoutput => 0, inputs => {0 => 2}, neurons => {0 => 2}},
                            { iamanoutput => 1, inputs => {}, neurons => {0 => 3}}, 
                            { iamanoutput => 1, inputs => {}, neurons => {0 => 2, 1 => 1}}]);
ok(defined $network1, "new() works");
ok($network1->isa("AI::ANN"), "Right class");

ok($out=$network1->execute([1]), "executed and still alive");

is($#{$out}, 1, "execute() output is the right length");

($inputs, $neurons, $outputs) = $network1->get_state();

is($#{$inputs}, 0, "get_state inputs is correct length");
is($#{$neurons}, 3, "get_state neurons is correct length");
is($#{$outputs}, 1, "get_state outputs is correct length");

ok(defined $network2, "new() works");
ok($network2->isa("AI::ANN"), "Right class");

ok($out=$network2->execute([1]), "executed and still alive");

is($#{$out}, 1, "execute() output is the right length");

($inputs, $neurons, $outputs) = $network2->get_state();

is($#{$inputs}, 0, "get_state inputs is correct length");
is($#{$neurons}, 3, "get_state neurons is correct length");
is($#{$outputs}, 1, "get_state outputs is correct length");

$network3=$evolver->crossover($network1, $network2);

ok(defined $network3, "crossover() works");
ok($network3->isa("AI::ANN"), "Right class");

ok($out=$network3->execute([1]), "crossed over, executed and still alive");

is($#{$out}, 1, "execute() output after crossover is the right length");

($inputs, $neurons, $outputs) = $network3->get_state();

is($#{$inputs}, 0, "get_state inputs after crossover is correct length");
is($#{$neurons}, 3, "get_state neurons after crossover is correct length");
is($#{$outputs}, 1, "get_state outputs after crossover is correct length");

# Next, we'll test mutate

$network4=$evolver->mutate($network1);

ok(defined $network4, "mutate() works");
ok($network4->isa("AI::ANN"), "Right class");

ok($out=$network4->execute([1]), "mutated, executed and still alive");

is($#{$out}, 1, "execute() output after mutate is the right length");

($inputs, $neurons, $outputs) = $network4->get_state();

is($#{$inputs}, 0, "get_state inputs after mutate is correct length");
is($#{$neurons}, 3, "get_state neurons after mutate is correct length");
is($#{$outputs}, 1, "get_state outputs after mutate is correct length");

# Next, we'll test mutate_gaussian

$network5=$evolver->mutate_gaussian($network1);

ok(defined $network5, "mutate_gaussian() works");
ok($network5->isa("AI::ANN"), "Right class");

ok($out=$network5->execute([1]), "mutate_gaussiand, executed and still alive");

is($#{$out}, 1, "execute() output after mutate_gaussian is the right length");

($inputs, $neurons, $outputs) = $network5->get_state();

is($#{$inputs}, 0, "get_state inputs after mutate_gaussian is correct length");
is($#{$neurons}, 3, "get_state neurons after mutate_gaussian is correct length");
is($#{$outputs}, 1, "get_state outputs after mutate_gaussian is correct length");

t/10_network_integrity.t  view on Meta::CPAN


# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

$network=new AI::ANN ('inputs'=>1, 'data'=>[{ iamanoutput => 0, inputs => {0 => 2}, neurons => {}},
                       { iamanoutput => 1, inputs => {}, neurons => {0 => 2}}], 'maxvalue' => 10);

ok(defined $network, "new() works");
ok($network->isa("AI::ANN"), "Right class");

ok($out=$network->execute([1]), "executed and still alive");

is($#{$out}, 0, "execute() output for two neurons is the right length");
is($out->[0], 4, "execute() output for two neurons has the correct value");

$data = $network->get_internals();

$data->[1]->{'iamanoutput'} = 0;
$data->[1]->{'inputs'}->[0] = 8;
$data->[1]->{'neurons'}->[0] = 0;

ok($out=$network->execute([1]), "executed and still alive");

is($#{$out}, 0, "execute() output for two neurons is the right length");
is($out->[0], 4, "execute() output for two neurons has the correct value");



( run in 0.751 second using v1.01-cache-2.11-cpan-39bf76dae61 )