alglib 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. data/History.txt +7 -0
  2. data/Manifest.txt +253 -0
  3. data/README.txt +33 -0
  4. data/Rakefile +27 -0
  5. data/ext/Rakefile +24 -0
  6. data/ext/alglib.i +24 -0
  7. data/ext/alglib/Makefile +157 -0
  8. data/ext/alglib/airyf.cpp +372 -0
  9. data/ext/alglib/airyf.h +81 -0
  10. data/ext/alglib/alglib.cpp +8558 -0
  11. data/ext/alglib/alglib_util.cpp +19 -0
  12. data/ext/alglib/alglib_util.h +14 -0
  13. data/ext/alglib/ap.cpp +877 -0
  14. data/ext/alglib/ap.english.html +364 -0
  15. data/ext/alglib/ap.h +666 -0
  16. data/ext/alglib/ap.russian.html +442 -0
  17. data/ext/alglib/apvt.h +754 -0
  18. data/ext/alglib/bdss.cpp +1500 -0
  19. data/ext/alglib/bdss.h +251 -0
  20. data/ext/alglib/bdsvd.cpp +1339 -0
  21. data/ext/alglib/bdsvd.h +164 -0
  22. data/ext/alglib/bessel.cpp +1226 -0
  23. data/ext/alglib/bessel.h +331 -0
  24. data/ext/alglib/betaf.cpp +105 -0
  25. data/ext/alglib/betaf.h +74 -0
  26. data/ext/alglib/bidiagonal.cpp +1328 -0
  27. data/ext/alglib/bidiagonal.h +350 -0
  28. data/ext/alglib/binomialdistr.cpp +247 -0
  29. data/ext/alglib/binomialdistr.h +153 -0
  30. data/ext/alglib/blas.cpp +576 -0
  31. data/ext/alglib/blas.h +132 -0
  32. data/ext/alglib/cblas.cpp +226 -0
  33. data/ext/alglib/cblas.h +57 -0
  34. data/ext/alglib/cdet.cpp +138 -0
  35. data/ext/alglib/cdet.h +92 -0
  36. data/ext/alglib/chebyshev.cpp +216 -0
  37. data/ext/alglib/chebyshev.h +76 -0
  38. data/ext/alglib/chisquaredistr.cpp +157 -0
  39. data/ext/alglib/chisquaredistr.h +144 -0
  40. data/ext/alglib/cholesky.cpp +285 -0
  41. data/ext/alglib/cholesky.h +86 -0
  42. data/ext/alglib/cinverse.cpp +298 -0
  43. data/ext/alglib/cinverse.h +111 -0
  44. data/ext/alglib/clu.cpp +337 -0
  45. data/ext/alglib/clu.h +120 -0
  46. data/ext/alglib/correlation.cpp +280 -0
  47. data/ext/alglib/correlation.h +77 -0
  48. data/ext/alglib/correlationtests.cpp +726 -0
  49. data/ext/alglib/correlationtests.h +134 -0
  50. data/ext/alglib/crcond.cpp +826 -0
  51. data/ext/alglib/crcond.h +148 -0
  52. data/ext/alglib/creflections.cpp +310 -0
  53. data/ext/alglib/creflections.h +165 -0
  54. data/ext/alglib/csolve.cpp +312 -0
  55. data/ext/alglib/csolve.h +99 -0
  56. data/ext/alglib/ctrinverse.cpp +387 -0
  57. data/ext/alglib/ctrinverse.h +98 -0
  58. data/ext/alglib/ctrlinsolve.cpp +297 -0
  59. data/ext/alglib/ctrlinsolve.h +81 -0
  60. data/ext/alglib/dawson.cpp +234 -0
  61. data/ext/alglib/dawson.h +74 -0
  62. data/ext/alglib/descriptivestatistics.cpp +436 -0
  63. data/ext/alglib/descriptivestatistics.h +112 -0
  64. data/ext/alglib/det.cpp +140 -0
  65. data/ext/alglib/det.h +94 -0
  66. data/ext/alglib/dforest.cpp +1819 -0
  67. data/ext/alglib/dforest.h +316 -0
  68. data/ext/alglib/elliptic.cpp +497 -0
  69. data/ext/alglib/elliptic.h +217 -0
  70. data/ext/alglib/estnorm.cpp +429 -0
  71. data/ext/alglib/estnorm.h +107 -0
  72. data/ext/alglib/expintegrals.cpp +422 -0
  73. data/ext/alglib/expintegrals.h +108 -0
  74. data/ext/alglib/faq.english.html +258 -0
  75. data/ext/alglib/faq.russian.html +272 -0
  76. data/ext/alglib/fdistr.cpp +202 -0
  77. data/ext/alglib/fdistr.h +163 -0
  78. data/ext/alglib/fresnel.cpp +211 -0
  79. data/ext/alglib/fresnel.h +91 -0
  80. data/ext/alglib/gammaf.cpp +338 -0
  81. data/ext/alglib/gammaf.h +104 -0
  82. data/ext/alglib/gqgengauss.cpp +235 -0
  83. data/ext/alglib/gqgengauss.h +92 -0
  84. data/ext/alglib/gqgenhermite.cpp +268 -0
  85. data/ext/alglib/gqgenhermite.h +63 -0
  86. data/ext/alglib/gqgenjacobi.cpp +297 -0
  87. data/ext/alglib/gqgenjacobi.h +72 -0
  88. data/ext/alglib/gqgenlaguerre.cpp +265 -0
  89. data/ext/alglib/gqgenlaguerre.h +69 -0
  90. data/ext/alglib/gqgenlegendre.cpp +300 -0
  91. data/ext/alglib/gqgenlegendre.h +62 -0
  92. data/ext/alglib/gqgenlobatto.cpp +305 -0
  93. data/ext/alglib/gqgenlobatto.h +97 -0
  94. data/ext/alglib/gqgenradau.cpp +232 -0
  95. data/ext/alglib/gqgenradau.h +95 -0
  96. data/ext/alglib/hbisinv.cpp +480 -0
  97. data/ext/alglib/hbisinv.h +183 -0
  98. data/ext/alglib/hblas.cpp +228 -0
  99. data/ext/alglib/hblas.h +64 -0
  100. data/ext/alglib/hcholesky.cpp +339 -0
  101. data/ext/alglib/hcholesky.h +91 -0
  102. data/ext/alglib/hermite.cpp +114 -0
  103. data/ext/alglib/hermite.h +49 -0
  104. data/ext/alglib/hessenberg.cpp +370 -0
  105. data/ext/alglib/hessenberg.h +152 -0
  106. data/ext/alglib/hevd.cpp +247 -0
  107. data/ext/alglib/hevd.h +107 -0
  108. data/ext/alglib/hsschur.cpp +1316 -0
  109. data/ext/alglib/hsschur.h +108 -0
  110. data/ext/alglib/htridiagonal.cpp +734 -0
  111. data/ext/alglib/htridiagonal.h +180 -0
  112. data/ext/alglib/ialglib.cpp +6 -0
  113. data/ext/alglib/ialglib.h +9 -0
  114. data/ext/alglib/ibetaf.cpp +960 -0
  115. data/ext/alglib/ibetaf.h +125 -0
  116. data/ext/alglib/igammaf.cpp +430 -0
  117. data/ext/alglib/igammaf.h +157 -0
  118. data/ext/alglib/inv.cpp +274 -0
  119. data/ext/alglib/inv.h +115 -0
  120. data/ext/alglib/inverseupdate.cpp +480 -0
  121. data/ext/alglib/inverseupdate.h +185 -0
  122. data/ext/alglib/jacobianelliptic.cpp +164 -0
  123. data/ext/alglib/jacobianelliptic.h +94 -0
  124. data/ext/alglib/jarquebera.cpp +2271 -0
  125. data/ext/alglib/jarquebera.h +80 -0
  126. data/ext/alglib/kmeans.cpp +356 -0
  127. data/ext/alglib/kmeans.h +76 -0
  128. data/ext/alglib/laguerre.cpp +94 -0
  129. data/ext/alglib/laguerre.h +48 -0
  130. data/ext/alglib/lbfgs.cpp +1167 -0
  131. data/ext/alglib/lbfgs.h +218 -0
  132. data/ext/alglib/lda.cpp +434 -0
  133. data/ext/alglib/lda.h +133 -0
  134. data/ext/alglib/ldlt.cpp +1130 -0
  135. data/ext/alglib/ldlt.h +124 -0
  136. data/ext/alglib/leastsquares.cpp +1252 -0
  137. data/ext/alglib/leastsquares.h +290 -0
  138. data/ext/alglib/legendre.cpp +107 -0
  139. data/ext/alglib/legendre.h +49 -0
  140. data/ext/alglib/linreg.cpp +1185 -0
  141. data/ext/alglib/linreg.h +380 -0
  142. data/ext/alglib/logit.cpp +1523 -0
  143. data/ext/alglib/logit.h +333 -0
  144. data/ext/alglib/lq.cpp +399 -0
  145. data/ext/alglib/lq.h +160 -0
  146. data/ext/alglib/lu.cpp +462 -0
  147. data/ext/alglib/lu.h +119 -0
  148. data/ext/alglib/mannwhitneyu.cpp +4490 -0
  149. data/ext/alglib/mannwhitneyu.h +115 -0
  150. data/ext/alglib/minlm.cpp +918 -0
  151. data/ext/alglib/minlm.h +312 -0
  152. data/ext/alglib/mlpbase.cpp +3375 -0
  153. data/ext/alglib/mlpbase.h +589 -0
  154. data/ext/alglib/mlpe.cpp +1369 -0
  155. data/ext/alglib/mlpe.h +552 -0
  156. data/ext/alglib/mlptrain.cpp +1056 -0
  157. data/ext/alglib/mlptrain.h +283 -0
  158. data/ext/alglib/nearunityunit.cpp +91 -0
  159. data/ext/alglib/nearunityunit.h +17 -0
  160. data/ext/alglib/normaldistr.cpp +377 -0
  161. data/ext/alglib/normaldistr.h +175 -0
  162. data/ext/alglib/nsevd.cpp +1869 -0
  163. data/ext/alglib/nsevd.h +140 -0
  164. data/ext/alglib/pca.cpp +168 -0
  165. data/ext/alglib/pca.h +87 -0
  166. data/ext/alglib/poissondistr.cpp +143 -0
  167. data/ext/alglib/poissondistr.h +130 -0
  168. data/ext/alglib/polinterpolation.cpp +685 -0
  169. data/ext/alglib/polinterpolation.h +206 -0
  170. data/ext/alglib/psif.cpp +173 -0
  171. data/ext/alglib/psif.h +88 -0
  172. data/ext/alglib/qr.cpp +414 -0
  173. data/ext/alglib/qr.h +168 -0
  174. data/ext/alglib/ratinterpolation.cpp +134 -0
  175. data/ext/alglib/ratinterpolation.h +72 -0
  176. data/ext/alglib/rcond.cpp +705 -0
  177. data/ext/alglib/rcond.h +140 -0
  178. data/ext/alglib/reflections.cpp +504 -0
  179. data/ext/alglib/reflections.h +165 -0
  180. data/ext/alglib/rotations.cpp +473 -0
  181. data/ext/alglib/rotations.h +128 -0
  182. data/ext/alglib/rsolve.cpp +221 -0
  183. data/ext/alglib/rsolve.h +99 -0
  184. data/ext/alglib/sbisinv.cpp +217 -0
  185. data/ext/alglib/sbisinv.h +171 -0
  186. data/ext/alglib/sblas.cpp +185 -0
  187. data/ext/alglib/sblas.h +64 -0
  188. data/ext/alglib/schur.cpp +156 -0
  189. data/ext/alglib/schur.h +102 -0
  190. data/ext/alglib/sdet.cpp +193 -0
  191. data/ext/alglib/sdet.h +101 -0
  192. data/ext/alglib/sevd.cpp +116 -0
  193. data/ext/alglib/sevd.h +99 -0
  194. data/ext/alglib/sinverse.cpp +672 -0
  195. data/ext/alglib/sinverse.h +138 -0
  196. data/ext/alglib/spddet.cpp +138 -0
  197. data/ext/alglib/spddet.h +96 -0
  198. data/ext/alglib/spdgevd.cpp +842 -0
  199. data/ext/alglib/spdgevd.h +200 -0
  200. data/ext/alglib/spdinverse.cpp +509 -0
  201. data/ext/alglib/spdinverse.h +122 -0
  202. data/ext/alglib/spdrcond.cpp +421 -0
  203. data/ext/alglib/spdrcond.h +118 -0
  204. data/ext/alglib/spdsolve.cpp +275 -0
  205. data/ext/alglib/spdsolve.h +105 -0
  206. data/ext/alglib/spline2d.cpp +1192 -0
  207. data/ext/alglib/spline2d.h +301 -0
  208. data/ext/alglib/spline3.cpp +1264 -0
  209. data/ext/alglib/spline3.h +290 -0
  210. data/ext/alglib/srcond.cpp +595 -0
  211. data/ext/alglib/srcond.h +127 -0
  212. data/ext/alglib/ssolve.cpp +895 -0
  213. data/ext/alglib/ssolve.h +139 -0
  214. data/ext/alglib/stdafx.h +0 -0
  215. data/ext/alglib/stest.cpp +131 -0
  216. data/ext/alglib/stest.h +94 -0
  217. data/ext/alglib/studenttdistr.cpp +222 -0
  218. data/ext/alglib/studenttdistr.h +115 -0
  219. data/ext/alglib/studentttests.cpp +377 -0
  220. data/ext/alglib/studentttests.h +178 -0
  221. data/ext/alglib/svd.cpp +620 -0
  222. data/ext/alglib/svd.h +126 -0
  223. data/ext/alglib/tdbisinv.cpp +2608 -0
  224. data/ext/alglib/tdbisinv.h +228 -0
  225. data/ext/alglib/tdevd.cpp +1229 -0
  226. data/ext/alglib/tdevd.h +115 -0
  227. data/ext/alglib/tridiagonal.cpp +594 -0
  228. data/ext/alglib/tridiagonal.h +171 -0
  229. data/ext/alglib/trigintegrals.cpp +490 -0
  230. data/ext/alglib/trigintegrals.h +131 -0
  231. data/ext/alglib/trinverse.cpp +345 -0
  232. data/ext/alglib/trinverse.h +98 -0
  233. data/ext/alglib/trlinsolve.cpp +926 -0
  234. data/ext/alglib/trlinsolve.h +73 -0
  235. data/ext/alglib/tsort.cpp +405 -0
  236. data/ext/alglib/tsort.h +54 -0
  237. data/ext/alglib/variancetests.cpp +245 -0
  238. data/ext/alglib/variancetests.h +134 -0
  239. data/ext/alglib/wsr.cpp +6285 -0
  240. data/ext/alglib/wsr.h +96 -0
  241. data/ext/ap.i +97 -0
  242. data/ext/correlation.i +24 -0
  243. data/ext/extconf.rb +6 -0
  244. data/ext/logit.i +89 -0
  245. data/lib/alglib.rb +71 -0
  246. data/lib/alglib/correlation.rb +26 -0
  247. data/lib/alglib/linearregression.rb +63 -0
  248. data/lib/alglib/logit.rb +42 -0
  249. data/test/test_alglib.rb +52 -0
  250. data/test/test_correlation.rb +44 -0
  251. data/test/test_correlationtest.rb +45 -0
  252. data/test/test_linreg.rb +35 -0
  253. data/test/test_logit.rb +43 -0
  254. data/test/test_pca.rb +27 -0
  255. metadata +326 -0
