[libfann] 213/242: Updated pyfann to work with fann 2.0 (unfinished)

Christian Kastner chrisk-guest at moszumanska.debian.org
Sat Oct 4 21:10:47 UTC 2014


This is an automated email from the git hooks/post-receive script.

chrisk-guest pushed a commit to tag Version2_0_0
in repository libfann.

commit 669d35d2793f857ea17790c61ba1b775c5243ef5
Author: Vincenzo Di Massa <hawk at hawk.linuxpratico.net>
Date:   Sat Dec 3 01:22:43 2005 +0000

    Updated pyfann to work with fann 2.0 (unfinished)
---
 python/INSTALL                  | 14 ++++++++++----
 python/Makefile                 |  7 ++++++-
 python/README                   |  7 ++++++-
 python/examples/mushroom.py     | 12 +++++++-----
 python/examples/simple_train.py |  8 ++++----
 python/pyfann/Makefile          |  2 +-
 python/pyfann/fann.py           |  4 ++--
 python/pyfann/pyfann.i          | 10 ++++++++++
 python/setup.py                 |  2 ++
 9 files changed, 48 insertions(+), 18 deletions(-)

diff --git a/python/INSTALL b/python/INSTALL
index 2783d0e..0f55b1f 100644
--- a/python/INSTALL
+++ b/python/INSTALL
@@ -3,18 +3,24 @@ INSTRUCTIONS
 
 PREREQUISITES
 ^^^^^^^^^^^^^
-Make sure to make and install the fann library first. 
+Make sure you can make and install the fann library first. 
 You are required to have swig and python development files 
 installed. After you compiled the fann library...
 
 
 
-BUILD AND INSTALL USING DISTUTILS 
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-run the following command as root
+BUILDING AND INSTALLING USING MAKE (preferred)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+run the following commands as root
 
 # make
+# make install
+
+BUILDING AND INSTALLING USING DISTUTILS (second alternative)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+run the following command as root
 
+# python setyp.py install
 
 ########## ** ** ** ** ** ** ** ** ** ** ** ** ** ** #########
 ####### The wrapper should be installed using distutils #######
diff --git a/python/Makefile b/python/Makefile
index 1dd55bd..fb8e58e 100644
--- a/python/Makefile
+++ b/python/Makefile
@@ -3,7 +3,7 @@
 
 ROOT=/
 
-all: install
+all: build
 
 linux:
 	@(cd pyfann && make)
@@ -11,6 +11,7 @@ linux:
 clean:
 	@(cd pyfann && make clean)
 	@rm -fr dist build setup.pyc
+	@rm -fr examples/{nets,pyfann/}
 
 msvc:
 	@(cd pyfann && make -f makefile.msvc)
@@ -27,3 +28,7 @@ install: build
 ../Makefile:
 	@(cd .. && ./configure)
 
+test: build
+	@-mkdir examples/nets
+	@python setup.py install --install-lib examples 
+	@cd examples && python simple_train.py && python mushroom.py
diff --git a/python/README b/python/README
index e86f63a..27b1290 100644
--- a/python/README
+++ b/python/README
@@ -2,11 +2,16 @@ This python binding is provided by Vincenzo Di Massa <hawk.it at tiscalinet.it>
 and Gil Megidish <gil at megidish.net>
 
 DESCRIPTION
-Using this wrapper it is possible tu use libfann from python scripts
+Using this wrapper it is possible to use libfann from python scripts.
 
 USAGE
 Just import pyfan.fann.
 
+TESTING
+To test the python bindings type 
+$ make test
+to build the library and execute example scripts in the example directory.
+
 BUILDING
 see INSTALL
 
diff --git a/python/examples/mushroom.py b/python/examples/mushroom.py
index b4160cc..c8c347d 100755
--- a/python/examples/mushroom.py
+++ b/python/examples/mushroom.py
@@ -1,5 +1,7 @@
 #!/usr/bin/python
-import fann
+import os
+import sys
+from pyfann import fann
 
 def print_callback(epochs, error):
 	print "Epochs     %8d. Current MSE-Error: %.10f\n" % (epochs, error)
@@ -15,8 +17,8 @@ iterations_between_reports = 1
 
 # create training data, and ann object
 print "Creating network."	
-train_data = fann.read_train_from_file("datasets/mushroom.train")
-ann = fann.create(connection_rate, learning_rate, (train_data.get_num_input(), num_neurons_hidden, train_data.get_num_output()))
+train_data = fann.read_train_from_file(os.path.join("..","..","benchmarks","datasets","mushroom.train"))
+ann = fann.create(connection_rate, (train_data.get_num_input(), num_neurons_hidden, train_data.get_num_output()))
 
 # start training the network
 print "Training network"
