Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Artificial Neural Networks made easy with the FANN library

, 28 Aug 2013 CPOL
Neural networks are typically associated with specialised applications, developed only by select groups of experts. This misconception has had a highly negative effect on its popularity. Hopefully, the FANN library will help fill this gap.
fann-1_2_0.zip
fann-1.2.0
debian
changelog
compat
control
copyright
docs
libfann1-dev.dirs
libfann1-dev.examples
libfann1-dev.files
libfann1-dev.install
libfann1.dirs
libfann1.files
libfann1.install
rules
doc
fann_doc_complete_1.0.pdf
Makefile
html
src
include
Makefile.in
Makefile.am
Makefile.in
COPYING
Makefile.am
win32_dll
examples
makefile
README
Makefile.in
configure
AUTHORS
COPYING
ChangeLog
INSTALL
Makefile.am
NEWS
TODO
aclocal.m4
config.guess
config.sub
configure.in
depcomp
fann.pc.in
fann.spec.in
install-sh
ltmain.sh
missing
mkinstalldirs
benchmarks
datasets
building.test
building.train
diabetes.test
diabetes.train
gene.test
gene.train
mushroom.test
mushroom.train
robot.test
robot.train
soybean.test
soybean.train
thyroid.test
thyroid.train
two-spiral.train
pumadyn-32fm.test
pumadyn-32fm.train
two-spiral.test
parity8.train
parity8.test
parity13.test
parity13.train
Makefile
README
benchmark.sh
benchmarks.pdf
gnuplot
performance.cc
quality.cc
.cvsignore
examples
Makefile
xor.data
python
README
examples
libfann.i
makefile.gnu
makefile.msvc
libfann.pyc
MSVC++
libfann.dsp
all.dsw
simple_test.dsp
simple_train.dsp
steepness_train.dsp
xor_test.dsp
xor_train.dsp
config.in
fann_win32_dll-1_2_0.zip
changelog
compat
control
copyright
docs
libfann1-dev.dirs
libfann1-dev.examples
libfann1-dev.files
libfann1-dev.install
libfann1.dirs
libfann1.files
libfann1.install
rules
fann_doc_complete_1.0.pdf
Makefile
Makefile.in
Makefile.am
Makefile.in
COPYING
Makefile.am
makefile
README
Makefile.in
configure
AUTHORS
COPYING
ChangeLog
INSTALL
Makefile.am
NEWS
TODO
aclocal.m4
config.guess
config.sub
configure.in
depcomp
fann.pc.in
fann.spec.in
install-sh
ltmain.sh
missing
mkinstalldirs
building.test
building.train
diabetes.test
diabetes.train
gene.test
gene.train
mushroom.test
mushroom.train
robot.test
robot.train
soybean.test
soybean.train
thyroid.test
thyroid.train
two-spiral.train
pumadyn-32fm.test
pumadyn-32fm.train
two-spiral.test
parity8.train
parity8.test
parity13.test
parity13.train
Makefile
README
benchmark.sh
benchmarks.pdf
gnuplot
performance.cc
quality.cc
.cvsignore
Makefile
xor.data
README
libfann.i
makefile.gnu
makefile.msvc
libfann.pyc
libfann.dsp
all.dsw
simple_test.dsp
simple_train.dsp
steepness_train.dsp
xor_test.dsp
xor_train.dsp
config.in
bin
fanndoubled.dll
fanndoubled.lib
fanndoubleMTd.dll
fanndoubleMTd.lib
fannfixedd.dll
fannfixedd.lib
fannfixedMTd.dll
fannfixedMTd.lib
fannfloatd.dll
fannfloatd.lib
fannfloatMTd.dll
fannfloatMTd.lib
fanndouble.dll
fanndouble.lib
fanndoubleMT.dll
fanndoubleMT.lib
fannfixed.dll
fannfixed.lib
fannfixedMT.dll
fannfixedMT.lib
fannfloat.dll
fannfloat.lib
fannfloatMT.dll
fannfloatMT.lib
vs_net2003.zip
VS.NET2003
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Getting Started</TITLE
><link href="../style.css" rel="stylesheet" type="text/css"><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Fast Artificial Neural Network Library"
HREF="index.html"><LINK
REL="UP"
TITLE="Introduction"
HREF="c13.html"><LINK
REL="PREVIOUS"
TITLE="Installation"
HREF="x26.html"><LINK
REL="NEXT"
TITLE="Getting Help"
HREF="x100.html"></HEAD
><BODY
CLASS="section"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Fast Artificial Neural Network Library</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x26.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 1. Introduction</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x100.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="intro.start"
>1.3. Getting Started</A
></H1
><P
>&#13;        An ANN is normally run in two different modes, a training mode and an execution mode. Although it is
        possible to do this in the same program, using different programs is recommended.
      </P
