Click here to Skip to main content
Click here to Skip to main content

Artificial Neural Networks made easy with the FANN library

By , 16 Feb 2006
 
fann-1_2_0.zip
fann-1.2.0
aclocal.m4
AUTHORS
benchmarks
.cvsignore
benchmark.sh
benchmarks.pdf
datasets
building.test
building.train
diabetes.test
diabetes.train
gene.test
gene.train
mushroom.test
mushroom.train
parity13.test
parity13.train
parity8.test
parity8.train
pumadyn-32fm.test
pumadyn-32fm.train
robot.test
robot.train
soybean.test
soybean.train
thyroid.test
thyroid.train
two-spiral.test
two-spiral.train
gnuplot
Makefile
performance.cc
quality.cc
README
ChangeLog
config.guess
config.in
config.sub
configure
configure.in
COPYING
debian
changelog
compat
control
copyright
docs
libfann1.dirs
libfann1.files
libfann1.install
libfann1-dev.dirs
libfann1-dev.examples
libfann1-dev.files
libfann1-dev.install
rules
depcomp
doc
fann_doc_complete_1.0.pdf
html
Makefile
examples
Makefile
xor.data
fann.pc.in
fann.spec.in
INSTALL
install-sh
ltmain.sh
Makefile.am
Makefile.in
missing
mkinstalldirs
MSVC++
all.dsw
libfann.dsp
simple_test.dsp
simple_train.dsp
steepness_train.dsp
xor_test.dsp
xor_train.dsp
NEWS
python
examples
libfann.i
libfann.pyc
makefile.gnu
makefile.msvc
README
README
src
COPYING
include
Makefile.am
Makefile.in
Makefile.am
Makefile.in
TODO
win32_dll
examples
makefile
fann_win32_dll-1_2_0.zip
aclocal.m4
AUTHORS
.cvsignore
benchmark.sh
benchmarks.pdf
building.test
building.train
diabetes.test
diabetes.train
gene.test
gene.train
mushroom.test
mushroom.train
parity13.test
parity13.train
parity8.test
parity8.train
pumadyn-32fm.test
pumadyn-32fm.train
robot.test
robot.train
soybean.test
soybean.train
thyroid.test
thyroid.train
two-spiral.test
two-spiral.train
gnuplot
Makefile
performance.cc
quality.cc
README
ChangeLog
config.guess
config.in
config.sub
configure
configure.in
COPYING
changelog
compat
control
copyright
docs
libfann1.dirs
libfann1.files
libfann1.install
libfann1-dev.dirs
libfann1-dev.examples
libfann1-dev.files
libfann1-dev.install
rules
depcomp
fann_doc_complete_1.0.pdf
Makefile
Makefile
xor.data
fann.pc.in
fann.spec.in
INSTALL
install-sh
ltmain.sh
Makefile.am
Makefile.in
missing
mkinstalldirs
all.dsw
libfann.dsp
simple_test.dsp
simple_train.dsp
steepness_train.dsp
xor_test.dsp
xor_train.dsp
NEWS
libfann.i
libfann.pyc
makefile.gnu
makefile.msvc
README
README
COPYING
Makefile.am
Makefile.in
Makefile.am
Makefile.in
TODO
bin
fanndouble.dll
fanndouble.lib
fanndoubled.dll
fanndoubled.lib
fanndoubleMT.dll
fanndoubleMT.lib
fanndoubleMTd.dll
fanndoubleMTd.lib
fannfixed.dll
fannfixed.lib
fannfixedd.dll
fannfixedd.lib
fannfixedMT.dll
fannfixedMT.lib
fannfixedMTd.dll
fannfixedMTd.lib
fannfloat.dll
fannfloat.lib
fannfloatd.dll
fannfloatd.lib
fannfloatMT.dll
fannfloatMT.lib
fannfloatMTd.dll
fannfloatMTd.lib
makefile
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 use 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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Software Developer's Journal
Publisher
Poland Poland
Member
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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 16 Feb 2006
Article Copyright 2006 by Software Developer's Journal
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid