[libfann] 59/242: created file for activation functions, commented the activation functions and defined more activation functions (did NOT implement them though)

Christian Kastner chrisk-guest at moszumanska.debian.org
Sat Oct 4 21:10:20 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 f62f95a508d44bba9a7043f6e38c2c13db437c95
Author: Steffen Nissen <lukesky at diku.dk>
Date:   Fri Jan 16 10:16:15 2004 +0000

    created file for activation functions, commented the activation functions and defined more activation functions (did NOT implement them though)
---
 ChangeLog                     |   1 +
 TODO                          |   2 +-
 libtool                       |  30 +++++------
 src/fann.c                    |   8 +--
 src/include/Makefile.am       |   2 +-
 src/include/Makefile.in       |   2 +-
 src/include/fann.h            |  10 +---
 src/include/fann_activation.h | 119 ++++++++++++++++++++++++++++++++++++++++++
 src/include/fann_internal.h   |   8 +--
 9 files changed, 144 insertions(+), 38 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b193acf..6fc021a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@ libfann (1.0.6) stable; urgency=low
 	* Renamed fann_get_error to fann_get_MSE (keeping old one for now)
 	* Renamed fann_reset_error to fann_reset_MSE (keeping old one for now)
 	* Rearanged some code for easy access by the newly created fann php module 
+	* Defined more activation functions and documented the old (in fann_activation.h)
 	
  -- Steffen Nissen <lukesky at diku.dk> 
 
diff --git a/TODO b/TODO
index a5aa7df..ca9d0c0 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,6 @@
 * Implement quickprop training
 * Implement rprop training.
-* More advanced activation functions.
+* Implement the activation functions defined in fann_activation.h
 * More checks to see if train data is properly formatted in the file (some have experienced nasty problems because a number was missing in one line).
 * Make it easy to use in windows compilers as Borland C++ and MS Visual C++.
 * Good reference manual.
diff --git a/libtool b/libtool
index 2cc29ae..3e6c791 100755
--- a/libtool
+++ b/libtool
@@ -65,8 +65,8 @@ allow_libtool_libs_with_static_runtimes=no
 fast_install=yes
 
 # The host system.
-host_alias=i386-linux
-host=i386-pc-linux-gnu
+host_alias=
+host=i686-pc-linux-gnu
 
 # An echo program that does not interpret backslashes.
 echo="echo"
@@ -76,10 +76,10 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="i386-linux-gcc"
+LTCC="gcc"
 
 # A language-specific compiler.
-CC="i386-linux-gcc"
+CC="gcc"
 
 # Is the compiler the GNU C compiler?
 with_gcc=yes
@@ -94,7 +94,7 @@ LD="/usr/bin/ld"
 LN_S="ln -s"
 
 # A BSD-compatible nm program.
-NM="nm"
+NM="/usr/bin/nm -B"
 
 # A symbol stripping program
 STRIP="strip"
@@ -6725,8 +6725,8 @@ allow_libtool_libs_with_static_runtimes=no
 fast_install=yes
 
 # The host system.
-host_alias=i386-linux
-host=i386-pc-linux-gnu
+host_alias=
+host=i686-pc-linux-gnu
 
 # An echo program that does not interpret backslashes.
 echo="echo"
@@ -6736,10 +6736,10 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="i386-linux-gcc"
+LTCC="gcc"
 
 # A language-specific compiler.
-CC="i386-linux-g++"
+CC="g++"
 
 # Is the compiler the GNU C compiler?
 with_gcc=yes
@@ -6754,7 +6754,7 @@ LD="/usr/bin/ld"
 LN_S="ln -s"
 
 # A BSD-compatible nm program.
-NM="nm"
+NM="/usr/bin/nm -B"
 
 # A symbol stripping program
 STRIP="strip"
@@ -7024,8 +7024,8 @@ allow_libtool_libs_with_static_runtimes=no
 fast_install=yes
 
 # The host system.
-host_alias=i386-linux
-host=i386-pc-linux-gnu
+host_alias=
+host=i686-pc-linux-gnu
 
 # An echo program that does not interpret backslashes.
 echo="echo"
@@ -7035,10 +7035,10 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="i386-linux-gcc"
+LTCC="gcc"
 
 # A language-specific compiler.
-CC="i386-linux-g77"
+CC="g77"
 
 # Is the compiler the GNU C compiler?
 with_gcc=yes
@@ -7053,7 +7053,7 @@ LD="/usr/bin/ld"
 LN_S="ln -s"
 
 # A BSD-compatible nm program.
-NM="nm"
+NM="/usr/bin/nm -B"
 
 # A symbol stripping program
 STRIP="strip"
