1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
From: Christian Kastner <ckk@kvr.at>
Date: Tue, 29 Sep 2015 13:49:26 +0200
Subject: Add an example
Add one of Vincenzo Di Massa's (the original author of the bindings) code
examples.
Taken from the original FANN source.
Last-Update: 2015-09-29
---
examples/simple_train.py | 22 ++++++++++++++++++++++
examples/xor.data | 9 +++++++++
2 files changed, 31 insertions(+)
create mode 100644 examples/simple_train.py
create mode 100644 examples/xor.data
diff --git a/examples/simple_train.py b/examples/simple_train.py
new file mode 100644
index 0000000..cc197d7
--- /dev/null
+++ b/examples/simple_train.py
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+from fann2 import libfann
+
+connection_rate = 1
+learning_rate = 0.7
+num_input = 2
+num_neurons_hidden = 4
+num_output = 1
+
+desired_error = 0.0001
+max_iterations = 100000
+iterations_between_reports = 1000
+
+ann = libfann.neural_net()
+ann.create_sparse_array(connection_rate, (num_input, num_neurons_hidden, num_output))
+ann.set_learning_rate(learning_rate)
+ann.set_activation_function_output(libfann.SIGMOID_SYMMETRIC_STEPWISE)
+
+ann.train_on_file("xor.data", max_iterations, iterations_between_reports, desired_error)
+
+ann.save("xor_float.net")
+
diff --git a/examples/xor.data b/examples/xor.data
new file mode 100644
index 0000000..e831fc6
--- /dev/null
+++ b/examples/xor.data
@@ -0,0 +1,9 @@
+4 2 1
+-1 -1
+-1
+-1 1
+1
+1 -1
+1
+1 1
+-1
|