><P
>&#13;        There are several reasons to why it is usually a good idea to write the training and execution in two
	different programs, but the most obvious is the fact that a typical ANN system is only trained once, while it
	is executed many times.
      </P
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="intro.start.train"
>1.3.1. Training</A
></H2
><P
>&#13;	  The following is a simple program which trains an ANN with a data set and then saves the ANN to a file. 
	</P
><DIV
CLASS="example"
><A
NAME="example.simple_train"
></A
><P
><B
>Example 1-1. Simple training example</B
></P
><PRE
CLASS="programlisting"
>&#13;
#include "fann.h"

int main()
{
        const float connection_rate = 1;
        const float learning_rate = 0.7;
        const unsigned int num_input = 2;
        const unsigned int num_output = 1;
        const unsigned int num_layers = 3;
        const unsigned int num_neurons_hidden = 4;
        const float desired_error = 0.0001;
        const unsigned int max_iterations = 500000;
        const unsigned int iterations_between_reports = 1000;

        struct fann *ann = fann_create(connection_rate, learning_rate, num_layers,
                num_input, num_neurons_hidden, num_output);
        
        fann_train_on_file(ann, "xor.data", max_iterations,
                iterations_between_reports, desired_error);
        
        fann_save(ann, "xor_float.net");
        
        fann_destroy(ann);

        return 0;
}

          </PRE
></DIV
><P
>&#13;	  The file xor.data, used to train the xor function:
	  <PRE
CLASS="literallayout"
>&#13;4 2 1
0 0
0
0 1
1
1 0
1
1 1
0
	  </PRE
> The first line consists of three numbers: The first is the number of training pairs in the file, the second is the number of inputs and
	  the third is the number of outputs. The rest of the file is the actual training data, consisting of one line with inputs, one with outputs etc.
	</P
><P
>&#13;	  This example introduces several fundamental functions, namely <A
HREF="r258.html"
><CODE
CLASS="function"
>fann_create</CODE
></A
>,
	  <A
HREF="r806.html"
><CODE
CLASS="function"
>fann_train_on_file</CODE
></A
>,
	  <A
HREF="r474.html"
><CODE
CLASS="function"
>fann_save</CODE
></A
>, and <A
HREF="r361.html"
><CODE
CLASS="function"
>fann_destroy</CODE
></A
>.
	</P
></DIV
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="intro.start.execution"
>1.3.2. Execution</A
></H2
><P
>&#13;	  The following example shows a simple program which executes a single input on the ANN. The program introduces two new functions
	  (<A
HREF="r519.html"
><CODE
CLASS="function"
>fann_create_from_file</CODE
></A
> and
	  <A
HREF="r376.html"
><CODE
CLASS="function"
>fann_run</CODE
></A
>) which were not used in the training procedure, as well as the <SPAN
CLASS="type"
>fann_type</SPAN
>
	  type.
	</P
><DIV
CLASS="example"
><A
NAME="example.simple_exec"
></A
><P
><B
>Example 1-2. Simple execution example</B
></P
><PRE
CLASS="programlisting"
>&#13;
#include &#60;stdio.h&#62;
#include "floatfann.h"

int main()
{
        fann_type *calc_out;
        fann_type input[2];

        struct fann *ann = fann_create_from_file("xor_float.net");
        
        input[0] = 0;
        input[1] = 1;
        calc_out = fann_run(ann, input);

        printf("xor test (%f,%f) -&#62; %f\n",
                input[0], input[1], *calc_out);
        
        fann_destroy(ann);
        return 0;
}

          </PRE
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x26.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x100.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Installation</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c13.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Getting Help</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Software Developer's Journal
Publisher
Poland Poland
Software Developer's Journal (formerly Software 2.0) is a magazine for professional programmers and developers publishing news from the software world and practical articles presenting very interesting ready programming solutions. To read more

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 28 Aug 2013
Article Copyright 2006 by Software Developer's Journal
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid