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
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
/*
Fast Artificial Neural Network Library (fann)
Copyright (C) 2003 Steffen Nissen (lukesky@diku.dk)

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

#ifndef __fann_activation_h__
#define __fann_activation_h__
/* internal include file, not to be included directly
 */

/* The possible activation functions.
   They are described with functions,
   where x is the input to the activation function,
   y is the output,
   s is the steepness and
   d is the derivation.
 */

enum {
	/* Linear activation function.
	   span: -inf < y < inf
	   y = x*s, d = 1*s
	   Can NOT be used in fixed point.
	*/
	FANN_LINEAR = 0,

	/* Threshold activation function.
	   x < 0 -> y = 0, x >= 0 -> y = 1
	   Can NOT be used during training.
	*/
	FANN_THRESHOLD,

	/* Threshold activation function.
	   x < 0 -> y = 0, x >= 0 -> y = 1
	   Can NOT be used during training.
	*/
	FANN_THRESHOLD_SYMMETRIC,

	/* Sigmoid activation function.
	   One of the most used activation functions.
	   span: 0 < y < 1
	   y = 1/(1 + exp(-2*s*x)), d = 2*s*y*(1 - y)
	*/
	FANN_SIGMOID,

	/* Stepwise linear approximation to sigmoid.
	   Faster than sigmoid but a bit less precise.
	*/
	FANN_SIGMOID_STEPWISE, /* (default) */


	/* Symmetric sigmoid activation function, aka. tanh.
	   One of the most used activation functions.
	   span: -1 < y < 1
	   y = tanh(s*x) = 2/(1 + exp(-2*s*x)) - 1, d = s*(1-(y*y))
	*/
	FANN_SIGMOID_SYMMETRIC,
	
	/* Stepwise linear approximation to symmetric sigmoid.
	   Faster than symmetric sigmoid but a bit less precise.
	*/
	FANN_SIGMOID_SYMMETRIC_STEPWISE,

	/* Gausian activation function.
	   0 when x = -inf, 1 when x = 0 and 0 when x = inf
	   span: 0 < y < 1
	   y = exp(-x*s*x*s), d = -2*x*y*s
	*/
	FANN_GAUSSIAN,

	/* Stepwise linear approximation to gaussian.
	   Faster than gaussian but a bit less precise.
	   NOT implemented yet.
	*/
	FANN_GAUSSIAN_STEPWISE,

	/* Fast (sigmoid like) activation function defined by David Elliott
	   span: 0 < y < 1
	   y = ((x*s) / 2) / (1 + |x*s|) + 0.5, d = s*1/(2*(1+|x|)*(1+|x|))
	   NOT implemented yet.
	*/
	FANN_ELLIOT,

	/* Fast (symmetric sigmoid like) activation function defined by David Elliott
	   span: -1 < y < 1   
	   y = (x*s) / (1 + |x*s|), d = s*1/((1+|x|)*(1+|x|))
	   NOT implemented yet.
	*/
	FANN_ELLIOT_SYMMETRIC
};

static char const * const FANN_ACTIVATION_NAMES[] = {
	"FANN_LINEAR",
	"FANN_THRESHOLD",
	"FANN_THRESHOLD_SYMMETRIC",
	"FANN_SIGMOID",
	"FANN_SIGMOID_STEPWISE",
	"FANN_SIGMOID_SYMMETRIC",
	"FANN_SIGMOID_SYMMETRIC_STEPWISE",
	"FANN_GAUSSIAN",
	"FANN_GAUSSIAN_STEPWISE",
	"FANN_ELLIOT",
	"FANN_ELLIOT_SYMMETRIC"
};

/* Implementation of the activation functions
 */

/* stepwise linear functions used for some of the activation functions */

/* defines used for the stepwise linear functions */

#define fann_linear_func(v1, r1, v2, r2, value) ((((r2-r1) * (value-v1))/(v2-v1)) + r1)
#define fann_stepwise(v1, v2, v3, v4, v5, v6, r1, r2, r3, r4, r5, r6, min, max, value) (value < v5 ? (value < v3 ? (value < v2 ? (value < v1 ? min : fann_linear_func(v1, r1, v2, r2, value)) : fann_linear_func(v2, r2, v3, r3, value)) : (value < v4 ? fann_linear_func(v3, r3, v4, r4, value) : fann_linear_func(v4, r4, v5, r5, value))) : (value < v6 ? fann_linear_func(v5, r5, v6, r6, value) : max))

/* FANN_LINEAR */
#define fann_linear(steepness, value) fann_mult(steepness, value)
#define fann_linear_derive(steepness, value) (steepness)

/* FANN_SIGMOID */
#define fann_sigmoid(steepness, value) (1.0f/(1.0f + exp(-2.0f * steepness * value)))
#define fann_sigmoid_derive(steepness, value) (2.0f * steepness * value * (1.0f - value)) /* the plus is a trick to the derived function, to avoid getting stuck on flat spots */

/* FANN_SIGMOID_SYMMETRIC */
#define fann_sigmoid_symmetric(steepness, value) (2.0f/(1.0f + exp(-2.0f * steepness * value)) - 1.0f)
#define fann_sigmoid_symmetric_derive(steepness, value) steepness * (1.0f - (value*value))

/* FANN_GAUSSIAN */
#define fann_gaussian(steepness, value) (exp(-value * steepness * value * steepness))

#endif

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)

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 | Mobile
Web04 | 2.8.140721.1 | Last Updated 28 Aug 2013
Article Copyright 2006 by Software Developer's Journal
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid