[libfann] 161/242: added python files

Christian Kastner chrisk-guest at moszumanska.debian.org
Sat Oct 4 21:10:38 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 e75719473eb620b7db8796f42b62080d71f91791
Author: Steffen Nissen <lukesky at diku.dk>
Date:   Sat Oct 9 11:09:37 2004 +0000

    added python files
---
 python/Makefile                 |  20 --
 python/README                   |  25 ++-
 python/__init__.py              |  11 +
 python/build.bat                |   3 +
 python/examples/mushroom.py     |  48 +++++
 python/examples/simple_train.py |  20 ++
 python/fann.py                  | 384 +++++++++++++++++++++++++++++++++
 python/fann_helper.c            |  96 ++++++---
 python/{fann.i => libfann.i}    | 162 +++++++-------
 python/libfann.py               | 459 ++++++++++++++++++++++++++++++++++++++++
 python/libfann.pyc              | Bin 0 -> 26911 bytes
 python/makefile.gnu             |  21 ++
 python/makefile.msvc            |  23 ++
 python/setup.py                 |  69 ++++++
 python/simple_train.py          |  20 --
 15 files changed, 1209 insertions(+), 152 deletions(-)

diff --git a/python/Makefile b/python/Makefile
deleted file mode 100644
index d2e4cac..0000000
--- a/python/Makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-# This makefile is on purpose not made with configure, to show how to use the library
-# The make file requires that the fann library is installed (see ../README)
-
-TARGETS = _fann.so 
-
-all: $(TARGETS)
-
-_%.so: %_wrap.o
-	gcc -shared $< -lfann -o $@ 
-
-%.o: %.c 
-	gcc -c -fpic $< -I/usr/include/python2.3/
-
-%_wrap.c: %.i 
-	swig -python $<
-
-
-
-clean:
-	rm -f $(TARGETS) *_wrap.* fann.py fann.pyc xor_float.net *~
diff --git a/python/README b/python/README
index 8b4bb8e..31073fd 100644
--- a/python/README
+++ b/python/README
@@ -1,13 +1,26 @@
 This python binding is provided by Vincenzo Di Massa <hawk.it at tiscalinet.it>
+and Gil Megidish <gil at megidish.net>
 
 MAKE
-Make sure to make and install the fann library first.
-Make sure that you have swig and python development files installed.
-Perhaps change the include directory of python.
-Then run 'make' to compile.
+Make sure to make the fann library first. You are required to have
+swig and python development files installed. After you compiled the
+fann library, run make with the apropriate makefile (gnu or msvc.) 
+Running build.bat will create a distribution for Windows platform. For
+that, you will need py2exe installed.
 
-INSTALL
-Copy the generated _fann.so and fann.py files to pyhon modules or into working directory.
+NOTE
+Two makefiles are provided. The GNU makefile will create a shared object
+for use in GNU/cygwin environments. The MSVC makefile will create a dll
+for the official Python distribution. Importing a dll made with cygwin
+in a standard distribution will cause python to hang.
+
+ANOTHER NOTE
+MSVC makefile does not compile fann sources by itself. This is done, as
+of the moment, by compiling them manually. This should go into the setup.py,
+as python supports compilation of C code, using extension tags. Due the
+demand of this release, it has been postponed to a future version. One last
+note, there isn't really a need for libfann.py. It will be removed next
+version.
 
 USAGE
 Just import fann.
diff --git a/python/__init__.py b/python/__init__.py
new file mode 100755
index 0000000..2fed0eb
--- /dev/null
+++ b/python/__init__.py
@@ -0,0 +1,11 @@
+#
+# Fast Artificial Neural Network library for Python
+#
+# package placeholder
+#
+# Copyright (c) 2004 by Gil Megidish
+#
+# See the README file for information on usage and redistribution.
+#
+
+# wee!
diff --git a/python/build.bat b/python/build.bat
new file mode 100755
index 0000000..83b1bb3
--- /dev/null
+++ b/python/build.bat
@@ -0,0 +1,3 @@
+deltree build
+deltree dist
+c:\python23\python setup.py bdist_wininst
diff --git a/python/examples/mushroom.py b/python/examples/mushroom.py
new file mode 100755
index 0000000..17f2055
--- /dev/null
+++ b/python/examples/mushroom.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+import fann
+
+def print_callback(epochs, error):
+	print "Epochs     %8d. Current MSE-Error: %.10f\n" % (epochs, error)
+	return 0
+
+# initialize network parameters
+connection_rate = 1
+learning_rate = 0.7
+num_neurons_hidden = 32
+desired_error = 0.000001
+max_iterations = 300
+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()))
+
+# start training the network
+print "Training network"
+ann.set_activation_function_hidden(fann.FANN_SIGMOID_SYMMETRIC_STEPWISE)
+ann.set_activation_function_output(fann.FANN_SIGMOID_STEPWISE)
+ann.set_training_algorithm(fann.FANN_TRAIN_INCREMENTAL)
+	
+ann.train_on_data(train_data, max_iterations, iterations_between_reports, desired_error)
+	
+# test outcome
+print "Testing network"
+test_data = fann.read_train_from_file("datasets/mushroom.test")
+
+ann.reset_MSE()
+for i in range(test_data.get_num_data()):
+    ann.test(test_data.get_input(i), test_data.get_output(i))
+
+print "MSE error on test data: %f" % ann.get_MSE()
+
+# save network to disk
+print "Saving network"
+ann.save("mushroom_float.net")
+
+# blow it all up
+print "Cleaning up."
+ann.destroy()
+test_data.destroy()
+train_data.destroy()
+
diff --git a/python/examples/simple_train.py b/python/examples/simple_train.py
new file mode 100755
index 0000000..946873a
--- /dev/null
+++ b/python/examples/simple_train.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+import fann
+
+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 = fann.create(connection_rate, learning_rate, (num_input, num_neurons_hidden, num_output))
+
+ann.train_on_file("datasets/xor.data", max_iterations, iterations_between_reports, desired_error)
+
+ann.save("xor_float.net")
+
+ann.destroy()
diff --git a/python/fann.py b/python/fann.py
new file mode 100755
index 0000000..7711e30
--- /dev/null
+++ b/python/fann.py
@@ -0,0 +1,384 @@
+"""
+Fast Artificial Neural Network Library (fann)
+Copyright (C) 2004 Steffen Nissen (lukesky at diku.dk)
+
+Python object by Gil Megidish, 2004
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+"""
+
+import libfann
+
+# Activation function
+FANN_LINEAR = 0
+FANN_THRESHOLD = 1
+FANN_THRESHOLD_SYMMETRIC = 2
+FANN_SIGMOID = 3
+FANN_SIGMOID_STEPWISE = 4                # default
+FANN_SIGMOID_SYMMETRIC = 5
+FANN_SIGMOID_SYMMETRIC_STEPWISE = 6
+FANN_GAUSSIAN = 7
+FANN_GAUSSIAN_STEPWISE = 8
+FANN_ELLIOT = 9                          # not implemented yet
+FANN_ELLIOT_SYMMETRIC = 10               # not implemented yet
+
+# Training algorithm
+FANN_TRAIN_INCREMENTAL = 0
+FANN_TRAIN_BATCH = 1
+FANN_TRAIN_RPROP = 2
+FANN_TRAIN_QUICKPROP = 3
+
+class fann_class:
+
+    def __init__(self, ann):
+        self.__ann = ann
+    
+    def get_native_object(self):
+        return self.__train_data
+
+    def run(self, input):
+        """
+        Runs a input through the network, and returns the output.
+        """
+        return libfann.fann_run(self.__ann, input)
+
+    def destroy(self):
+        """ 
+        Destructs the entire network.
+        Be sure to call this function after finished using the network.
+        """
+        libfann.fann_destroy(self.__ann)
+
+    def randomize_weights(self, min_weight, max_weight):
+        """
+        Randomize weights (from the beginning the weights are random between -0.1 and 0.1)
+        """
+        libfann.fann_randomize_weights(self.__ann, min_weight, max_weight)
+
+    def save(self, filename):
+        """
+        Save the entire network to a configuration file.
+        """
+        libfann.fann_save(self.__ann, filename)
+
+    def save_to_fixed(self, filename):
+        """
+        Saves the entire network to a configuration file.
+        But it is saved in fixed point format no matter which
+        format it is currently in.
+
+        This is usefull for training a network in floating points,
+        and then later executing it in fixed point.
+
+        The function returns the bit position of the fix point, which
+        can be used to find out how accurate the fixed point network will be.
+        A high value indicates high precision, and a low value indicates low
+        precision.
+
+        A negative value indicates very low precision, and a very
+        strong possibility for overflow.
+        (the actual fix point will be set to 0, since a negative
+        fix point does not make sence).
+
+        Generally, a fix point lower than 6 is bad, and should be avoided.
+        The best way to avoid this, is to have less connections to each neuron,
+        or just less neurons in each layer.
+
+        The fixed point use of this network is only intended for use on machines that
+        have no floating point processor, like an iPAQ. On normal computers the floating
+        point version is actually faster.
+        """
+        return libfann.fann_save_to_fixed(self.__ann, filename)
+
+    def train(self, input, desired_output):
+        """
+        Train one iteration with a set of inputs, and a set of desired outputs.
+        """
+	libfann.fann_train(self.__ann, input, desired_output)
+
+    def test(self, input, output):
+        """
+        Test with a set of inputs, and a set of desired outputs.
+        This operation updates the mean square error, but does not
+        change the network in any way.
+        """
+        libfann.fann_test(self.__ann, input, output)
+
+    def get_MSE(self):
+        """
+        Reads the mean square error from the network.
+        """
+        return libfann.fann_get_MSE(self.__ann)
+
+    def reset_error(self):
+        """
+        Resets the mean square error from the network.
+        (obsolete will be removed at some point, use fann_reset_MSE)
+        """
+        libfann.fann_reset_error(self.__ann)
+
+    def reset_MSE(self):
+        """
+        Resets the mean square error from the network.
+        """
+        libfann.fann_reset_MSE(self.__ann)
+
+    def get_num_input(self):
+        """
+        Get the number of input neurons.
+        """
+        return libfann.fann_get_num_input(self.__ann)
+
+    def get_num_output(self):
+        """
+        Get the number of output neurons.
+        """
+        return libfann.fann_get_num_output(self.__ann)
+
+    def get_total_neurons(self):
+        """
+        Get the total number of neurons in the entire network.
+        """
+        return libfann.fann_get_total_neurons(self.__ann)
+
+    def get_total_connections(self):
+        """
+        Get the total number of connections in the entire network.
+        """
+        return libfann.fann_get_total_connections(self.__ann)
+
+    def get_learning_rate(self):
+        """
+        Get the learning rate. 
+        """
+        return libfann.fann_get_learning_rate(self.__ann)
+
+    def set_learning_rate(self, learning_rate):
+        """
+        Set the learning rate.
+        """
+        return libfann.fann_set_learning_rate(self.__ann, learning_rate)
+
+    def train_on_file(self, filename, max_iterations, iterations_between_reports, desired_error):
+        libfann.fann_train_on_file(self.__ann, filename, max_iterations, iterations_between_reports, desired_error)
+
+    def get_activation_function_hidden(self):
+        """
+        Get the activation function used in the hidden layers.
+        """
+        return libfann.fann_get_activation_function_hidden(self.__ann)
+
+    def set_activation_function_hidden(self, activation_function):
+        """
+        Set the activation function for the hidden layers.
+        """
+        libfann.fann_set_activation_function_hidden(self.__ann, activation_function)
+
+    def get_activation_function_output(self):
+        """
+        Get the activation function used in the output layer.
+        """
+        return libfann.fann_get_activation_function_output(self.__ann)
+
+    def set_activation_function_output(self, activation_function):
+        """
+        Set the activation function for the output layer.
+        """
+        libfann.fann_set_activation_function_output(self.__ann, activation_function)
+
+    def get_activation_hidden_steepness(self):
+        """
+        Get the steepness parameter for the sigmoid function used in the hidden layers.
+        """
+        return libfann.get_activation_hidden_steepness(self.__ann)
+
+    def set_activation_hidden_steepness(self, steepness):
+        """
+        Set the steepness of the sigmoid function used in the hidden layers.
+        Only usefull if sigmoid function is used in the hidden layers (default 0.5).
+        """
+        libfann.fann_set_activation_hidden_steepness(self.__ann, steepness)
+
+    def get_activation_output_steepness(self):
+        """
+        Get the steepness parameter for the sigmoid function used in the output layer.
+        """
+        return libfann.fann_get_activation_output_steepness(self.__ann)
+
+    def set_activation_output_steepness(self, steepness):
+        """
+        Set the steepness of the sigmoid function used in the output layer.
+        Only usefull if sigmoid function is used in the output layer (default 0.5).
+        """
+        libfann.fann_set_activation_output_steepness(self.__ann, steepness)
+
+    def train_on_data(self, data, max_epochs, epochs_between_reports, desired_error):
+        """
+        Trains on an entire dataset, for a maximum of max_epochs
+        epochs or until mean square error is lower than desired_error.
+        Reports about the progress is given every
+        epochs_between_reports epochs.
+        If epochs_between_reports is zero, no reports are given.
+        """
+        libfann.fann_train_on_data(self.__ann, data.get_native_object(), max_epochs, epochs_between_reports, desired_error)
+
+    def train_on_file(self, filename, max_epochs, epochs_between_reports, desired_error):
+        """
+        Does the same as train_on_data, but reads the data directly from a file.
+        """
+        libfann.fann_train_on_file(self.__ann, filename, max_epochs, epochs_between_reports, desired_error)
+
+    def print_connections(self):
+        """
+        Print out which connections there are in the ann
+        """
+        libfann.fann_print_connections(self.__ann)
+ 
+    def print_parameters(self):
+        """
+        Prints all of the parameters and options of the ANN
+        """
+        libfann.fann_print_parameters(self.__ann)
+
+    def	get_training_algorithm(self):
+        """
+        Get the training algorithm.
+        """
+        return libfann.fann_get_training_algorithm(self.__ann)
+
+    def set_training_algorithm(self, training_algorithm):
+        """
+        Set the training algorithm.
+        """
+        libfann.fann_set_training_algorithm(self.__ann, training_algorithm)
+
+## end of class fann_class ##
+
+class train_class:
+
+    def __init__(self, train_data):
+        self.__train_data = train_data
+
+    def get_native_object(self):
+        return self.__train_data
+
+    def get_num_data(self):
+        return self.__train_data.num_data
+
+    def get_num_input(self):
+        return self.__train_data.num_input
+
+    def get_num_output(self):
+        return self.__train_data.num_output
+
+    def get_input(self, index):
+	return libfann.get_train_data_input(self.__train_data, index);
+
+    def get_output(self, index):
+	return libfann.get_train_data_output(self.__train_data, index);
+
+    def destroy(self):
+        """
+        Destructs the training data
+        Be sure to call this function after finished using the training data.
+        """
+        libfann.fann_destroy_train(self.__train_data)
+
+    def shuffle(self):
+        """
+        Shuffles training data, randomizing the order
+        """
+        libfann.fann_shuffle_train_data(self.__train_data)
+
+    def save(self, filename):
+        """
+        Save the training structure to a file.
+        """
+        libfann.fann_save_train(self.__train_data, filename)
+
+    def save_to_fixed(self, filename):
+        """
+        Saves the training structure to a fixed point data file.
+        (Very usefull for testing the quality of a fixed point network).
+        """
+        libfann.fann_save_train_to_fixed(self.__train_data, filename)
+
+    def merge(self, other):
+        """
+        Merges training data into a single struct
+        """
+        outcome = libfann.fann_merge_train_data(self.__train_data, other.get_native_object())
+        self.destroy()
+        self.__train_data = outcome
+        return self
+
+    def duplicate(self):
+        """
+        Return a copy of a fann_train_data struct
+        """
+        outcome = libfann.fann_duplicate_train_data(self.__train_dat)
+        return train_class(outcome)
+
+def create(connection_rate, learning_rate, layers):
+    """
+    Constructs a backpropagation neural network, from an connection rate,
+    a learning rate, and number of neurons in each layer.
+
+    The connection rate controls how many connections there will be in the
+    network. If the connection rate is set to 1, the network will be fully
+    connected, but if it is set to 0.5 only half of the connections will be set.
+
+    There will be a bias neuron in each layer (except the output layer),
+    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)
+    return fann_class(ann)
+
+def create_from_file(filename):
+    """
+    Constructs a backpropagation neural network from a configuration file.
+    """
+    ann = libfann.fann_create_from_file(filename)
+    return fann_class(ann)
+
+def read_train_from_file(filename):
+    """
+    Reads a file that stores training data, in the format:
+    num_train_data num_input num_output\n
+    inputdata seperated by space\n
+    outputdata seperated by space\n
+
+    .
+    .
+    .
+   
+    inputdata seperated by space\n
+    outputdata seperated by space\n
+    """
+    train = libfann.fann_read_train_from_file(filename)
+    return train_class(train)
+
+"""
+fann_set_error_log = _libfann.fann_set_error_log
+fann_get_errno = _libfann.fann_get_errno
+fann_reset_errno = _libfann.fann_reset_errno
+fann_reset_errstr = _libfann.fann_reset_errstr
+fann_get_errstr = _libfann.fann_get_errstr
+fann_print_error = _libfann.fann_print_error
+
+fann_train_on_data_callback = _libfann.fann_train_on_data_callback
+fann_train_on_file_callback = _libfann.fann_train_on_file_callback
+"""
diff --git a/python/fann_helper.c b/python/fann_helper.c
index a2e371a..3b9fd6d 100644
--- a/python/fann_helper.c
+++ b/python/fann_helper.c
@@ -1,26 +1,70 @@
-#include <Python.h>
-#include <fann.h>
-
-PyObject* fann_type_to_PyList(fann_type *array,int n)
-{
-  int i;
-  PyObject* res = PyList_New(n);
-  for (i = 0; i < n; i++) {
-    PyObject *o = PyFloat_FromDouble((double) array[i]);
-    PyList_SetItem(res,i,o);
-  }
-  return res;
-}
-
-PyObject* fann_run2(struct fann *ann, fann_type *input)
-{
-  if (!ann) return NULL;
-  return fann_type_to_PyList(fann_run(ann,input),ann->num_output);
-}
-
-
-PyObject* fann_test2(struct fann *ann, fann_type *input, fann_type *desired_output)
-{
-  if (!ann) return NULL;
-  return fann_type_to_PyList(fann_test(ann,input,desired_output),ann->num_output);
-}
+#include <Python.h>
+#include <fann.h>
+
+PyObject *fann_type_to_PyList(fann_type *array,int n)
+{
+	int i;
+	PyObject* res = PyList_New(n);
+	for (i = 0; i < n; i++) 
+	{
+		PyObject *o = PyFloat_FromDouble((double) array[i]);
+		PyList_SetItem(res,i,o);
+	}
+
+	return res;
+}
+
+PyObject *fann_run2(struct fann *ann, fann_type *input)
+{
+	if (ann == NULL) 
+	{
+		return NULL;
+	}
+
+	return fann_type_to_PyList(fann_run(ann,input),ann->num_output);
+}
+
+PyObject *fann_test2(struct fann *ann, fann_type *input, fann_type *desired_output)
+{
+	if (ann == NULL) 
+	{
+		return NULL;
+	}
+
+	return fann_type_to_PyList(fann_test(ann,input,desired_output),ann->num_output);
+}
+
+static PyObject *get_row_from_double_array(fann_type **f, int row, int ncols) 
+{
+	int i;
+	PyObject *result = PyList_New(ncols);
+
+	for (i=0; i<ncols; i++) 
+	{
+		/* printf("%d:%d %f\n", row, i, f[row][i]); */
+		PyList_SetItem(result, i, Py_BuildValue("d", f[row][i]));
+	}
+
+	return result;
+}
+
+PyObject *get_train_data_input(struct fann_train_data *t, int row) 
+{
+	if (row < 0 || row >= t->num_data) 
+	{
+		return Py_BuildValue("");
+	}
+
+	return get_row_from_double_array(t->input, row, t->num_input);
+}
+
+PyObject *get_train_data_output(struct fann_train_data *t, int row) 
+{
+	if (row < 0 || row >= t->num_data) 
+	{
+		return Py_BuildValue("");
+	}
+
+	return get_row_from_double_array(t->output, row, t->num_output);
+}
+
diff --git a/python/fann.i b/python/libfann.i
old mode 100644
new mode 100755
similarity index 86%
rename from python/fann.i
rename to python/libfann.i
index 86ce59c..4493c77
--- a/python/fann.i
+++ b/python/libfann.i
@@ -1,80 +1,82 @@
-/* File : fann.i */
-%module fann
-
-%include "typemaps.i"
-
-%{
-#include "../src/include/fann.h"
-%}
-
-/*Define some typemaps*/
-
-%typemap(in) fann_type[ANY] {
-  int i;
-  if (!PySequence_Check($input)) {
-    PyErr_SetString(PyExc_ValueError,"Expected a sequence");
-    return NULL;
-  }
-  if (PySequence_Length($input) == 0) {
-    PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected some elements");
-    return NULL;
-  }
-  $1 = (float *) malloc(PySequence_Length($input)*sizeof(float));
-  for (i = 0; i < PySequence_Length($input); i++) {
-    PyObject *o = PySequence_GetItem($input,i);
-    if (PyNumber_Check(o)) {
-      $1[i] = (float) PyFloat_AsDouble(o);
-    } else {
-      PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");      
-      return NULL;
-    }
-  }
-}
-
-%typemap(in) int[ANY] {
-  int i;
-  if (!PySequence_Check($input)) {
-    PyErr_SetString(PyExc_ValueError,"Expected a sequence");
-    return NULL;
-  }
-  if (PySequence_Length($input) == 0) {
-    PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected some elements");
-    return NULL;
-  }
-  $1 = (unsigned int *) malloc(PySequence_Length($input)*sizeof(unsigned int));
-  for (i = 0; i < PySequence_Length($input); i++) {
-    PyObject *o = PySequence_GetItem($input,i);
-    if (PyNumber_Check(o)) {
-      $1[i] = (int) PyInt_AsLong(o);
-    } else {
-      PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");      
-      return NULL;
-    }
-  }
-}
-
-%typemap(freearg) fann_type value[ANY] {
-   if ($1) free($1);
-}
-
-%typemap(out) PyObject* {
-  $result = $1;
-}
-
-%apply fann_type[ANY] {fann_type *};
-%apply int[ANY] {int *, unsigned int*};
-
-#define FANN_INCLUDE
-%varargs(10,int n = 0) fann_create;
-%rename(fann_run_old) fann_run;
-%rename(fann_run) fann_run2;
-
-%rename(fann_test_old) fann_test;
-%rename(fann_test) fann_test2;
-
-/* Let's grab the original header file here */
-%include "../src/include/fann.h"
-
-// Helper functions
-PyObject* fann_run2(struct fann *ann, fann_type *input);
-PyObject* fann_test2(struct fann *ann, fann_type *input, fann_type *desired_output);
+/* File : fann.i */
+%module libfann
+
+%include "typemaps.i"
+
+%{
+#include "../src/include/fann.h"
+%}
+
+%typemap(in) fann_type[ANY] {
+  int i;
+  if (!PySequence_Check($input)) {
+    PyErr_SetString(PyExc_ValueError,"Expected a sequence");
+    return NULL;
+  }
+  if (PySequence_Length($input) == 0) {
+    PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected some elements");
+    return NULL;
+  }
+  $1 = (float *) malloc(PySequence_Length($input)*sizeof(float));
+  for (i = 0; i < PySequence_Length($input); i++) {
+    PyObject *o = PySequence_GetItem($input,i);
+    if (PyNumber_Check(o)) {
+      $1[i] = (float) PyFloat_AsDouble(o);
+    } else {
+      PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");      
+      return NULL;
+    }
+  }
+}
+
+%typemap(in) int[ANY] {
+  int i;
+  if (!PySequence_Check($input)) {
+    PyErr_SetString(PyExc_ValueError,"Expected a sequence");
+    return NULL;
+  }
+  if (PySequence_Length($input) == 0) {
+    PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected some elements");
+    return NULL;
+  }
+  $1 = (unsigned int *) malloc(PySequence_Length($input)*sizeof(unsigned int));
+  for (i = 0; i < PySequence_Length($input); i++) {
+    PyObject *o = PySequence_GetItem($input,i);
+    if (PyNumber_Check(o)) {
+      $1[i] = (int) PyInt_AsLong(o);
+    } else {
+      PyErr_SetString(PyExc_ValueError,"Sequence elements must be numbers");      
+      return NULL;
+    }
+  }
+}
+
+%typemap(freearg) fann_type* {
+   if ($1) free($1);
+}
+
+%typemap(out) PyObject* {
+  $result = $1;
+}
+
+%apply fann_type[ANY] {fann_type *};
+%apply int[ANY] {int *, unsigned int*};
+
+#define FANN_INCLUDE
+%varargs(10,int n = 0) fann_create;
+%rename(fann_run_old) fann_run;
+%rename(fann_run) fann_run2;
+
+%rename(fann_test_old) fann_test;
+%rename(fann_test) fann_test2;
+
+%include "../src/include/fann.h"
+%include "../src/include/fann_data.h"
+
+// Helper functions
+PyObject* fann_run2(struct fann *ann, fann_type *input);
+PyObject* fann_test2(struct fann *ann, fann_type *input, fann_type *desired_output);
+PyObject* get_train_data_input(struct fann_train_data *ann, int row);
+PyObject* get_train_data_output(struct fann_train_data *ann, int row);
+
+
diff --git a/python/libfann.py b/python/libfann.py
new file mode 100644
index 0000000..2d85db7
--- /dev/null
+++ b/python/libfann.py
@@ -0,0 +1,459 @@
+# This file was created automatically by SWIG.
+# Don't modify this file, modify the SWIG interface instead.
+# This file is compatible with both classic and new-style classes.
+
+import _libfann
+
+def _swig_setattr(self,class_type,name,value):
+    if (name == "this"):
+        if isinstance(value, class_type):
+            self.__dict__[name] = value.this
+            if hasattr(value,"thisown"): self.__dict__["thisown"] = value.thisown
+            del value.thisown
+            return
+    method = class_type.__swig_setmethods__.get(name,None)
+    if method: return method(self,value)
+    self.__dict__[name] = value
+
+def _swig_getattr(self,class_type,name):
+    method = class_type.__swig_getmethods__.get(name,None)
+    if method: return method(self)
+    raise AttributeError,name
+
+import types
+try:
+    _object = types.ObjectType
+    _newclass = 1
+except AttributeError:
+    class _object : pass
+    _newclass = 0
+del types
+
+
+NULL = _libfann.NULL
+
+fann_create = _libfann.fann_create
+
+fann_create_array = _libfann.fann_create_array
+
+fann_create_shortcut = _libfann.fann_create_shortcut
+
+fann_create_shortcut_array = _libfann.fann_create_shortcut_array
+
+fann_run_old = _libfann.fann_run_old
+
+fann_destroy = _libfann.fann_destroy
+
+fann_randomize_weights = _libfann.fann_randomize_weights
+
+fann_init_weights = _libfann.fann_init_weights
+
+fann_print_connections = _libfann.fann_print_connections
+
+fann_create_from_file = _libfann.fann_create_from_file
+
+fann_save = _libfann.fann_save
+
+fann_save_to_fixed = _libfann.fann_save_to_fixed
+
+fann_train = _libfann.fann_train
+
+fann_test_old = _libfann.fann_test_old
+
+fann_get_error = _libfann.fann_get_error
+
+fann_get_MSE = _libfann.fann_get_MSE
+
+fann_reset_error = _libfann.fann_reset_error
+
+fann_reset_MSE = _libfann.fann_reset_MSE
+
+fann_read_train_from_file = _libfann.fann_read_train_from_file
+
+fann_destroy_train = _libfann.fann_destroy_train
+
+fann_train_epoch = _libfann.fann_train_epoch
+
+fann_test_data = _libfann.fann_test_data
+
+fann_train_on_data = _libfann.fann_train_on_data
+
+fann_train_on_data_callback = _libfann.fann_train_on_data_callback
+
+fann_train_on_file = _libfann.fann_train_on_file
+
+fann_train_on_file_callback = _libfann.fann_train_on_file_callback
+
+fann_shuffle_train_data = _libfann.fann_shuffle_train_data
+
+fann_merge_train_data = _libfann.fann_merge_train_data
+
+fann_duplicate_train_data = _libfann.fann_duplicate_train_data
+
+fann_save_train = _libfann.fann_save_train
+
+fann_save_train_to_fixed = _libfann.fann_save_train_to_fixed
+
+fann_print_parameters = _libfann.fann_print_parameters
+
+fann_get_training_algorithm = _libfann.fann_get_training_algorithm
+
+fann_set_training_algorithm = _libfann.fann_set_training_algorithm
+
+fann_get_learning_rate = _libfann.fann_get_learning_rate
+
+fann_set_learning_rate = _libfann.fann_set_learning_rate
+
+fann_get_activation_function_hidden = _libfann.fann_get_activation_function_hidden
+
+fann_set_activation_function_hidden = _libfann.fann_set_activation_function_hidden
+
+fann_get_activation_function_output = _libfann.fann_get_activation_function_output
+
+fann_set_activation_function_output = _libfann.fann_set_activation_function_output
+
+fann_get_activation_steepness_hidden = _libfann.fann_get_activation_steepness_hidden
+
+fann_set_activation_steepness_hidden = _libfann.fann_set_activation_steepness_hidden
+
+fann_get_activation_steepness_output = _libfann.fann_get_activation_steepness_output
+
+fann_set_activation_steepness_output = _libfann.fann_set_activation_steepness_output
+
+fann_get_activation_hidden_steepness = _libfann.fann_get_activation_hidden_steepness
+
+fann_set_activation_hidden_steepness = _libfann.fann_set_activation_hidden_steepness
+
+fann_get_activation_output_steepness = _libfann.fann_get_activation_output_steepness
+
+fann_set_activation_output_steepness = _libfann.fann_set_activation_output_steepness
+
+fann_set_train_error_function = _libfann.fann_set_train_error_function
+
+fann_get_train_error_function = _libfann.fann_get_train_error_function
+
+fann_get_quickprop_decay = _libfann.fann_get_quickprop_decay
+
+fann_set_quickprop_decay = _libfann.fann_set_quickprop_decay
+
+fann_get_quickprop_mu = _libfann.fann_get_quickprop_mu
+
+fann_set_quickprop_mu = _libfann.fann_set_quickprop_mu
+
+fann_get_rprop_increase_factor = _libfann.fann_get_rprop_increase_factor
+
+fann_set_rprop_increase_factor = _libfann.fann_set_rprop_increase_factor
+
+fann_get_rprop_decrease_factor = _libfann.fann_get_rprop_decrease_factor
+
+fann_set_rprop_decrease_factor = _libfann.fann_set_rprop_decrease_factor
+
+fann_get_rprop_delta_min = _libfann.fann_get_rprop_delta_min
+
+fann_set_rprop_delta_min = _libfann.fann_set_rprop_delta_min
+
+fann_get_rprop_delta_max = _libfann.fann_get_rprop_delta_max
+
+fann_set_rprop_delta_max = _libfann.fann_set_rprop_delta_max
+
+fann_get_num_input = _libfann.fann_get_num_input
+
+fann_get_num_output = _libfann.fann_get_num_output
+
+fann_get_total_neurons = _libfann.fann_get_total_neurons
+
+fann_get_total_connections = _libfann.fann_get_total_connections
+
+fann_set_error_log = _libfann.fann_set_error_log
+
+fann_get_errno = _libfann.fann_get_errno
+
+fann_reset_errno = _libfann.fann_reset_errno
+
+fann_reset_errstr = _libfann.fann_reset_errstr
+
+fann_get_errstr = _libfann.fann_get_errstr
+
+fann_print_error = _libfann.fann_print_error
+class fann_neuron(_object):
+    __swig_setmethods__ = {}
+    __setattr__ = lambda self, name, value: _swig_setattr(self, fann_neuron, name, value)
+    __swig_getmethods__ = {}
+    __getattr__ = lambda self, name: _swig_getattr(self, fann_neuron, name)
+    def __repr__(self):
+        return "<C fann_neuron instance at %s>" % (self.this,)
+    __swig_setmethods__["weights"] = _libfann.fann_neuron_weights_set
+    __swig_getmethods__["weights"] = _libfann.fann_neuron_weights_get
+    if _newclass:weights = property(_libfann.fann_neuron_weights_get, _libfann.fann_neuron_weights_set)
+    __swig_setmethods__["connected_neurons"] = _libfann.fann_neuron_connected_neurons_set
+    __swig_getmethods__["connected_neurons"] = _libfann.fann_neuron_connected_neurons_get
+    if _newclass:connected_neurons = property(_libfann.fann_neuron_connected_neurons_get, _libfann.fann_neuron_connected_neurons_set)
+    __swig_setmethods__["num_connections"] = _libfann.fann_neuron_num_connections_set
+    __swig_getmethods__["num_connections"] = _libfann.fann_neuron_num_connections_get
+    if _newclass:num_connections = property(_libfann.fann_neuron_num_connections_get, _libfann.fann_neuron_num_connections_set)
+    __swig_setmethods__["value"] = _libfann.fann_neuron_value_set
+    __swig_getmethods__["value"] = _libfann.fann_neuron_value_get
+    if _newclass:value = property(_libfann.fann_neuron_value_get, _libfann.fann_neuron_value_set)
+    def __init__(self, *args):
+        _swig_setattr(self, fann_neuron, 'this', _libfann.new_fann_neuron(*args))
+        _swig_setattr(self, fann_neuron, 'thisown', 1)
+    def __del__(self, destroy=_libfann.delete_fann_neuron):
+        try:
+            if self.thisown: destroy(self)
+        except: pass
+
+class fann_neuronPtr(fann_neuron):
+    def __init__(self, this):
+        _swig_setattr(self, fann_neuron, 'this', this)
+        if not hasattr(self,"thisown"): _swig_setattr(self, fann_neuron, 'thisown', 0)
+        _swig_setattr(self, fann_neuron,self.__class__,fann_neuron)
+_libfann.fann_neuron_swigregister(fann_neuronPtr)
+
+class fann_layer(_object):
+    __swig_setmethods__ = {}
+    __setattr__ = lambda self, name, value: _swig_setattr(self, fann_layer, name, value)
+    __swig_getmethods__ = {}
+    __getattr__ = lambda self, name: _swig_getattr(self, fann_layer, name)
+    def __repr__(self):
+        return "<C fann_layer instance at %s>" % (self.this,)
+    __swig_setmethods__["first_neuron"] = _libfann.fann_layer_first_neuron_set
+    __swig_getmethods__["first_neuron"] = _libfann.fann_layer_first_neuron_get
+    if _newclass:first_neuron = property(_libfann.fann_layer_first_neuron_get, _libfann.fann_layer_first_neuron_set)
+    __swig_setmethods__["last_neuron"] = _libfann.fann_layer_last_neuron_set
+    __swig_getmethods__["last_neuron"] = _libfann.fann_layer_last_neuron_get
+    if _newclass:last_neuron = property(_libfann.fann_layer_last_neuron_get, _libfann.fann_layer_last_neuron_set)
+    def __init__(self, *args):
+        _swig_setattr(self, fann_layer, 'this', _libfann.new_fann_layer(*args))
+        _swig_setattr(self, fann_layer, 'thisown', 1)
+    def __del__(self, destroy=_libfann.delete_fann_layer):
+        try:
+            if self.thisown: destroy(self)
+        except: pass
+
+class fann_layerPtr(fann_layer):
+    def __init__(self, this):
+        _swig_setattr(self, fann_layer, 'this', this)
+        if not hasattr(self,"thisown"): _swig_setattr(self, fann_layer, 'thisown', 0)
+        _swig_setattr(self, fann_layer,self.__class__,fann_layer)
+_libfann.fann_layer_swigregister(fann_layerPtr)
+
+class fann(_object):
+    __swig_setmethods__ = {}
+    __setattr__ = lambda self, name, value: _swig_setattr(self, fann, name, value)
+    __swig_getmethods__ = {}
+    __getattr__ = lambda self, name: _swig_getattr(self, fann, name)
+    def __repr__(self):
+        return "<C fann instance at %s>" % (self.this,)
+    __swig_setmethods__["errno_f"] = _libfann.fann_errno_f_set
+    __swig_getmethods__["errno_f"] = _libfann.fann_errno_f_get
+    if _newclass:errno_f = property(_libfann.fann_errno_f_get, _libfann.fann_errno_f_set)
+    __swig_setmethods__["error_log"] = _libfann.fann_error_log_set
+    __swig_getmethods__["error_log"] = _libfann.fann_error_log_get
+    if _newclass:error_log = property(_libfann.fann_error_log_get, _libfann.fann_error_log_set)
+    __swig_setmethods__["errstr"] = _libfann.fann_errstr_set
+    __swig_getmethods__["errstr"] = _libfann.fann_errstr_get
+    if _newclass:errstr = property(_libfann.fann_errstr_get, _libfann.fann_errstr_set)
+    __swig_setmethods__["learning_rate"] = _libfann.fann_learning_rate_set
+    __swig_getmethods__["learning_rate"] = _libfann.fann_learning_rate_get
+    if _newclass:learning_rate = property(_libfann.fann_learning_rate_get, _libfann.fann_learning_rate_set)
+    __swig_setmethods__["connection_rate"] = _libfann.fann_connection_rate_set
+    __swig_getmethods__["connection_rate"] = _libfann.fann_connection_rate_get
+    if _newclass:connection_rate = property(_libfann.fann_connection_rate_get, _libfann.fann_connection_rate_set)
+    __swig_setmethods__["shortcut_connections"] = _libfann.fann_shortcut_connections_set
+    __swig_getmethods__["shortcut_connections"] = _libfann.fann_shortcut_connections_get
+    if _newclass:shortcut_connections = property(_libfann.fann_shortcut_connections_get, _libfann.fann_shortcut_connections_set)
+    __swig_setmethods__["first_layer"] = _libfann.fann_first_layer_set
+    __swig_getmethods__["first_layer"] = _libfann.fann_first_layer_get
+    if _newclass:first_layer = property(_libfann.fann_first_layer_get, _libfann.fann_first_layer_set)
+    __swig_setmethods__["last_layer"] = _libfann.fann_last_layer_set
+    __swig_getmethods__["last_layer"] = _libfann.fann_last_layer_get
+    if _newclass:last_layer = property(_libfann.fann_last_layer_get, _libfann.fann_last_layer_set)
+    __swig_setmethods__["total_neurons"] = _libfann.fann_total_neurons_set
+    __swig_getmethods__["total_neurons"] = _libfann.fann_total_neurons_get
+    if _newclass:total_neurons = property(_libfann.fann_total_neurons_get, _libfann.fann_total_neurons_set)
+    __swig_setmethods__["num_input"] = _libfann.fann_num_input_set
+    __swig_getmethods__["num_input"] = _libfann.fann_num_input_get
+    if _newclass:num_input = property(_libfann.fann_num_input_get, _libfann.fann_num_input_set)
+    __swig_setmethods__["num_output"] = _libfann.fann_num_output_set
+    __swig_getmethods__["num_output"] = _libfann.fann_num_output_get
+    if _newclass:num_output = property(_libfann.fann_num_output_get, _libfann.fann_num_output_set)
+    __swig_setmethods__["train_errors"] = _libfann.fann_train_errors_set
+    __swig_getmethods__["train_errors"] = _libfann.fann_train_errors_get
+    if _newclass:train_errors = property(_libfann.fann_train_errors_get, _libfann.fann_train_errors_set)
+    __swig_setmethods__["activation_function_hidden"] = _libfann.fann_activation_function_hidden_set
+    __swig_getmethods__["activation_function_hidden"] = _libfann.fann_activation_function_hidden_get
+    if _newclass:activation_function_hidden = property(_libfann.fann_activation_function_hidden_get, _libfann.fann_activation_function_hidden_set)
+    __swig_setmethods__["activation_function_output"] = _libfann.fann_activation_function_output_set
+    __swig_getmethods__["activation_function_output"] = _libfann.fann_activation_function_output_get
+    if _newclass:activation_function_output = property(_libfann.fann_activation_function_output_get, _libfann.fann_activation_function_output_set)
+    __swig_setmethods__["activation_steepness_hidden"] = _libfann.fann_activation_steepness_hidden_set
+    __swig_getmethods__["activation_steepness_hidden"] = _libfann.fann_activation_steepness_hidden_get
+    if _newclass:activation_steepness_hidden = property(_libfann.fann_activation_steepness_hidden_get, _libfann.fann_activation_steepness_hidden_set)
+    __swig_setmethods__["activation_steepness_output"] = _libfann.fann_activation_steepness_output_set
+    __swig_getmethods__["activation_steepness_output"] = _libfann.fann_activation_steepness_output_get
+    if _newclass:activation_steepness_output = property(_libfann.fann_activation_steepness_output_get, _libfann.fann_activation_steepness_output_set)
+    __swig_setmethods__["training_algorithm"] = _libfann.fann_training_algorithm_set
+    __swig_getmethods__["training_algorithm"] = _libfann.fann_training_algorithm_get
+    if _newclass:training_algorithm = property(_libfann.fann_training_algorithm_get, _libfann.fann_training_algorithm_set)
+    __swig_setmethods__["activation_results_hidden"] = _libfann.fann_activation_results_hidden_set
+    __swig_getmethods__["activation_results_hidden"] = _libfann.fann_activation_results_hidden_get
+    if _newclass:activation_results_hidden = property(_libfann.fann_activation_results_hidden_get, _libfann.fann_activation_results_hidden_set)
+    __swig_setmethods__["activation_values_hidden"] = _libfann.fann_activation_values_hidden_set
+    __swig_getmethods__["activation_values_hidden"] = _libfann.fann_activation_values_hidden_get
+    if _newclass:activation_values_hidden = property(_libfann.fann_activation_values_hidden_get, _libfann.fann_activation_values_hidden_set)
+    __swig_setmethods__["activation_results_output"] = _libfann.fann_activation_results_output_set
+    __swig_getmethods__["activation_results_output"] = _libfann.fann_activation_results_output_get
+    if _newclass:activation_results_output = property(_libfann.fann_activation_results_output_get, _libfann.fann_activation_results_output_set)
+    __swig_setmethods__["activation_values_output"] = _libfann.fann_activation_values_output_set
+    __swig_getmethods__["activation_values_output"] = _libfann.fann_activation_values_output_get
+    if _newclass:activation_values_output = property(_libfann.fann_activation_values_output_get, _libfann.fann_activation_values_output_set)
+    __swig_setmethods__["total_connections"] = _libfann.fann_total_connections_set
+    __swig_getmethods__["total_connections"] = _libfann.fann_total_connections_get
+    if _newclass:total_connections = property(_libfann.fann_total_connections_get, _libfann.fann_total_connections_set)
+    __swig_setmethods__["output"] = _libfann.fann_output_set
+    __swig_getmethods__["output"] = _libfann.fann_output_get
+    if _newclass:output = property(_libfann.fann_output_get, _libfann.fann_output_set)
+    __swig_setmethods__["num_MSE"] = _libfann.fann_num_MSE_set
+    __swig_getmethods__["num_MSE"] = _libfann.fann_num_MSE_get
+    if _newclass:num_MSE = property(_libfann.fann_num_MSE_get, _libfann.fann_num_MSE_set)
+    __swig_setmethods__["MSE_value"] = _libfann.fann_MSE_value_set
+    __swig_getmethods__["MSE_value"] = _libfann.fann_MSE_value_get
+    if _newclass:MSE_value = property(_libfann.fann_MSE_value_get, _libfann.fann_MSE_value_set)
+    __swig_setmethods__["train_error_function"] = _libfann.fann_train_error_function_set
+    __swig_getmethods__["train_error_function"] = _libfann.fann_train_error_function_get
+    if _newclass:train_error_function = property(_libfann.fann_train_error_function_get, _libfann.fann_train_error_function_set)
+    __swig_setmethods__["quickprop_decay"] = _libfann.fann_quickprop_decay_set
+    __swig_getmethods__["quickprop_decay"] = _libfann.fann_quickprop_decay_get
+    if _newclass:quickprop_decay = property(_libfann.fann_quickprop_decay_get, _libfann.fann_quickprop_decay_set)
+    __swig_setmethods__["quickprop_mu"] = _libfann.fann_quickprop_mu_set
+    __swig_getmethods__["quickprop_mu"] = _libfann.fann_quickprop_mu_get
+    if _newclass:quickprop_mu = property(_libfann.fann_quickprop_mu_get, _libfann.fann_quickprop_mu_set)
+    __swig_setmethods__["rprop_increase_factor"] = _libfann.fann_rprop_increase_factor_set
+    __swig_getmethods__["rprop_increase_factor"] = _libfann.fann_rprop_increase_factor_get
+    if _newclass:rprop_increase_factor = property(_libfann.fann_rprop_increase_factor_get, _libfann.fann_rprop_increase_factor_set)
+    __swig_setmethods__["rprop_decrease_factor"] = _libfann.fann_rprop_decrease_factor_set
+    __swig_getmethods__["rprop_decrease_factor"] = _libfann.fann_rprop_decrease_factor_get
+    if _newclass:rprop_decrease_factor = property(_libfann.fann_rprop_decrease_factor_get, _libfann.fann_rprop_decrease_factor_set)
+    __swig_setmethods__["rprop_delta_min"] = _libfann.fann_rprop_delta_min_set
+    __swig_getmethods__["rprop_delta_min"] = _libfann.fann_rprop_delta_min_get
+    if _newclass:rprop_delta_min = property(_libfann.fann_rprop_delta_min_get, _libfann.fann_rprop_delta_min_set)
+    __swig_setmethods__["rprop_delta_max"] = _libfann.fann_rprop_delta_max_set
+    __swig_getmethods__["rprop_delta_max"] = _libfann.fann_rprop_delta_max_get
+    if _newclass:rprop_delta_max = property(_libfann.fann_rprop_delta_max_get, _libfann.fann_rprop_delta_max_set)
+    __swig_setmethods__["train_slopes"] = _libfann.fann_train_slopes_set
+    __swig_getmethods__["train_slopes"] = _libfann.fann_train_slopes_get
+    if _newclass:train_slopes = property(_libfann.fann_train_slopes_get, _libfann.fann_train_slopes_set)
+    __swig_setmethods__["prev_steps"] = _libfann.fann_prev_steps_set
+    __swig_getmethods__["prev_steps"] = _libfann.fann_prev_steps_get
+    if _newclass:prev_steps = property(_libfann.fann_prev_steps_get, _libfann.fann_prev_steps_set)
+    __swig_setmethods__["prev_train_slopes"] = _libfann.fann_prev_train_slopes_set
+    __swig_getmethods__["prev_train_slopes"] = _libfann.fann_prev_train_slopes_get
+    if _newclass:prev_train_slopes = property(_libfann.fann_prev_train_slopes_get, _libfann.fann_prev_train_slopes_set)
+    def __init__(self, *args):
+        _swig_setattr(self, fann, 'this', _libfann.new_fann(*args))
+        _swig_setattr(self, fann, 'thisown', 1)
+    def __del__(self, destroy=_libfann.delete_fann):
+        try:
+            if self.thisown: destroy(self)
+        except: pass
+
+class fannPtr(fann):
+    def __init__(self, this):
+        _swig_setattr(self, fann, 'this', this)
+        if not hasattr(self,"thisown"): _swig_setattr(self, fann, 'thisown', 0)
+        _swig_setattr(self, fann,self.__class__,fann)
+_libfann.fann_swigregister(fannPtr)
+
+class fann_train_data(_object):
+    __swig_setmethods__ = {}
+    __setattr__ = lambda self, name, value: _swig_setattr(self, fann_train_data, name, value)
+    __swig_getmethods__ = {}
+    __getattr__ = lambda self, name: _swig_getattr(self, fann_train_data, name)
+    def __repr__(self):
+        return "<C fann_train_data instance at %s>" % (self.this,)
+    __swig_setmethods__["errno_f"] = _libfann.fann_train_data_errno_f_set
+    __swig_getmethods__["errno_f"] = _libfann.fann_train_data_errno_f_get
+    if _newclass:errno_f = property(_libfann.fann_train_data_errno_f_get, _libfann.fann_train_data_errno_f_set)
+    __swig_setmethods__["error_log"] = _libfann.fann_train_data_error_log_set
+    __swig_getmethods__["error_log"] = _libfann.fann_train_data_error_log_get
+    if _newclass:error_log = property(_libfann.fann_train_data_error_log_get, _libfann.fann_train_data_error_log_set)
+    __swig_setmethods__["errstr"] = _libfann.fann_train_data_errstr_set
+    __swig_getmethods__["errstr"] = _libfann.fann_train_data_errstr_get
+    if _newclass:errstr = property(_libfann.fann_train_data_errstr_get, _libfann.fann_train_data_errstr_set)
+    __swig_setmethods__["num_data"] = _libfann.fann_train_data_num_data_set
+    __swig_getmethods__["num_data"] = _libfann.fann_train_data_num_data_get
+    if _newclass:num_data = property(_libfann.fann_train_data_num_data_get, _libfann.fann_train_data_num_data_set)
+    __swig_setmethods__["num_input"] = _libfann.fann_train_data_num_input_set
+    __swig_getmethods__["num_input"] = _libfann.fann_train_data_num_input_get
+    if _newclass:num_input = property(_libfann.fann_train_data_num_input_get, _libfann.fann_train_data_num_input_set)
+    __swig_setmethods__["num_output"] = _libfann.fann_train_data_num_output_set
+    __swig_getmethods__["num_output"] = _libfann.fann_train_data_num_output_get
+    if _newclass:num_output = property(_libfann.fann_train_data_num_output_get, _libfann.fann_train_data_num_output_set)
+    __swig_setmethods__["input"] = _libfann.fann_train_data_input_set
+    __swig_getmethods__["input"] = _libfann.fann_train_data_input_get
+    if _newclass:input = property(_libfann.fann_train_data_input_get, _libfann.fann_train_data_input_set)
+    __swig_setmethods__["output"] = _libfann.fann_train_data_output_set
+    __swig_getmethods__["output"] = _libfann.fann_train_data_output_get
+    if _newclass:output = property(_libfann.fann_train_data_output_get, _libfann.fann_train_data_output_set)
+    def __init__(self, *args):
+        _swig_setattr(self, fann_train_data, 'this', _libfann.new_fann_train_data(*args))
+        _swig_setattr(self, fann_train_data, 'thisown', 1)
+    def __del__(self, destroy=_libfann.delete_fann_train_data):
+        try:
+            if self.thisown: destroy(self)
+        except: pass
+
+class fann_train_dataPtr(fann_train_data):
+    def __init__(self, this):
+        _swig_setattr(self, fann_train_data, 'this', this)
+        if not hasattr(self,"thisown"): _swig_setattr(self, fann_train_data, 'thisown', 0)
+        _swig_setattr(self, fann_train_data,self.__class__,fann_train_data)
+_libfann.fann_train_data_swigregister(fann_train_dataPtr)
+
+class fann_error(_object):
+    __swig_setmethods__ = {}
+    __setattr__ = lambda self, name, value: _swig_setattr(self, fann_error, name, value)
+    __swig_getmethods__ = {}
+    __getattr__ = lambda self, name: _swig_getattr(self, fann_error, name)
+    def __repr__(self):
+        return "<C fann_error instance at %s>" % (self.this,)
+    __swig_setmethods__["errno_f"] = _libfann.fann_error_errno_f_set
+    __swig_getmethods__["errno_f"] = _libfann.fann_error_errno_f_get
+    if _newclass:errno_f = property(_libfann.fann_error_errno_f_get, _libfann.fann_error_errno_f_set)
+    __swig_setmethods__["error_log"] = _libfann.fann_error_error_log_set
+    __swig_getmethods__["error_log"] = _libfann.fann_error_error_log_get
+    if _newclass:error_log = property(_libfann.fann_error_error_log_get, _libfann.fann_error_error_log_set)
+    __swig_setmethods__["errstr"] = _libfann.fann_error_errstr_set
+    __swig_getmethods__["errstr"] = _libfann.fann_error_errstr_get
+    if _newclass:errstr = property(_libfann.fann_error_errstr_get, _libfann.fann_error_errstr_set)
+    def __init__(self, *args):
+        _swig_setattr(self, fann_error, 'this', _libfann.new_fann_error(*args))
+        _swig_setattr(self, fann_error, 'thisown', 1)
+    def __del__(self, destroy=_libfann.delete_fann_error):
+        try:
+            if self.thisown: destroy(self)
+        except: pass
+
+class fann_errorPtr(fann_error):
+    def __init__(self, this):
+        _swig_setattr(self, fann_error, 'this', this)
+        if not hasattr(self,"thisown"): _swig_setattr(self, fann_error, 'thisown', 0)
+        _swig_setattr(self, fann_error,self.__class__,fann_error)
+_libfann.fann_error_swigregister(fann_errorPtr)
+
+FANN_TRAIN_INCREMENTAL = _libfann.FANN_TRAIN_INCREMENTAL
+FANN_TRAIN_BATCH = _libfann.FANN_TRAIN_BATCH
+FANN_TRAIN_RPROP = _libfann.FANN_TRAIN_RPROP
+FANN_TRAIN_QUICKPROP = _libfann.FANN_TRAIN_QUICKPROP
+FANN_ERRORFUNC_LINEAR = _libfann.FANN_ERRORFUNC_LINEAR
+FANN_ERRORFUNC_TANH = _libfann.FANN_ERRORFUNC_TANH
+
+fann_run = _libfann.fann_run
+
+fann_test = _libfann.fann_test
+
+get_train_data_input = _libfann.get_train_data_input
+
+get_train_data_output = _libfann.get_train_data_output
+cvar = _libfann.cvar
+
diff --git a/python/libfann.pyc b/python/libfann.pyc
new file mode 100644
index 0000000..c02a78d
Binary files /dev/null and b/python/libfann.pyc differ
diff --git a/python/makefile.gnu b/python/makefile.gnu
new file mode 100755
index 0000000..06f4e81
--- /dev/null
+++ b/python/makefile.gnu
@@ -0,0 +1,21 @@
+# This makefile was written to compile a distribution of pyfann for
+# GNU platforms (cygwin included.)
+
+TARGETS = _libfann.dll
+
+PYTHON=python2.3
+LIBS=-L. -L/usr/local/lib -L/usr/bin -l$(PYTHON) ../src/fann*.o
+
+all: $(TARGETS)
+
+_%.dll: %_wrap.o fann_helper.o
+	gcc $(LIBS) -shared -dll $^ -o $@
+
+%.o: %.c 
+	gcc -c $< -I/usr/include/$(PYTHON)/
+
+%_wrap.c: %.i 
+	swig -python $<
+
+clean:
+	rm -f $(TARGETS) *_wrap.* fann_helper.o fann.pyc
diff --git a/python/makefile.msvc b/python/makefile.msvc
new file mode 100755
index 0000000..6c760e0
--- /dev/null
+++ b/python/makefile.msvc
@@ -0,0 +1,23 @@
+# This makefile was written to compile a distribution of pyfann for
+# Microsoft Visual C++. 
+
+TARGETS = _libfann.pyd
+
+PYTHON=python2.3
+
+PYDIR=C:/Python23
+OBJS=libfann_wrap.obj fann_helper.obj
+
+all: $(TARGETS)
+
+_libfann.pyd: $(OBJS)
+	link /LIBPATH:$(PYDIR)/libs /DLL /OUT:$@ $(OBJS) ../src/fann*.obj python23.lib
+
+.c.obj:
+	cl -c $< -I $(PYDIR)/include -I ../src/include
+
+libfann_wrap.c: libfann.i
+	swig -python libfann.i
+
+clean:
+	del -f $(TARGETS) *_wrap.* fann_helper.obj fann.pyc libfann.py _libfann.*
diff --git a/python/setup.py b/python/setup.py
new file mode 100755
index 0000000..5dffc7c
--- /dev/null
+++ b/python/setup.py
@@ -0,0 +1,69 @@
+from distutils.core import setup, Extension
+from distutils.command.install_data import install_data
+from compiler.pycodegen import compileFile
+import glob
+import distutils
+import distutils.sysconfig
+import distutils.core
+import os
+import py2exe
+
+VERSION='1.2.0'
+
+LONG_DESCRIPTION="""\
+Fast Artificial Neural Network Library implements multilayer
+artificial neural networks with support for both fully connected
+and sparsely connected networks. It includes a framework for easy 
+handling of training data sets. It is easy to use, versatile, well 
+documented, and fast. 
+"""
+
+class smart_install_data(install_data):
+    """
+    override default distutils install_data, so we can copy
+    files directly, without splitting into modules, scripts,
+    packages, and extensions."
+    """
+    def run(self):
+        # need to change self.install_dir to the actual library dir
+
+        install_cmd = self.get_finalized_command('install')
+        self.install_dir = getattr(install_cmd, 'install_lib')
+        return install_data.run(self)
+
+def hunt_files(root, which):
+    return glob.glob(os.path.join(root, which))
+
+data_files = []
+
+# add sources
+data_files = data_files + [['', ['fann.py', '__init__.py']]]
+
+# add dll and swig output
+compileFile('libfann.py')
+data_files = data_files + [['', ['libfann.pyc', '_libfann.pyd']]]
+
+# add examples
+data_files = data_files + [['examples', hunt_files('examples', '*.py')]]
+
+# add examples datasets
+data_files = data_files + [['examples/datasets', hunt_files('../benchmarks/datasets', 'mushroom*')]]
+data_files = data_files + [['examples/datasets', hunt_files('../examples', 'xor.data')]]
+
+setup(
+    name='pyfann',
+    description='Fast Artificial Neural Network Library (fann)',
+    long_description=LONG_DESCRIPTION,
+    version=VERSION,
+    author='Steffen Nissen',
+    author_email='lukesky at diku.dk',
+    maintainer='Gil Megidish',
+    maintainer_email='gil at megidish.net',
+    url='http://sourceforge.net/projects/fann/',
+    platforms='WIN32',
+    license='GNU LESSER GENERAL PUBLIC LICENSE (LGPL)',
+    data_files=data_files,
+    cmdclass={'install_data': smart_install_data},
+    extra_path='pyfann'
+)
+
diff --git a/python/simple_train.py b/python/simple_train.py
deleted file mode 100755
index edf6a45..0000000
--- a/python/simple_train.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/python
-import fann
-
-connection_rate = 1
-learning_rate = 0.7
-num_layers = 3
-num_input = 2
-num_neurons_hidden = 4
-num_output = 1
-
-
-ann = fann.fann_create(connection_rate, learning_rate, num_layers,num_input, num_neurons_hidden, num_output)
-
-desired_error = 0.0001
-max_iterations = 500000
-iterations_between_reports = 1000
-fann.fann_train_on_file(ann, "../examples/xor.data", max_iterations, iterations_between_reports, desired_error)
-fann.fann_save(ann, "xor_float.net")
-
-fann.fann_destroy(ann)

-- 
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