diff --git a/src/fann.c b/src/fann.c
index ec31a66..d158ac1 100644
--- a/src/fann.c
+++ b/src/fann.c
@@ -880,9 +880,9 @@ fann_type* fann_run(struct fann *ann, fann_type *input)
 				case FANN_SIGMOID:
 				case FANN_SIGMOID_STEPWISE:
 					if(layer_it == last_layer-1){
-						neuron_it->value = fann_sigmoid_stepwise(o1, o2, o3, o4, o5, o6, r1, r2, r3, r4, r5, r6, neuron_value, multiplier);
+						neuron_it->value = fann_stepwise(o1, o2, o3, o4, o5, o6, r1, r2, r3, r4, r5, r6, neuron_value, multiplier);
 					}else{
-						neuron_it->value = fann_sigmoid_stepwise(h1, h2, h3, h4, h5, h6, r1, r2, r3, r4, r5, r6, neuron_value, multiplier);
+						neuron_it->value = fann_stepwise(h1, h2, h3, h4, h5, h6, r1, r2, r3, r4, r5, r6, neuron_value, multiplier);
 					}
 					break;
 #else
@@ -892,9 +892,9 @@ fann_type* fann_run(struct fann *ann, fann_type *input)
 					
 				case FANN_SIGMOID_STEPWISE:
 					if(layer_it == last_layer-1){
-						neuron_it->value = fann_sigmoid_stepwise(o1, o2, o3, o4, o5, o6, r1, r2, r3, r4, r5, r6, neuron_value, 1);
+						neuron_it->value = fann_stepwise(o1, o2, o3, o4, o5, o6, r1, r2, r3, r4, r5, r6, neuron_value, 1);
 					}else{
-						neuron_it->value = fann_sigmoid_stepwise(h1, h2, h3, h4, h5, h6, r1, r2, r3, r4, r5, r6, neuron_value, 1);
+						neuron_it->value = fann_stepwise(h1, h2, h3, h4, h5, h6, r1, r2, r3, r4, r5, r6, neuron_value, 1);
 					}
 					break;
 #endif
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 776033d..f070f7b 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -1 +1 @@
-include_HEADERS = fann.h doublefann.h fann_internal.h floatfann.h doublefann.h fann_data.h fixedfann.h compat_time.h fann_errno.h
+include_HEADERS = fann.h doublefann.h fann_internal.h floatfann.h doublefann.h fann_data.h fixedfann.h compat_time.h fann_errno.h fann_activation.h
diff --git a/src/include/Makefile.in b/src/include/Makefile.in
index d4a652e..10a64df 100644
--- a/src/include/Makefile.in
+++ b/src/include/Makefile.in
@@ -129,7 +129,7 @@ sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 sysconfdir = @sysconfdir@
 target_alias = @target_alias@
-include_HEADERS = fann.h doublefann.h fann_internal.h floatfann.h doublefann.h fann_data.h fixedfann.h compat_time.h fann_errno.h
+include_HEADERS = fann.h doublefann.h fann_internal.h floatfann.h doublefann.h fann_data.h fixedfann.h compat_time.h fann_errno.h fann_activation.h
 subdir = src/include
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
diff --git a/src/include/fann.h b/src/include/fann.h
index 7f559fc..7668d41 100644
--- a/src/include/fann.h
+++ b/src/include/fann.h
@@ -35,6 +35,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 #include "fann_data.h"
 #include "fann_internal.h"
+#include "fann_activation.h"
 
 #ifndef __fann_h__
 #define __fann_h__
@@ -120,15 +121,6 @@ int fann_save_to_fixed(struct fann *ann, const char *configuration_file);
  */
 void fann_set_learning_rate(struct fann *ann, float learning_rate);
 
-/* The possible activation functions.
-   Threshold can not be used, when training the network.
-   FANN_SIGMOID_STEPWISE is a stepwise linear function,
-   which is faster but a bit less precise than FANN_SIGMOID
- */
-#define FANN_SIGMOID 1
-#define FANN_THRESHOLD 2
-#define FANN_SIGMOID_STEPWISE 3 /* (default) */
-
 /* Set the activation function for the hidden layers.
  */
 void fann_set_activation_function_hidden(struct fann *ann, unsigned int activation_function);
diff --git a/src/include/fann_activation.h b/src/include/fann_activation.h
new file mode 100644
index 0000000..607a584
--- /dev/null
+++ b/src/include/fann_activation.h
@@ -0,0 +1,119 @@
+/*
+Fast Artificial Neural Network Library (fann)
+Copyright (C) 2003 Steffen Nissen (lukesky at 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.
+ */
+
+/* Linear activation function.
+   span: -inf < y < inf
+   y = x*s, d = 1*s
+   Can NOT be used in fixed point.
+   NOT implemented yet.
+*/
+#define FANN_LINEAR 4
+
+/* Threshold activation function.
+   x < 0 -> y = 0, x >= 0 -> y = 1
+   Can NOT be used during training.
+*/
+#define FANN_THRESHOLD 2
+
+/* 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)
+*/
+#define FANN_SIGMOID 1
+
+/* Stepwise linear approximation to sigmoid.
+   Faster than sigmoid but a bit less precise.
+*/
+#define FANN_SIGMOID_STEPWISE 3 /* (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))
+   NOT implemented yet.
+*/
+#define FANN_SIGMOID_SYMMETRIC 5
+	
+/* Stepwise linear approximation to symmetric sigmoid.
+   Faster than symmetric sigmoid but a bit less precise.
+   NOT implemented yet.
+*/
+#define FANN_SIGMOID_SYMMETRIC_STEPWISE 6
+
+/* 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
+   NOT implemented yet.
+*/
+#define FANN_GAUSSIAN 7
+
+/* Stepwise linear approximation to gaussian.
+   Faster than gaussian but a bit less precise.
+   NOT implemented yet.
+*/
+#define FANN_GAUSSIAN_STEPWISE 8 /* not implemented yet. */
+
+/* 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.
+*/
+#define FANN_ELLIOT 9
+
+/* 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.
+*/
+#define FANN_ELLIOT_SYMMETRIC 10
+
+/* Implementation of the activation functions
+ */
+
+/* stepwise linear functions used for some of the activation 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, value, multiplier) (value < v5 ? (value < v3 ? (value < v2 ? (value < v1 ? 0 : 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) : multiplier))
+
+#ifdef FIXEDFANN
+#define fann_sigmoid(steepness, value) ((fann_type)(0.5+((1.0/(1.0 + exp(-2.0 * ((float)steepness/multiplier) * ((float)value/multiplier))))*multiplier)))
+
+#else
+
+#define fann_sigmoid(steepness, value) (1.0/(1.0 + exp(-2.0 * steepness * value)))
+#define fann_sigmoid_derive(steepness, value) ((2.0 * steepness * value * (1.0 - value)) + 0.01) /* the plus is a trick to the derived function, to avoid getting stuck on flat spots */
+#endif
+
+
+#endif
diff --git a/src/include/fann_internal.h b/src/include/fann_internal.h
index c39d3a4..91f8ed2 100644
--- a/src/include/fann_internal.h
+++ b/src/include/fann_internal.h
@@ -66,24 +66,18 @@ struct fann_train_data* fann_read_train_from_fd(FILE *file, char *filename);
 
 #define fann_abs(value) (((value) > 0) ? (value) : -(value))
 
-/* sigmoid as a stepwise linear function */
-#define fann_linear(v1, r1, v2, r2, value) ((((r2-r1) * (value-v1))/(v2-v1)) + r1)
-#define fann_sigmoid_stepwise(v1, v2, v3, v4, v5, v6, r1, r2, r3, r4, r5, r6, value, multiplier) (value < v5 ? (value < v3 ? (value < v2 ? (value < v1 ? 0 : fann_linear(v1, r1, v2, r2, value)) : fann_linear(v2, r2, v3, r3, value)) : (value < v4 ? fann_linear(v3, r3, v4, r4, value) : fann_linear(v4, r4, v5, r5, value))) : (value < v6 ? fann_linear(v5, r5, v6, r6, value) : multiplier))
-
 #ifdef FIXEDFANN
 
 #define fann_mult(x,y) ((x*y) >> decimal_point)
 #define fann_div(x,y) (((x) << decimal_point)/y)
 #define fann_random_weight() (fann_type)(fann_rand(-multiplier/10,multiplier/10))
 /* sigmoid calculated with use of floats, only as reference */
-#define fann_sigmoid(steepness, value) ((fann_type)(0.5+((1.0/(1.0 + exp(-2.0 * ((float)steepness/multiplier) * ((float)value/multiplier))))*multiplier)))
+
 #else
 
 #define fann_mult(x,y) (x*y)
 #define fann_div(x,y) (x/y)
 #define fann_random_weight() (fann_rand(-0.1,0.1))
-#define fann_sigmoid(steepness, value) (1.0/(1.0 + exp(-2.0 * steepness * value)))
-#define fann_sigmoid_derive(steepness, value) ((2.0 * steepness * value * (1.0 - value)) + 0.01) /* the plus is a trick to the derived function, to avoid getting stuck on flat spots */
 
 #endif
 

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