Skip to content

Instantly share code, notes, and snippets.

@tony-o
Created March 15, 2016 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony-o/6e9634b0c43d22c44833 to your computer and use it in GitHub Desktop.
Save tony-o/6e9634b0c43d22c44833 to your computer and use it in GitHub Desktop.

output

tonyo@mbp:~/projects/perl6-perceptron$ perl6 -Ilib t/00-linetest.t
1..2
Perceptron[Str,Str].new(weights => [-0.730241661428426e0, -0.0568448253466738e0])
242.652261079551, 213.411496682069: 1 ?= -1?
not ok 1 - Negative test
chars requires a concrete string, but got null
  in sub proclaim at /Users/tonyo/.rakudobrew/moar-nom/install/share/perl6/sources/C712FE6969F786C9380D643DF17E85D06868219E line 519
  in sub ok at /Users/tonyo/.rakudobrew/moar-nom/install/share/perl6/sources/C712FE6969F786C9380D643DF17E85D06868219E line 100

# Looks like you planned 2 tests, but ran 1
# Looks like you failed 1 test of 1

script

use Perceptron;
use Trainer;
use Test;

plan 2;

my Trainer @a;
my Perceptron['x','y'] $p .=new;
my ($x, $y);

@a.append(
  Trainer.new(
    :inputs($x = 250 - 500.rand, $y = 250 - 500.rand), 
    :expected($y < (2*$x)+1 ?? 1 !! -1)
  )) for ^20000;

$p.perl.say;
.train($p) for @a;

while $y >= (2 * $x) + 1 {
  $x = 250 - 500.rand;
  $y = 250 - 500.rand;
}
say "$x, $y: { $p.feed($x, $y) } ?= -1?";

ok $p.feed($x, $y) == -1, 'Negative test';

while $y < (2 * $x) + 1 {
  $x = 250 - 500.rand;
  $y = 250 - 500.rand;
}

ok $p.feed($x, $y) == 1, 'Positive test';

done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment