aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/fann.rb
diff options
context:
space:
mode:
authorAdam Vandenberg2012-06-27 08:45:36 -0700
committerAdam Vandenberg2012-06-27 08:45:36 -0700
commitdade22f69a8b695f8cf7b2cc86fcfa071cde059a (patch)
treec641b0680d37765ce13032d7e7497f8a69dbdefa /Library/Formula/fann.rb
parent9fee38b0c93c6560f50f903f9ec5e873ce59241d (diff)
downloadhomebrew-dade22f69a8b695f8cf7b2cc86fcfa071cde059a.tar.bz2
fann: add test
Diffstat (limited to 'Library/Formula/fann.rb')
-rw-r--r--Library/Formula/fann.rb45
1 files changed, 44 insertions, 1 deletions
diff --git a/Library/Formula/fann.rb b/Library/Formula/fann.rb
index 82e706bd3..08c0f0a94 100644
--- a/Library/Formula/fann.rb
+++ b/Library/Formula/fann.rb
@@ -3,7 +3,7 @@ require 'formula'
class Fann < Formula
homepage 'http://leenissen.dk/fann/wp/'
url 'http://downloads.sourceforge.net/project/fann/fann/2.2.0/FANN-2.2.0-Source.tar.gz'
- md5 'c9d6c8da5bb70276352a1718a668562c'
+ sha1 'ff8341e4104bdbc0f3ab7ad39aef33285f8512d4'
depends_on 'cmake' => :build
@@ -11,4 +11,47 @@ class Fann < Formula
system "cmake", ".", *std_cmake_args
system "make install"
end
+
+ def test
+ mktemp do
+ (Pathname.pwd/'xor.data').write <<-EOS.undent
+ 4 2 1
+ -1 -1
+ -1
+ -1 1
+ 1
+ 1 -1
+ 1
+ 1 1
+ -1
+ EOS
+
+ (Pathname.pwd/'test.c').write <<-EOS.undent
+ #include "fann.h"
+ int main()
+ {
+ const unsigned int num_input = 2;
+ const unsigned int num_output = 1;
+ const unsigned int num_layers = 3;
+ const unsigned int num_neurons_hidden = 3;
+ const float desired_error = (const float) 0.001;
+ const unsigned int max_epochs = 500000;
+ const unsigned int epochs_between_reports = 1000;
+ struct fann *ann = fann_create_standard(num_layers, num_input,
+ num_neurons_hidden, num_output);
+ fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
+ fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);
+ fann_train_on_file(ann, "xor.data", max_epochs,
+ epochs_between_reports, desired_error);
+ fann_save(ann, "xor_float.net");
+ fann_destroy(ann);
+ return 0;
+ }
+ EOS
+ system ENV.cc, "-o", "test", "test.c", "-lfann"
+ system "./test"
+ system "cat xor_float.net"
+ puts
+ end
+ end
end