@@ -28,7 +30,7 @@ ann.train_on_data(train_data, max_iterations, iterations_between_reports, desire
 	
 # test outcome
 print "Testing network"
-test_data = fann.read_train_from_file("datasets/mushroom.test")
+test_data = fann.read_train_from_file(os.path.join("..","..","benchmarks","datasets","mushroom.test"))
 
 ann.reset_MSE()
 for i in range(test_data.get_num_data()):
@@ -38,5 +40,5 @@ print "MSE error on test data: %f" % ann.get_MSE()
 
 # save network to disk
 print "Saving network"
-ann.save("mushroom_float.net")
+ann.save(os.path.join("nets","mushroom_float.net"))
 
diff --git a/python/examples/simple_train.py b/python/examples/simple_train.py
index 30c21e2..10e224b 100755
--- a/python/examples/simple_train.py
+++ b/python/examples/simple_train.py
@@ -1,5 +1,5 @@
 #!/usr/bin/python
-import fann
+from pyfann import fann
 
 connection_rate = 1
 learning_rate = 0.7
@@ -11,10 +11,10 @@ desired_error = 0.0001
 max_iterations = 100000
 iterations_between_reports = 1000
 
-ann = fann.create(connection_rate, learning_rate, (num_input, num_neurons_hidden, num_output))
+ann = fann.create(connection_rate, (num_input, num_neurons_hidden, num_output))
 ann.set_activation_function_output(fann.SIGMOID_SYMMETRIC_STEPWISE)
 
-ann.train_on_file("datasets/xor.data", max_iterations, iterations_between_reports, desired_error)
+ann.train_on_file("../../examples/xor.data", max_iterations, iterations_between_reports, desired_error)
 
-ann.save("xor_float.net")
+ann.save("nets/xor_float.net")
 
diff --git a/python/pyfann/Makefile b/python/pyfann/Makefile
index 562f366..ec37fc4 100644
--- a/python/pyfann/Makefile
+++ b/python/pyfann/Makefile
@@ -19,4 +19,4 @@ pyfann_wrap.c: pyfann.i
 	swig -python $<
 
 clean:
-	rm -f $(TARGETS) *_wrap.* fann_helper.o fann.pyc *.so libfann.*
+	rm -f $(TARGETS) *_wrap.* fann_helper.o *.py{c,o} *.so libfann.*
diff --git a/python/pyfann/fann.py b/python/pyfann/fann.py
index a472b48..c778ec9 100644
--- a/python/pyfann/fann.py
+++ b/python/pyfann/fann.py
@@ -313,7 +313,7 @@ class train_class:
         outcome = libfann.fann_duplicate_train_data(self.__train_dat)
         return train_class(outcome)
 
-def create(connection_rate, learning_rate, layers):
+def create(connRate, layers):
     """
     Constructs a backpropagation neural network, from an connection rate,
     a learning rate, and number of neurons in each layer.
@@ -326,7 +326,7 @@ def create(connection_rate, learning_rate, layers):
     and this bias neuron will be connected to all neurons in the next layer.
     When running the network, the bias nodes always emits 1
     """
-    ann = libfann.fann_create_array(connection_rate, learning_rate, len(layers), layers)
+    ann = libfann.fann_create_sparse_array(connRate,len(layers), layers)
     if libfann.fann_is_NULL(ann):
         return None # probably won't happen
     return fann_class(ann)
diff --git a/python/pyfann/pyfann.i b/python/pyfann/pyfann.i
index a70d4fc..04a6708 100644
--- a/python/pyfann/pyfann.i
+++ b/python/pyfann/pyfann.i
@@ -5,6 +5,12 @@
 
 %{
 #include "fann.h"
+#include "fann_io.h"
+#include "fann_train.h"
+#include "fann_data.h"
+#include "fann_cascade.h"
+#include "fann_error.h"
+#include "fann_activation.h"
 %}
 
 %define CHECKED_FLOAT_ARRAY(typemap_name, expected_length)
@@ -87,6 +93,10 @@ typedef double fann_type;
 %include "../../src/include/fann.h"
 %include "../../src/include/fann_data.h"
 %include "../../src/include/fann_activation.h"
+%include "../../src/include/fann_train.h"
+%include "../../src/include/fann_io.h"
+%include "../../src/include/fann_cascade.h"
+%include "../../src/include/fann_error.h"
 
 // Helper functions
 PyObject* fann_run2(struct fann *ann, fann_type *input);
diff --git a/python/setup.py b/python/setup.py
index f389d42..0eb3090 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -1,3 +1,5 @@
+#!/usr/bin/python
+
 from distutils.core import setup, Extension
 import glob
 #from compiler.pycodegen import compileFile

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/libfann.git



More information about the debian-science-commits mailing list