Installing the FANN Neural Network on Linux

We will install the Fast Artificial Neural Network library on the Debian operating system (one of the Linux distributions). There are two ways to install the library.

  1. Installation from repositories
  2. installation of all elements separately.

The first method of course makes installation a bit easier, but it's not worth it. That's what I actually had to face. When I needed to install on Debian. I found an installation guide that described the first method. Having read it fluently and having already managed to rejoice (as it turned out in the future, not for long), I began to carry out exactly all the steps for installing the library described in the manual. Nuances did not arise. It seems that the library has been installed and the extension for PHP, too. Everything seemed to work. But it was not there. First I connected the neural network I used on denwere. But the result was zero. It turned out that even the initialization of the library itself did not go through. After re-reading the installation guide and similar manuals from other resources, I realized that everything should work. But in the end, nothing worked. Two days it took me to solve the installation problem. When all the possible options (and there were not many) were exhausted, the thought flashed through me, what if the distribution from the repositories of the library itself was “broken”. And as it turned out later, the way it was. Therefore, I recommend that you use the second installation method, as a result, everything will work, and your nerves will be in perfect order.

Installation start


For installation, we need the following tools:

  1. make program
  2. gcc compiler;
  3. phpize utility from php5-dev package.

If the first two tools can already be installed, then the third, most likely not. But just in case, we’ll check all three.

dpkg -l | grep make
ii makedev 2.3.1-88 creates device files in / dev
dpkg -l | grep gcc
ii gcc-3.3-base 1: 3.3.6-15 The GNU Compiler Collection (base package)
ii gcc-4.1-base 4.1.2-25 The GNU Compiler Collection (base package)
ii gcc-4.3-base 4.3.2-1.1 The GNU Compiler Collection (base package)
ii libgcc1 1: 4.3.2-1.1 GCC support library
dpkg -l | grep php5-dev

Well, as expected, we really have nothing installed. Before starting the installation, it is advisable to update the repositories. To do this, use the command:

apt-get update

Now you need to install the missing tools:

apt-get install make make
apt-get install gcc
apt-get install php5-dev

Next, you need to obtain information about the architecture in order to know which packages of the Fast Artificial Neural Network library (although Debian will not allow installing packages with the wrong architecture) to install. To do this, use the command:

uname –m

As a result, we see that the server has the architecture:

i686

Go to the / usr / local / src directory and download the following packages for the i686 architecture:

cd / usr / local / src
wget http://ubuntu.mirror.cambrium.nl/ubuntu//pool/universe/libf/libfann1/
libfann1_1.2.0-1_i386.deb
wget http://ubuntu.mirror.cambrium.nl/ubuntu//pool/universe/libf/libfann1/
libfann1-dev_1.2.0-1_i386.deb

Make sure everything downloaded:

ls -1
libfann1_1.2.0-1_i386.deb
libfann1-dev_1.2.0-1_i386.deb

Now they need to be installed in a certain order:

dpkg -i libfann1_1.2.0-1_i386.deb
dpkg -i libfann1-dev_1.2.0-1_i386.deb

Install extension for PHP


In order to start installing the extension, you need to download it:

wget http://pecl.php.net/get/fann

Check or archive in place:
ls -1
fann


Next, you need to unpack it:

tar xvfz fann
package.xml
fann-0.1.1 / config.m4
fann-0.1.1 / fann.c
fann-0.1.1 / php_fann.h
fann-0.1.1 / demo.php
fann-0.1.1 / CREDITS
fann-0.1.1 / EXPERIMENTAL

Then go to the directory /usr/local/src/fann-0.1.1

cd fann-0.1.1

Everything, it remains only to compile everything. First you need to run the phpize command . Which will prepare the environment of the PHP extension.

phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626

Next, run the configure script .

./configure

That's all, now it remains to assemble the PHP extension with the make program .

make

If you see something similar to the following lines:

fann.c: 393: error: 'zif_fannOO___set' undeclared (first use in this function)
fann.c: 393: error: (Each undeclared identifier is reported only once
fann.c: 393: error: for each function it appears in.)
fann.c: 403: error: b-? zif_fannOO ___ getb-? undeclared (first use in this function)

you need to comment out line 28 #define PHP_FANN_OO 1 in the php_fann.h file . And repeat the make program call .

make
libtool: install: cp ./.libs/fann.so /usr/local/src/fann-0.1.1/modules/fann.so
libtool: install: cp ./.libs/fann.lai /usr/local/src/fann-0.1.1/modules/fann.la
libtool: finish: PATH = "/ usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / sbin: / bin:
/ sbin "ldconfig -n /usr/local/src/fann-0.1.1/modules
-------------------------------------------------- --------------------
Libraries have been installed in:
   /usr/local/src/fann-0.1.1/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR '
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH 'environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH 'environment variable
     during linking
   - use the `-Wl, -rpath -Wl, LIBDIR 'linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf '
See any operating system documentation about shared libraries for
more information, such as the ld (1) and ld.so (8) manual pages.
-------------------------------------------------- --------------------
Build complete.
Don't forget to run 'make test'.

Everything, the extension is assembled and it remains to install it:

make install
Installing shared extensions: / usr / lib / php5 / 20090626 /

If you added the extension to /etc/php5/cli/php.ini , then you can see if the module is connected with the following command:
php -m | grep fann
fann

I personally try to synchronize settings everywhere immediately:

  • /etc/php5/apache2/php.ini;
  • / etc / php5 / cgi / php.ini;
  • / etc / php5 / cli / php.ini.


In order to test the library, you need to run the demo.php module. It is located in the /usr/local/src/fann-0.1.1 directory .
Still there is a small one nuance. You may not be able to use the network trained in another version of the Fast Artificial Neural Network library with this library. You have to retrain it under Linux. But there is nothing wrong with that.

Also popular now: