ruby-fann 0.7.10 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -1
- data/License.txt +1 -1
- data/Manifest.txt +22 -1
- data/README.txt +0 -1
- data/Rakefile +0 -0
- data/config/hoe.rb +0 -0
- data/config/requirements.rb +0 -0
- data/ext/ruby_fann/MANIFEST +0 -0
- data/ext/ruby_fann/Makefile +36 -28
- data/ext/ruby_fann/doublefann.c +30 -0
- data/ext/ruby_fann/doublefann.h +33 -0
- data/ext/ruby_fann/extconf.rb +9 -5
- data/ext/ruby_fann/fann.c +1552 -0
- data/ext/ruby_fann/fann_activation.h +144 -0
- data/ext/ruby_fann/fann_augment.h +0 -0
- data/ext/ruby_fann/fann_cascade.c +1031 -0
- data/ext/ruby_fann/fann_cascade.h +503 -0
- data/ext/ruby_fann/fann_data.h +799 -0
- data/ext/ruby_fann/fann_error.c +204 -0
- data/ext/ruby_fann/fann_error.h +161 -0
- data/ext/ruby_fann/fann_internal.h +148 -0
- data/ext/ruby_fann/fann_io.c +762 -0
- data/ext/ruby_fann/fann_io.h +100 -0
- data/ext/ruby_fann/fann_train.c +962 -0
- data/ext/ruby_fann/fann_train.h +1203 -0
- data/ext/ruby_fann/fann_train_data.c +1231 -0
- data/ext/ruby_fann/neural_network.c +0 -0
- data/lib/ruby_fann/neurotica.rb +0 -0
- data/lib/ruby_fann/version.rb +3 -3
- data/lib/ruby_fann.rb +0 -0
- data/neurotica1.png +0 -0
- data/neurotica2.vrml +18 -18
- data/setup.rb +0 -0
- data/tasks/deployment.rake +0 -0
- data/tasks/environment.rake +0 -0
- data/tasks/website.rake +0 -0
- data/test/test.train +0 -0
- data/test/test_helper.rb +0 -0
- data/test/test_neurotica.rb +0 -0
- data/test/test_ruby_fann.rb +0 -0
- data/test/test_ruby_fann_functional.rb +0 -0
- data/verify.train +0 -0
- data/website/index.html +42 -92
- data/website/index.txt +0 -0
- data/website/javascripts/rounded_corners_lite.inc.js +0 -0
- data/website/stylesheets/screen.css +0 -0
- data/website/template.rhtml +0 -0
- data/xor.train +0 -0
- data/xor_cascade.net +2 -2
- data/xor_float.net +1 -1
- metadata +22 -6
- data/log/debug.log +0 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
/*
|
2
|
+
Fast Artificial Neural Network Library (fann)
|
3
|
+
Copyright (C) 2003 Steffen Nissen (lukesky@diku.dk)
|
4
|
+
|
5
|
+
This library is free software; you can redistribute it and/or
|
6
|
+
modify it under the terms of the GNU Lesser General Public
|
7
|
+
License as published by the Free Software Foundation; either
|
8
|
+
version 2.1 of the License, or (at your option) any later version.
|
9
|
+
|
10
|
+
This library is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public
|
16
|
+
License along with this library; if not, write to the Free Software
|
17
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
*/
|
19
|
+
|
20
|
+
#ifndef __fann_activation_h__
|
21
|
+
#define __fann_activation_h__
|
22
|
+
/* internal include file, not to be included directly
|
23
|
+
*/
|
24
|
+
|
25
|
+
/* Implementation of the activation functions
|
26
|
+
*/
|
27
|
+
|
28
|
+
/* stepwise linear functions used for some of the activation functions */
|
29
|
+
|
30
|
+
/* defines used for the stepwise linear functions */
|
31
|
+
|
32
|
+
#define fann_linear_func(v1, r1, v2, r2, sum) (((((r2)-(r1)) * ((sum)-(v1)))/((v2)-(v1))) + (r1))
|
33
|
+
#define fann_stepwise(v1, v2, v3, v4, v5, v6, r1, r2, r3, r4, r5, r6, min, max, sum) (sum < v5 ? (sum < v3 ? (sum < v2 ? (sum < v1 ? min : fann_linear_func(v1, r1, v2, r2, sum)) : fann_linear_func(v2, r2, v3, r3, sum)) : (sum < v4 ? fann_linear_func(v3, r3, v4, r4, sum) : fann_linear_func(v4, r4, v5, r5, sum))) : (sum < v6 ? fann_linear_func(v5, r5, v6, r6, sum) : max))
|
34
|
+
|
35
|
+
/* FANN_LINEAR */
|
36
|
+
/* #define fann_linear(steepness, sum) fann_mult(steepness, sum) */
|
37
|
+
#define fann_linear_derive(steepness, value) (steepness)
|
38
|
+
|
39
|
+
/* FANN_SIGMOID */
|
40
|
+
/* #define fann_sigmoid(steepness, sum) (1.0f/(1.0f + exp(-2.0f * steepness * sum))) */
|
41
|
+
#define fann_sigmoid_real(sum) (1.0f/(1.0f + exp(-2.0f * sum)))
|
42
|
+
#define fann_sigmoid_derive(steepness, value) (2.0f * steepness * value * (1.0f - value))
|
43
|
+
|
44
|
+
/* FANN_SIGMOID_SYMMETRIC */
|
45
|
+
/* #define fann_sigmoid_symmetric(steepness, sum) (2.0f/(1.0f + exp(-2.0f * steepness * sum)) - 1.0f) */
|
46
|
+
#define fann_sigmoid_symmetric_real(sum) (2.0f/(1.0f + exp(-2.0f * sum)) - 1.0f)
|
47
|
+
#define fann_sigmoid_symmetric_derive(steepness, value) steepness * (1.0f - (value*value))
|
48
|
+
|
49
|
+
/* FANN_GAUSSIAN */
|
50
|
+
/* #define fann_gaussian(steepness, sum) (exp(-sum * steepness * sum * steepness)) */
|
51
|
+
#define fann_gaussian_real(sum) (exp(-sum * sum))
|
52
|
+
#define fann_gaussian_derive(steepness, value, sum) (-2.0f * sum * value * steepness * steepness)
|
53
|
+
|
54
|
+
/* FANN_GAUSSIAN_SYMMETRIC */
|
55
|
+
/* #define fann_gaussian_symmetric(steepness, sum) ((exp(-sum * steepness * sum * steepness)*2.0)-1.0) */
|
56
|
+
#define fann_gaussian_symmetric_real(sum) ((exp(-sum * sum)*2.0f)-1.0f)
|
57
|
+
#define fann_gaussian_symmetric_derive(steepness, value, sum) (-2.0f * sum * (value+1.0f) * steepness * steepness)
|
58
|
+
|
59
|
+
/* FANN_ELLIOT */
|
60
|
+
/* #define fann_elliot(steepness, sum) (((sum * steepness) / 2.0f) / (1.0f + fann_abs(sum * steepness)) + 0.5f) */
|
61
|
+
#define fann_elliot_real(sum) (((sum) / 2.0f) / (1.0f + fann_abs(sum)) + 0.5f)
|
62
|
+
#define fann_elliot_derive(steepness, value, sum) (steepness * 1.0f / (2.0f * (1.0f + fann_abs(sum)) * (1.0f + fann_abs(sum))))
|
63
|
+
|
64
|
+
/* FANN_ELLIOT_SYMMETRIC */
|
65
|
+
/* #define fann_elliot_symmetric(steepness, sum) ((sum * steepness) / (1.0f + fann_abs(sum * steepness)))*/
|
66
|
+
#define fann_elliot_symmetric_real(sum) ((sum) / (1.0f + fann_abs(sum)))
|
67
|
+
#define fann_elliot_symmetric_derive(steepness, value, sum) (steepness * 1.0f / ((1.0f + fann_abs(sum)) * (1.0f + fann_abs(sum))))
|
68
|
+
|
69
|
+
/* FANN_SIN_SYMMETRIC */
|
70
|
+
#define fann_sin_symmetric_real(sum) (sin(sum))
|
71
|
+
#define fann_sin_symmetric_derive(steepness, sum) (steepness*cos(steepness*sum))
|
72
|
+
|
73
|
+
/* FANN_COS_SYMMETRIC */
|
74
|
+
#define fann_cos_symmetric_real(sum) (cos(sum))
|
75
|
+
#define fann_cos_symmetric_derive(steepness, sum) (steepness*-sin(steepness*sum))
|
76
|
+
|
77
|
+
/* FANN_SIN */
|
78
|
+
#define fann_sin_real(sum) (sin(sum)/2.0f+0.5f)
|
79
|
+
#define fann_sin_derive(steepness, sum) (steepness*cos(steepness*sum)/2.0f)
|
80
|
+
|
81
|
+
/* FANN_COS */
|
82
|
+
#define fann_cos_real(sum) (cos(sum)/2.0f+0.5f)
|
83
|
+
#define fann_cos_derive(steepness, sum) (steepness*-sin(steepness*sum)/2.0f)
|
84
|
+
|
85
|
+
#define fann_activation_switch(activation_function, value, result) \
|
86
|
+
switch(activation_function) \
|
87
|
+
{ \
|
88
|
+
case FANN_LINEAR: \
|
89
|
+
result = (fann_type)value; \
|
90
|
+
break; \
|
91
|
+
case FANN_LINEAR_PIECE: \
|
92
|
+
result = (fann_type)((value < 0) ? 0 : (value > 1) ? 1 : value); \
|
93
|
+
break; \
|
94
|
+
case FANN_LINEAR_PIECE_SYMMETRIC: \
|
95
|
+
result = (fann_type)((value < -1) ? -1 : (value > 1) ? 1 : value); \
|
96
|
+
break; \
|
97
|
+
case FANN_SIGMOID: \
|
98
|
+
result = (fann_type)fann_sigmoid_real(value); \
|
99
|
+
break; \
|
100
|
+
case FANN_SIGMOID_SYMMETRIC: \
|
101
|
+
result = (fann_type)fann_sigmoid_symmetric_real(value); \
|
102
|
+
break; \
|
103
|
+
case FANN_SIGMOID_SYMMETRIC_STEPWISE: \
|
104
|
+
result = (fann_type)fann_stepwise(-2.64665293693542480469e+00, -1.47221934795379638672e+00, -5.49306154251098632812e-01, 5.49306154251098632812e-01, 1.47221934795379638672e+00, 2.64665293693542480469e+00, -9.90000009536743164062e-01, -8.99999976158142089844e-01, -5.00000000000000000000e-01, 5.00000000000000000000e-01, 8.99999976158142089844e-01, 9.90000009536743164062e-01, -1, 1, value); \
|
105
|
+
break; \
|
106
|
+
case FANN_SIGMOID_STEPWISE: \
|
107
|
+
result = (fann_type)fann_stepwise(-2.64665246009826660156e+00, -1.47221946716308593750e+00, -5.49306154251098632812e-01, 5.49306154251098632812e-01, 1.47221934795379638672e+00, 2.64665293693542480469e+00, 4.99999988824129104614e-03, 5.00000007450580596924e-02, 2.50000000000000000000e-01, 7.50000000000000000000e-01, 9.49999988079071044922e-01, 9.95000004768371582031e-01, 0, 1, value); \
|
108
|
+
break; \
|
109
|
+
case FANN_THRESHOLD: \
|
110
|
+
result = (fann_type)((value < 0) ? 0 : 1); \
|
111
|
+
break; \
|
112
|
+
case FANN_THRESHOLD_SYMMETRIC: \
|
113
|
+
result = (fann_type)((value < 0) ? -1 : 1); \
|
114
|
+
break; \
|
115
|
+
case FANN_GAUSSIAN: \
|
116
|
+
result = (fann_type)fann_gaussian_real(value); \
|
117
|
+
break; \
|
118
|
+
case FANN_GAUSSIAN_SYMMETRIC: \
|
119
|
+
result = (fann_type)fann_gaussian_symmetric_real(value); \
|
120
|
+
break; \
|
121
|
+
case FANN_ELLIOT: \
|
122
|
+
result = (fann_type)fann_elliot_real(value); \
|
123
|
+
break; \
|
124
|
+
case FANN_ELLIOT_SYMMETRIC: \
|
125
|
+
result = (fann_type)fann_elliot_symmetric_real(value); \
|
126
|
+
break; \
|
127
|
+
case FANN_SIN_SYMMETRIC: \
|
128
|
+
result = (fann_type)fann_sin_symmetric_real(value); \
|
129
|
+
break; \
|
130
|
+
case FANN_COS_SYMMETRIC: \
|
131
|
+
result = (fann_type)fann_cos_symmetric_real(value); \
|
132
|
+
break; \
|
133
|
+
case FANN_SIN: \
|
134
|
+
result = (fann_type)fann_sin_real(value); \
|
135
|
+
break; \
|
136
|
+
case FANN_COS: \
|
137
|
+
result = (fann_type)fann_cos_real(value); \
|
138
|
+
break; \
|
139
|
+
case FANN_GAUSSIAN_STEPWISE: \
|
140
|
+
result = 0; \
|
141
|
+
break; \
|
142
|
+
}
|
143
|
+
|
144
|
+
#endif
|
File without changes
|