@@ -0,0 +1,283 @@
1
+ /*************************************************************************
2
+ Copyright (c) 2007-2008, Sergey Bochkanov (ALGLIB project).
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ - Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ - Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer listed
13
+ in this license in the documentation and/or other materials
14
+ provided with the distribution.
15
+
16
+ - Neither the name of the copyright holders nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *************************************************************************/
32
+
33
+ #ifndef _mlptrain_h
34
+ #define _mlptrain_h
35
+
36
+ #include "ap.h"
37
+ #include "ialglib.h"
38
+
39
+ #include "mlpbase.h"
40
+ #include "trinverse.h"
41
+ #include "lbfgs.h"
42
+ #include "cholesky.h"
43
+ #include "spdsolve.h"
44
+
45
+
46
+ struct mlpreport
47
+ {
48
+ int ngrad;
49
+ int nhess;
50
+ int ncholesky;
51
+ };
52
+ struct mlpcvreport
53
+ {
54
+ double relclserror;
55
+ double avgce;
56
+ double rmserror;
57
+ double avgerror;
58
+ double avgrelerror;
59
+ };
60
+
61
+
62
+ /*************************************************************************
63
+ Neural network training using modified Levenberg-Marquardt with exact
64
+ Hessian calculation and regularization. Subroutine trains neural network
65
+ with restarts from random positions. Algorithm is well suited for small
66
+ and medium scale problems (hundreds of weights).
67
+
68
+ INPUT PARAMETERS:
69
+ Network - neural network with initialized geometry
70
+ XY - training set
71
+ NPoints - training set size
72
+ Decay - weight decay constant, >=0.001
73
+ Decay term 'Decay*||Weights||^2' is added to error
74
+ function.
75
+ If you don't know what Decay to choose, use 0.001.
76
+ Restarts - number of restarts from random position, >0.
77
+ If you don't know what Restarts to choose, use 2.
78
+
79
+ OUTPUT PARAMETERS:
80
+ Network - trained neural network.
81
+ Info - return code:
82
+ * -9, if internal matrix inverse subroutine failed
83
+ * -2, if there is a point with class number
84
+ outside of [0..NOut-1].
85
+ * -1, if wrong parameters specified
86
+ (NPoints<0, Restarts<1).
87
+ * 2, if task has been solved.
88
+ Rep - training report
89
+
90
+ -- ALGLIB --
91
+ Copyright 10.03.2009 by Bochkanov Sergey
92
+ *************************************************************************/
93
+ void mlptrainlm(multilayerperceptron& network,
94
+ const ap::real_2d_array& xy,
95
+ int npoints,
96
+ double decay,
97
+ int restarts,
98
+ int& info,
99
+ mlpreport& rep);
100
+
101
+
102
+ /*************************************************************************
103
+ Neural network training using L-BFGS algorithm with regularization.
104
+ Subroutine trains neural network with restarts from random positions.
105
+ Algorithm is well suited for problems of any dimensionality (memory
106
+ requirements and step complexity are linear by weights number).
107
+
108
+ INPUT PARAMETERS:
109
+ Network - neural network with initialized geometry
110
+ XY - training set
111
+ NPoints - training set size
112
+ Decay - weight decay constant, >=0.001
113
+ Decay term 'Decay*||Weights||^2' is added to error
114
+ function.
115
+ If you don't know what Decay to choose, use 0.001.
116
+ Restarts - number of restarts from random position, >0.
117
+ If you don't know what Restarts to choose, use 2.
118
+ WStep - stopping criterion. Algorithm stops if step size is
119
+ less than WStep. Recommended value - 0.01. Zero step
120
+ size means stopping after MaxIts iterations.
121
+ MaxIts - stopping criterion. Algorithm stops after MaxIts
122
+ iterations (NOT gradient calculations). Zero MaxIts
123
+ means stopping when step is sufficiently small.
124
+
125
+ OUTPUT PARAMETERS:
126
+ Network - trained neural network.
127
+ Info - return code:
128
+ * -8, if both WStep=0 and MaxIts=0
129
+ * -2, if there is a point with class number
130
+ outside of [0..NOut-1].
131
+ * -1, if wrong parameters specified
132
+ (NPoints<0, Restarts<1).
133
+ * 2, if task has been solved.
134
+ Rep - training report
135
+
136
+ -- ALGLIB --
137
+ Copyright 09.12.2007 by Bochkanov Sergey
138
+ *************************************************************************/
139
+ void mlptrainlbfgs(multilayerperceptron& network,
140
+ const ap::real_2d_array& xy,
141
+ int npoints,
142
+ double decay,
143
+ int restarts,
144
+ double wstep,
145
+ int maxits,
146
+ int& info,
147
+ mlpreport& rep);
148
+
149
+
150
+ /*************************************************************************
151
+ Neural network training using early stopping (base algorithm - L-BFGS with
152
+ regularization).
153
+
154
+ INPUT PARAMETERS:
155
+ Network - neural network with initialized geometry
156
+ TrnXY - training set
157
+ TrnSize - training set size
158
+ ValXY - validation set
159
+ ValSize - validation set size
160
+ Decay - weight decay constant, >=0.001
161
+ Decay term 'Decay*||Weights||^2' is added to error
162
+ function.
163
+ If you don't know what Decay to choose, use 0.001.
164
+ Restarts - number of restarts from random position, >0.
165
+ If you don't know what Restarts to choose, use 2.
166
+
167
+ OUTPUT PARAMETERS:
168
+ Network - trained neural network.
169
+ Info - return code:
170
+ * -2, if there is a point with class number
171
+ outside of [0..NOut-1].
172
+ * -1, if wrong parameters specified
173
+ (NPoints<0, Restarts<1, ...).
174
+ * 2, task has been solved, stopping criterion met -
175
+ sufficiently small step size. Not expected (we
176
+ use EARLY stopping) but possible and not an
177
+ error.
178
+ * 6, task has been solved, stopping criterion met -
179
+ increasing of validation set error.
180
+ Rep - training report
181
+
182
+ NOTE:
183
+
184
+ Algorithm stops if validation set error increases for a long enough or
185
+ step size is small enought (there are task where validation set may
186
+ decrease for eternity). In any case solution returned corresponds to the
187
+ minimum of validation set error.
188
+
189
+ -- ALGLIB --
190
+ Copyright 10.03.2009 by Bochkanov Sergey
191
+ *************************************************************************/
192
+ void mlptraines(multilayerperceptron& network,
193
+ const ap::real_2d_array& trnxy,
194
+ int trnsize,
195
+ const ap::real_2d_array& valxy,
196
+ int valsize,
197
+ double decay,
198
+ int restarts,
199
+ int& info,
200
+ mlpreport& rep);
201
+
202
+
203
+ /*************************************************************************
204
+ Cross-validation estimate of generalization error.
205
+
206
+ Base algorithm - L-BFGS.
207
+
208
+ INPUT PARAMETERS:
209
+ Network - neural network with initialized geometry. Network is
210
+ not changed during cross-validation - it is used only
211
+ as a representative of its architecture.
212
+ XY - training set.
213
+ SSize - training set size
214
+ Decay - weight decay, same as in MLPTrainLBFGS
215
+ Restarts - number of restarts, >0.
216
+ restarts are counted for each partition separately, so
217
+ total number of restarts will be Restarts*FoldsCount.
218
+ WStep - stopping criterion, same as in MLPTrainLBFGS
219
+ MaxIts - stopping criterion, same as in MLPTrainLBFGS
220
+ FoldsCount - number of folds in k-fold cross-validation,
221
+ 2<=FoldsCount<=SSize.
222
+ recommended value: 10.
223
+
224
+ OUTPUT PARAMETERS:
225
+ Info - return code, same as in MLPTrainLBFGS
226
+ Rep - report, same as in MLPTrainLM/MLPTrainLBFGS
227
+ CVRep - generalization error estimates
228
+
229
+ -- ALGLIB --
230
+ Copyright 09.12.2007 by Bochkanov Sergey
231
+ *************************************************************************/
232
+ void mlpkfoldcvlbfgs(const multilayerperceptron& network,
233
+ const ap::real_2d_array& xy,
234
+ int npoints,
235
+ double decay,
236
+ int restarts,
237
+ double wstep,
238
+ int maxits,
239
+ int foldscount,
240
+ int& info,
241
+ mlpreport& rep,
242
+ mlpcvreport& cvrep);
243
+
244
+
245
+ /*************************************************************************
246
+ Cross-validation estimate of generalization error.
247
+
248
+ Base algorithm - Levenberg-Marquardt.
249
+
250
+ INPUT PARAMETERS:
251
+ Network - neural network with initialized geometry. Network is
252
+ not changed during cross-validation - it is used only
253
+ as a representative of its architecture.
254
+ XY - training set.
255
+ SSize - training set size
256
+ Decay - weight decay, same as in MLPTrainLBFGS
257
+ Restarts - number of restarts, >0.
258
+ restarts are counted for each partition separately, so
259
+ total number of restarts will be Restarts*FoldsCount.
260
+ FoldsCount - number of folds in k-fold cross-validation,
261
+ 2<=FoldsCount<=SSize.
262
+ recommended value: 10.
263
+
264
+ OUTPUT PARAMETERS:
265
+ Info - return code, same as in MLPTrainLBFGS
266
+ Rep - report, same as in MLPTrainLM/MLPTrainLBFGS
267
+ CVRep - generalization error estimates
268
+
269
+ -- ALGLIB --
270
+ Copyright 09.12.2007 by Bochkanov Sergey
271
+ *************************************************************************/
272
+ void mlpkfoldcvlm(const multilayerperceptron& network,
273
+ const ap::real_2d_array& xy,
274
+ int npoints,
275
+ double decay,
276
+ int restarts,
277
+ int foldscount,
278
+ int& info,
279
+ mlpreport& rep,
280
+ mlpcvreport& cvrep);
281
+
282
+
283
+ #endif
@@ -0,0 +1,91 @@
1
+
2
+ #include <stdafx.h>
3
+ #include "nearunityunit.h"
4
+
5
+ double log1p(double x)
6
+ {
7
+ double result;
8
+ double z;
9
+ double lp;
10
+ double lq;
11
+
12
+ z = 1.0+x;
13
+ if( z<0.70710678118654752440||z>1.41421356237309504880 )
14
+ {
15
+ result = log(z);
16
+ return result;
17
+ }
18
+ z = x*x;
19
+ lp = 4.5270000862445199635215E-5;
20
+ lp = lp*x+4.9854102823193375972212E-1;
21
+ lp = lp*x+6.5787325942061044846969E0;
22
+ lp = lp*x+2.9911919328553073277375E1;
23
+ lp = lp*x+6.0949667980987787057556E1;
24
+ lp = lp*x+5.7112963590585538103336E1;
25
+ lp = lp*x+2.0039553499201281259648E1;
26
+ lq = 1.0000000000000000000000E0;
27
+ lq = lq*x+1.5062909083469192043167E1;
28
+ lq = lq*x+8.3047565967967209469434E1;
29
+ lq = lq*x+2.2176239823732856465394E2;
30
+ lq = lq*x+3.0909872225312059774938E2;
31
+ lq = lq*x+2.1642788614495947685003E2;
32
+ lq = lq*x+6.0118660497603843919306E1;
33
+ z = -0.5*z+x*(z*lp/lq);
34
+ result = x+z;
35
+ return result;
36
+ }
37
+
38
+
39
+ double expm1(double x)
40
+ {
41
+ double result;
42
+ double r;
43
+ double xx;
44
+ double ep;
45
+ double eq;
46
+
47
+ if( x<-0.5||x>0.5 )
48
+ {
49
+ result = exp(x)-1.0;
50
+ return result;
51
+ }
52
+ xx = x*x;
53
+ ep = 1.2617719307481059087798E-4;
54
+ ep = ep*xx+3.0299440770744196129956E-2;
55
+ ep = ep*xx+9.9999999999999999991025E-1;
56
+ eq = 3.0019850513866445504159E-6;
57
+ eq = eq*xx+2.5244834034968410419224E-3;
58
+ eq = eq*xx+2.2726554820815502876593E-1;
59
+ eq = eq*xx+2.0000000000000000000897E0;
60
+ r = x*ep;
61
+ r = r/(eq-r);
62
+ result = r+r;
63
+ return result;
64
+ }
65
+
66
+
67
+ double cosm1(double x)
68
+ {
69
+ double result;
70
+ double xx;
71
+ double c;
72
+
73
+ if( x<-0.25*ap::pi()||x>0.25*ap::pi() )
74
+ {
75
+ result = cos(x)-1;
76
+ return result;
77
+ }
78
+ xx = x*x;
79
+ c = 4.7377507964246204691685E-14;
80
+ c = c*xx-1.1470284843425359765671E-11;
81
+ c = c*xx+2.0876754287081521758361E-9;
82
+ c = c*xx-2.7557319214999787979814E-7;
83
+ c = c*xx+2.4801587301570552304991E-5;
84
+ c = c*xx-1.3888888888888872993737E-3;
85
+ c = c*xx+4.1666666666666666609054E-2;
86
+ result = -0.5*xx+xx*xx*c;
87
+ return result;
88
+ }
89
+
90
+
91
+
@@ -0,0 +1,17 @@
1
+
2
+ #ifndef _nearunityunit_h
3
+ #define _nearunityunit_h
4
+
5
+ #include "ap.h"
6
+ #include "ialglib.h"
7
+
8
+ double log1p(double x);
9
+
10
+
11
+ double expm1(double x);
12
+
13
+
14
+ double cosm1(double x);
15
+
16
+
17
+ #endif
@@ -0,0 +1,377 @@
1
+ /*************************************************************************
2
+ Cephes Math Library Release 2.8: June, 2000
3
+ Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
4
+
5
+ Contributors:
6
+ * Sergey Bochkanov (ALGLIB project). Translation from C to
7
+ pseudocode.
8
+
9
+ See subroutines comments for additional copyrights.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are
13
+ met:
14
+
15
+ - Redistributions of source code must retain the above copyright
16
+ notice, this list of conditions and the following disclaimer.
17
+
18
+ - Redistributions in binary form must reproduce the above copyright
19
+ notice, this list of conditions and the following disclaimer listed
20
+ in this license in the documentation and/or other materials
21
+ provided with the distribution.
22
+
23
+ - Neither the name of the copyright holders nor the names of its
24
+ contributors may be used to endorse or promote products derived from
25
+ this software without specific prior written permission.
26
+
27
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
+ *************************************************************************/
39
+
40
+ #include <stdafx.h>
41
+ #include "normaldistr.h"
42
+
43
+ /*************************************************************************
44
+ Error function
45
+
46
+ The integral is
47
+
48
+ x
49
+ -
50
+ 2 | | 2
51
+ erf(x) = -------- | exp( - t ) dt.
52
+ sqrt(pi) | |
53
+ -
54
+ 0
55
+
56
+ For 0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2); otherwise
57
+ erf(x) = 1 - erfc(x).
58
+
59
+
60
+ ACCURACY:
61
+
62
+ Relative error:
63
+ arithmetic domain # trials peak rms
64
+ IEEE 0,1 30000 3.7e-16 1.0e-16
65
+
66
+ Cephes Math Library Release 2.8: June, 2000
67
+ Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
68
+ *************************************************************************/
69
+ double erf(double x)
70
+ {
71
+ double result;
72
+ double xsq;
73
+ double s;
74
+ double p;
75
+ double q;
76
+
77
+ s = ap::sign(x);
78
+ x = fabs(x);
79
+ if( x<0.5 )
80
+ {
81
+ xsq = x*x;
82
+ p = 0.007547728033418631287834;
83
+ p = 0.288805137207594084924010+xsq*p;
84
+ p = 14.3383842191748205576712+xsq*p;
85
+ p = 38.0140318123903008244444+xsq*p;
86
+ p = 3017.82788536507577809226+xsq*p;
87
+ p = 7404.07142710151470082064+xsq*p;
88
+ p = 80437.3630960840172832162+xsq*p;
89
+ q = 0.0;
90
+ q = 1.00000000000000000000000+xsq*q;
91
+ q = 38.0190713951939403753468+xsq*q;
92
+ q = 658.070155459240506326937+xsq*q;
93
+ q = 6379.60017324428279487120+xsq*q;
94
+ q = 34216.5257924628539769006+xsq*q;
95
+ q = 80437.3630960840172826266+xsq*q;
96
+ result = s*1.1283791670955125738961589031*x*p/q;
97
+ return result;
98
+ }
99
+ if( x>=10 )
100
+ {
101
+ result = s;
102
+ return result;
103
+ }
104
+ result = s*(1-erfc(x));
105
+ return result;
106
+ }
107
+
108
+
109
+ /*************************************************************************
110
+ Complementary error function
111
+
112
+ 1 - erf(x) =
113
+
114
+ inf.
115
+ -
116
+ 2 | | 2
117
+ erfc(x) = -------- | exp( - t ) dt
118
+ sqrt(pi) | |
119
+ -
120
+ x
121
+
122
+
123
+ For small x, erfc(x) = 1 - erf(x); otherwise rational
124
+ approximations are computed.
125
+
126
+
127
+ ACCURACY:
128
+
129
+ Relative error:
130
+ arithmetic domain # trials peak rms
131
+ IEEE 0,26.6417 30000 5.7e-14 1.5e-14
132
+
133
+ Cephes Math Library Release 2.8: June, 2000
134
+ Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
135
+ *************************************************************************/
136
+ double erfc(double x)
137
+ {
138
+ double result;
139
+ double p;
140
+ double q;
141
+
142
+ if( x<0 )
143
+ {
144
+ result = 2-erfc(-x);
145
+ return result;
146
+ }
147
+ if( x<0.5 )
148
+ {
149
+ result = 1.0-erf(x);
150
+ return result;
151
+ }
152
+ if( x>=10 )
153
+ {
154
+ result = 0;
155
+ return result;
156
+ }
157
+ p = 0.0;
158
+ p = 0.5641877825507397413087057563+x*p;
159
+ p = 9.675807882987265400604202961+x*p;
160
+ p = 77.08161730368428609781633646+x*p;
161
+ p = 368.5196154710010637133875746+x*p;
162
+ p = 1143.262070703886173606073338+x*p;
163
+ p = 2320.439590251635247384768711+x*p;
164
+ p = 2898.0293292167655611275846+x*p;
165
+ p = 1826.3348842295112592168999+x*p;
166
+ q = 1.0;
167
+ q = 17.14980943627607849376131193+x*q;
168
+ q = 137.1255960500622202878443578+x*q;
169
+ q = 661.7361207107653469211984771+x*q;
170
+ q = 2094.384367789539593790281779+x*q;
171
+ q = 4429.612803883682726711528526+x*q;
172
+ q = 6089.5424232724435504633068+x*q;
173
+ q = 4958.82756472114071495438422+x*q;
174
+ q = 1826.3348842295112595576438+x*q;
175
+ result = exp(-ap::sqr(x))*p/q;
176
+ return result;
177
+ }
178
+
179
+
180
+ /*************************************************************************
181
+ Normal distribution function
182
+
183
+ Returns the area under the Gaussian probability density
184
+ function, integrated from minus infinity to x:
185
+
186
+ x
187
+ -
188
+ 1 | | 2
189
+ ndtr(x) = --------- | exp( - t /2 ) dt
190
+ sqrt(2pi) | |
191
+ -
192
+ -inf.
193
+
194
+ = ( 1 + erf(z) ) / 2
195
+ = erfc(z) / 2
196
+
197
+ where z = x/sqrt(2). Computation is via the functions
198
+ erf and erfc.
199
+
200
+
201
+ ACCURACY:
202
+
203
+ Relative error:
204
+ arithmetic domain # trials peak rms
205
+ IEEE -13,0 30000 3.4e-14 6.7e-15
206
+
207
+ Cephes Math Library Release 2.8: June, 2000
208
+ Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
209
+ *************************************************************************/
210
+ double normaldistribution(double x)
211
+ {
212
+ double result;
213
+
214
+ result = 0.5*(erf(x/1.41421356237309504880)+1);
215
+ return result;
216
+ }
217
+
218
+
219
+ /*************************************************************************
220
+ Inverse of the error function
221
+
222
+ Cephes Math Library Release 2.8: June, 2000
223
+ Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
224
+ *************************************************************************/
225
+ double inverf(double e)
226
+ {
227
+ double result;
228
+
229
+ result = invnormaldistribution(0.5*(e+1))/sqrt(double(2));
230
+ return result;
231
+ }
232
+
233
+
234
+ /*************************************************************************
235
+ Inverse of Normal distribution function
236
+
237
+ Returns the argument, x, for which the area under the
238
+ Gaussian probability density function (integrated from
239
+ minus infinity to x) is equal to y.
240
+
241
+
242
+ For small arguments 0 < y < exp(-2), the program computes
243
+ z = sqrt( -2.0 * log(y) ); then the approximation is
244
+ x = z - log(z)/z - (1/z) P(1/z) / Q(1/z).
245
+ There are two rational functions P/Q, one for 0 < y < exp(-32)
246
+ and the other for y up to exp(-2). For larger arguments,
247
+ w = y - 0.5, and x/sqrt(2pi) = w + w**3 R(w**2)/S(w**2)).
248
+
249
+ ACCURACY:
250
+
251
+ Relative error:
252
+ arithmetic domain # trials peak rms
253
+ IEEE 0.125, 1 20000 7.2e-16 1.3e-16
254
+ IEEE 3e-308, 0.135 50000 4.6e-16 9.8e-17
255
+
256
+ Cephes Math Library Release 2.8: June, 2000
257
+ Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
258
+ *************************************************************************/
259
+ double invnormaldistribution(double y0)
260
+ {
261
+ double result;
262
+ double expm2;
263
+ double s2pi;
264
+ double x;
265
+ double y;
266
+ double z;
267
+ double y2;
268
+ double x0;
269
+ double x1;
270
+ int code;
271
+ double p0;
272
+ double q0;
273
+ double p1;
274
+ double q1;
275
+ double p2;
276
+ double q2;
277
+
278
+ expm2 = 0.13533528323661269189;
279
+ s2pi = 2.50662827463100050242;
280
+ if( y0<=0 )
281
+ {
282
+ result = -ap::maxrealnumber;
283
+ return result;
284
+ }
285
+ if( y0>=1 )
286
+ {
287
+ result = ap::maxrealnumber;
288
+ return result;
289
+ }
290
+ code = 1;
291
+ y = y0;
292
+ if( y>1.0-expm2 )
293
+ {
294
+ y = 1.0-y;
295
+ code = 0;
296
+ }
297
+ if( y>expm2 )
298
+ {
299
+ y = y-0.5;
300
+ y2 = y*y;
301
+ p0 = -59.9633501014107895267;
302
+ p0 = 98.0010754185999661536+y2*p0;
303
+ p0 = -56.6762857469070293439+y2*p0;
304
+ p0 = 13.9312609387279679503+y2*p0;
305
+ p0 = -1.23916583867381258016+y2*p0;
306
+ q0 = 1;
307
+ q0 = 1.95448858338141759834+y2*q0;
308
+ q0 = 4.67627912898881538453+y2*q0;
309
+ q0 = 86.3602421390890590575+y2*q0;
310
+ q0 = -225.462687854119370527+y2*q0;
311
+ q0 = 200.260212380060660359+y2*q0;
312
+ q0 = -82.0372256168333339912+y2*q0;
313
+ q0 = 15.9056225126211695515+y2*q0;
314
+ q0 = -1.18331621121330003142+y2*q0;
315
+ x = y+y*y2*p0/q0;
316
+ x = x*s2pi;
317
+ result = x;
318
+ return result;
319
+ }
320
+ x = sqrt(-2.0*log(y));
321
+ x0 = x-log(x)/x;
322
+ z = 1.0/x;
323
+ if( x<8.0 )
324
+ {
325
+ p1 = 4.05544892305962419923;
326
+ p1 = 31.5251094599893866154+z*p1;
327
+ p1 = 57.1628192246421288162+z*p1;
328
+ p1 = 44.0805073893200834700+z*p1;
329
+ p1 = 14.6849561928858024014+z*p1;
330
+ p1 = 2.18663306850790267539+z*p1;
331
+ p1 = -1.40256079171354495875*0.1+z*p1;
332
+ p1 = -3.50424626827848203418*0.01+z*p1;
333
+ p1 = -8.57456785154685413611*0.0001+z*p1;
334
+ q1 = 1;
335
+ q1 = 15.7799883256466749731+z*q1;
336
+ q1 = 45.3907635128879210584+z*q1;
337
+ q1 = 41.3172038254672030440+z*q1;
338
+ q1 = 15.0425385692907503408+z*q1;
339
+ q1 = 2.50464946208309415979+z*q1;
340
+ q1 = -1.42182922854787788574*0.1+z*q1;
341
+ q1 = -3.80806407691578277194*0.01+z*q1;
342
+ q1 = -9.33259480895457427372*0.0001+z*q1;
343
+ x1 = z*p1/q1;
344
+ }
345
+ else
346
+ {
347
+ p2 = 3.23774891776946035970;
348
+ p2 = 6.91522889068984211695+z*p2;
349
+ p2 = 3.93881025292474443415+z*p2;
350
+ p2 = 1.33303460815807542389+z*p2;
351
+ p2 = 2.01485389549179081538*0.1+z*p2;
352
+ p2 = 1.23716634817820021358*0.01+z*p2;
353
+ p2 = 3.01581553508235416007*0.0001+z*p2;
354
+ p2 = 2.65806974686737550832*0.000001+z*p2;
355
+ p2 = 6.23974539184983293730*0.000000001+z*p2;
356
+ q2 = 1;
357
+ q2 = 6.02427039364742014255+z*q2;
358
+ q2 = 3.67983563856160859403+z*q2;
359
+ q2 = 1.37702099489081330271+z*q2;
360
+ q2 = 2.16236993594496635890*0.1+z*q2;
361
+ q2 = 1.34204006088543189037*0.01+z*q2;
362
+ q2 = 3.28014464682127739104*0.0001+z*q2;
363
+ q2 = 2.89247864745380683936*0.000001+z*q2;
364
+ q2 = 6.79019408009981274425*0.000000001+z*q2;
365
+ x1 = z*p2/q2;
366
+ }
367
+ x = x0-x1;
368
+ if( code!=0 )
369
+ {
370
+ x = -x;
371
+ }
372
+ result = x;
373
+ return result;
374
+ }
375
+
376
+
377
+