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,290 @@
1
+ /*************************************************************************
2
+ Copyright (c) 2007, 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 _spline3_h
34
+ #define _spline3_h
35
+
36
+ #include "ap.h"
37
+ #include "ialglib.h"
38
+
39
+ /*************************************************************************
40
+ This subroutine builds linear spline coefficients table.
41
+
42
+ Input parameters:
43
+ X - spline nodes, array[0..N-1]
44
+ Y - function values, array[0..N-1]
45
+ N - points count, N>=2
46
+
47
+ Output parameters:
48
+ C - coefficients table. Used by SplineInterpolation and other
49
+ subroutines from this file.
50
+
51
+ -- ALGLIB PROJECT --
52
+ Copyright 24.06.2007 by Bochkanov Sergey
53
+ *************************************************************************/
54
+ void buildlinearspline(ap::real_1d_array x,
55
+ ap::real_1d_array y,
56
+ int n,
57
+ ap::real_1d_array& c);
58
+
59
+
60
+ /*************************************************************************
61
+ This subroutine builds cubic spline coefficients table.
62
+
63
+ Input parameters:
64
+ X - spline nodes, array[0..N-1]
65
+ Y - function values, array[0..N-1]
66
+ N - points count, N>=2
67
+ BoundLType - boundary condition type for the left boundary
68
+ BoundL - left boundary condition (first or second derivative,
69
+ depending on the BoundLType)
70
+ BoundRType - boundary condition type for the right boundary
71
+ BoundR - right boundary condition (first or second derivative,
72
+ depending on the BoundRType)
73
+
74
+ Output parameters:
75
+ C - coefficients table. Used by SplineInterpolation and
76
+ other subroutines from this file.
77
+
78
+ The BoundLType/BoundRType parameters can have the following values:
79
+ * 0, which corresponds to the parabolically terminated spline
80
+ (BoundL/BoundR are ignored).
81
+ * 1, which corresponds to the first derivative boundary condition
82
+ * 2, which corresponds to the second derivative boundary condition
83
+
84
+ -- ALGLIB PROJECT --
85
+ Copyright 23.06.2007 by Bochkanov Sergey
86
+ *************************************************************************/
87
+ void buildcubicspline(ap::real_1d_array x,
88
+ ap::real_1d_array y,
89
+ int n,
90
+ int boundltype,
91
+ double boundl,
92
+ int boundrtype,
93
+ double boundr,
94
+ ap::real_1d_array& c);
95
+
96
+
97
+ /*************************************************************************
98
+ This subroutine builds cubic Hermite spline coefficients table.
99
+
100
+ Input parameters:
101
+ X - spline nodes, array[0..N-1]
102
+ Y - function values, array[0..N-1]
103
+ D - derivatives, array[0..N-1]
104
+ N - points count, N>=2
105
+
106
+ Output parameters:
107
+ C - coefficients table. Used by SplineInterpolation and
108
+ other subroutines from this file.
109
+
110
+ -- ALGLIB PROJECT --
111
+ Copyright 23.06.2007 by Bochkanov Sergey
112
+ *************************************************************************/
113
+ void buildhermitespline(ap::real_1d_array x,
114
+ ap::real_1d_array y,
115
+ ap::real_1d_array d,
116
+ int n,
117
+ ap::real_1d_array& c);
118
+
119
+
120
+ /*************************************************************************
121
+ This subroutine builds Akima spline coefficients table.
122
+
123
+ Input parameters:
124
+ X - spline nodes, array[0..N-1]
125
+ Y - function values, array[0..N-1]
126
+ N - points count, N>=5
127
+
128
+ Output parameters:
129
+ C - coefficients table. Used by SplineInterpolation and
130
+ other subroutines from this file.
131
+
132
+ -- ALGLIB PROJECT --
133
+ Copyright 24.06.2007 by Bochkanov Sergey
134
+ *************************************************************************/
135
+ void buildakimaspline(ap::real_1d_array x,
136
+ ap::real_1d_array y,
137
+ int n,
138
+ ap::real_1d_array& c);
139
+
140
+
141
+ /*************************************************************************
142
+ This subroutine calculates the value of the spline at the given point X.
143
+
144
+ Input parameters:
145
+ C - coefficients table. Built by BuildLinearSpline,
146
+ BuildHermiteSpline, BuildCubicSpline, BuildAkimaSpline.
147
+ X - point
148
+
149
+ Result:
150
+ S(x)
151
+
152
+ -- ALGLIB PROJECT --
153
+ Copyright 23.06.2007 by Bochkanov Sergey
154
+ *************************************************************************/
155
+ double splineinterpolation(const ap::real_1d_array& c, double x);
156
+
157
+
158
+ /*************************************************************************
159
+ This subroutine differentiates the spline.
160
+
161
+ Input parameters:
162
+ C - coefficients table. Built by BuildLinearSpline,
163
+ BuildHermiteSpline, BuildCubicSpline, BuildAkimaSpline.
164
+ X - point
165
+
166
+ Result:
167
+ S - S(x)
168
+ DS - S'(x)
169
+ D2S - S''(x)
170
+
171
+ -- ALGLIB PROJECT --
172
+ Copyright 24.06.2007 by Bochkanov Sergey
173
+ *************************************************************************/
174
+ void splinedifferentiation(const ap::real_1d_array& c,
175
+ double x,
176
+ double& s,
177
+ double& ds,
178
+ double& d2s);
179
+
180
+
181
+ /*************************************************************************
182
+ This subroutine makes the copy of the spline.
183
+
184
+ Input parameters:
185
+ C - coefficients table. Built by BuildLinearSpline,
186
+ BuildHermiteSpline, BuildCubicSpline, BuildAkimaSpline.
187
+
188
+ Result:
189
+ CC - spline copy
190
+
191
+ -- ALGLIB PROJECT --
192
+ Copyright 29.06.2007 by Bochkanov Sergey
193
+ *************************************************************************/
194
+ void splinecopy(const ap::real_1d_array& c, ap::real_1d_array& cc);
195
+
196
+
197
+ /*************************************************************************
198
+ This subroutine unpacks the spline into the coefficients table.
199
+
200
+ Input parameters:
201
+ C - coefficients table. Built by BuildLinearSpline,
202
+ BuildHermiteSpline, BuildCubicSpline, BuildAkimaSpline.
203
+ X - point
204
+
205
+ Result:
206
+ Tbl - coefficients table, unpacked format, array[0..N-2, 0..5].
207
+ For I = 0...N-2:
208
+ Tbl[I,0] = X[i]
209
+ Tbl[I,1] = X[i+1]
210
+ Tbl[I,2] = C0
211
+ Tbl[I,3] = C1
212
+ Tbl[I,4] = C2
213
+ Tbl[I,5] = C3
214
+ On [x[i], x[i+1]] spline is equals to:
215
+ S(x) = C0 + C1*t + C2*t^2 + C3*t^3
216
+ t = x-x[i]
217
+
218
+ -- ALGLIB PROJECT --
219
+ Copyright 29.06.2007 by Bochkanov Sergey
220
+ *************************************************************************/
221
+ void splineunpack(const ap::real_1d_array& c, int& n, ap::real_2d_array& tbl);
222
+
223
+
224
+ /*************************************************************************
225
+ This subroutine performs linear transformation of the spline argument.
226
+
227
+ Input parameters:
228
+ C - coefficients table. Built by BuildLinearSpline,
229
+ BuildHermiteSpline, BuildCubicSpline, BuildAkimaSpline.
230
+ A, B- transformation coefficients: x = A*t + B
231
+ Result:
232
+ C - transformed spline
233
+
234
+ -- ALGLIB PROJECT --
235
+ Copyright 30.06.2007 by Bochkanov Sergey
236
+ *************************************************************************/
237
+ void splinelintransx(ap::real_1d_array& c, double a, double b);
238
+
239
+
240
+ /*************************************************************************
241
+ This subroutine performs linear transformation of the spline.
242
+
243
+ Input parameters:
244
+ C - coefficients table. Built by BuildLinearSpline,
245
+ BuildHermiteSpline, BuildCubicSpline, BuildAkimaSpline.
246
+ A, B- transformation coefficients: S2(x) = A*S(x) + B
247
+ Result:
248
+ C - transformed spline
249
+
250
+ -- ALGLIB PROJECT --
251
+ Copyright 30.06.2007 by Bochkanov Sergey
252
+ *************************************************************************/
253
+ void splinelintransy(ap::real_1d_array& c, double a, double b);
254
+
255
+
256
+ /*************************************************************************
257
+ This subroutine integrates the spline.
258
+
259
+ Input parameters:
260
+ C - coefficients table. Built by BuildLinearSpline,
261
+ BuildHermiteSpline, BuildCubicSpline, BuildAkimaSpline.
262
+ X - right bound of the integration interval [a, x]
263
+ Result:
264
+ integral(S(t)dt,a,x)
265
+
266
+ -- ALGLIB PROJECT --
267
+ Copyright 23.06.2007 by Bochkanov Sergey
268
+ *************************************************************************/
269
+ double splineintegration(const ap::real_1d_array& c, double x);
270
+
271
+
272
+ /*************************************************************************
273
+ Obsolete subroutine, left for backward compatibility.
274
+ *************************************************************************/
275
+ void spline3buildtable(int n,
276
+ const int& diffn,
277
+ ap::real_1d_array x,
278
+ ap::real_1d_array y,
279
+ const double& boundl,
280
+ const double& boundr,
281
+ ap::real_2d_array& ctbl);
282
+
283
+
284
+ /*************************************************************************
285
+ Obsolete subroutine, left for backward compatibility.
286
+ *************************************************************************/
287
+ double spline3interpolate(int n, const ap::real_2d_array& c, const double& x);
288
+
289
+
290
+ #endif
@@ -0,0 +1,595 @@
1
+ /*************************************************************************
2
+ Copyright (c) 1992-2007 The University of Tennessee. All rights reserved.
3
+
4
+ Contributors:
5
+ * Sergey Bochkanov (ALGLIB project). Translation from FORTRAN to
6
+ pseudocode.
7
+
8
+ See subroutines comments for additional copyrights.
9
+
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are
12
+ met:
13
+
14
+ - Redistributions of source code must retain the above copyright
15
+ notice, this list of conditions and the following disclaimer.
16
+
17
+ - Redistributions in binary form must reproduce the above copyright
18
+ notice, this list of conditions and the following disclaimer listed
19
+ in this license in the documentation and/or other materials
20
+ provided with the distribution.
21
+
22
+ - Neither the name of the copyright holders nor the names of its
23
+ contributors may be used to endorse or promote products derived from
24
+ this software without specific prior written permission.
25
+
26
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
+ *************************************************************************/
38
+
39
+ #include <stdafx.h>
40
+ #include "srcond.h"
41
+
42
+ /*************************************************************************
43
+ Condition number estimate of a symmetric matrix
44
+
45
+ The algorithm calculates a lower bound of the condition number. In this
46
+ case, the algorithm does not return a lower bound of the condition number,
47
+ but an inverse number (to avoid an overflow in case of a singular matrix).
48
+
49
+ It should be noted that 1-norm and inf-norm condition numbers of symmetric
50
+ matrices are equal, so the algorithm doesn't take into account the
51
+ differences between these types of norms.
52
+
53
+ Input parameters:
54
+ A - symmetric definite matrix which is given by its upper or
55
+ lower triangle depending on IsUpper.
56
+ Array with elements [0..N-1, 0..N-1].
57
+ N - size of matrix A.
58
+ IsUpper - storage format.
59
+
60
+ Result:
61
+ 1/LowerBound(cond(A))
62
+ *************************************************************************/
63
+ double smatrixrcond(const ap::real_2d_array& a, int n, bool isupper)
64
+ {
65
+ double result;
66
+ int i;
67
+ int j;
68
+ ap::real_2d_array a1;
69
+
70
+ a1.setbounds(1, n, 1, n);
71
+ for(i = 1; i <= n; i++)
72
+ {
73
+ if( isupper )
74
+ {
75
+ for(j = i; j <= n; j++)
76
+ {
77
+ a1(i,j) = a(i-1,j-1);
78
+ }
79
+ }
80
+ else
81
+ {
82
+ for(j = 1; j <= i; j++)
83
+ {
84
+ a1(i,j) = a(i-1,j-1);
85
+ }
86
+ }
87
+ }
88
+ result = rcondsymmetric(a1, n, isupper);
89
+ return result;
90
+ }
91
+
92
+
93
+ /*************************************************************************
94
+ Condition number estimate of a matrix given by LDLT-decomposition
95
+
96
+ The algorithm calculates a lower bound of the condition number. In this
97
+ case, the algorithm does not return a lower bound of the condition number,
98
+ but an inverse number (to avoid an overflow in case of a singular matrix).
99
+
100
+ It should be noted that 1-norm and inf-norm condition numbers of symmetric
101
+ matrices are equal, so the algorithm doesn't take into account the
102
+ differences between these types of norms.
103
+
104
+ Input parameters:
105
+ L - LDLT-decomposition of matrix A given by the upper or lower
106
+ triangle depending on IsUpper.
107
+ Output of SMatrixLDLT subroutine.
108
+ Pivots - table of permutations which were made during LDLT-decomposition,
109
+ Output of SMatrixLDLT subroutine.
110
+ N - size of matrix A.
111
+ IsUpper - storage format.
112
+
113
+ Result:
114
+ 1/LowerBound(cond(A))
115
+ *************************************************************************/
116
+ double smatrixldltrcond(const ap::real_2d_array& l,
117
+ const ap::integer_1d_array& pivots,
118
+ int n,
119
+ bool isupper)
120
+ {
121
+ double result;
122
+ int i;
123
+ int j;
124
+ ap::real_2d_array l1;
125
+ ap::integer_1d_array p1;
126
+
127
+ l1.setbounds(1, n, 1, n);
128
+ for(i = 1; i <= n; i++)
129
+ {
130
+ if( isupper )
131
+ {
132
+ for(j = i; j <= n; j++)
133
+ {
134
+ l1(i,j) = l(i-1,j-1);
135
+ }
136
+ }
137
+ else
138
+ {
139
+ for(j = 1; j <= i; j++)
140
+ {
141
+ l1(i,j) = l(i-1,j-1);
142
+ }
143
+ }
144
+ }
145
+ p1.setbounds(1, n);
146
+ for(i = 1; i <= n; i++)
147
+ {
148
+ if( pivots(i-1)>=0 )
149
+ {
150
+ p1(i) = pivots(i-1)+1;
151
+ }
152
+ else
153
+ {
154
+ p1(i) = -(pivots(i-1)+n+1);
155
+ }
156
+ }
157
+ result = rcondldlt(l1, p1, n, isupper);
158
+ return result;
159
+ }
160
+
161
+
162
+ /*************************************************************************
163
+ Obsolete 1-based subroutine
164
+ *************************************************************************/
165
+ double rcondsymmetric(ap::real_2d_array a, int n, bool isupper)
166
+ {
167
+ double result;
168
+ int i;
169
+ int j;
170
+ int im;
171
+ int jm;
172
+ double v;
173
+ double nrm;
174
+ ap::integer_1d_array pivots;
175
+
176
+ nrm = 0;
177
+ for(j = 1; j <= n; j++)
178
+ {
179
+ v = 0;
180
+ for(i = 1; i <= n; i++)
181
+ {
182
+ im = i;
183
+ jm = j;
184
+ if( isupper&&j<i )
185
+ {
186
+ im = j;
187
+ jm = i;
188
+ }
189
+ if( !isupper&&j>i )
190
+ {
191
+ im = j;
192
+ jm = i;
193
+ }
194
+ v = v+fabs(a(im,jm));
195
+ }
196
+ nrm = ap::maxreal(nrm, v);
197
+ }
198
+ ldltdecomposition(a, n, isupper, pivots);
199
+ internalldltrcond(a, pivots, n, isupper, true, nrm, v);
200
+ result = v;
201
+ return result;
202
+ }
203
+
204
+
205
+ /*************************************************************************
206
+ Obsolete 1-based subroutine
207
+ *************************************************************************/
208
+ double rcondldlt(const ap::real_2d_array& l,
209
+ const ap::integer_1d_array& pivots,
210
+ int n,
211
+ bool isupper)
212
+ {
213
+ double result;
214
+ double v;
215
+
216
+ internalldltrcond(l, pivots, n, isupper, false, double(0), v);
217
+ result = v;
218
+ return result;
219
+ }
220
+
221
+
222
+ void internalldltrcond(const ap::real_2d_array& l,
223
+ const ap::integer_1d_array& pivots,
224
+ int n,
225
+ bool isupper,
226
+ bool isnormprovided,
227
+ double anorm,
228
+ double& rcond)
229
+ {
230
+ int i;
231
+ int ix;
232
+ int kase;
233
+ int k;
234
+ int km1;
235
+ int km2;
236
+ int kp1;
237
+ int kp2;
238
+ double ainvnm;
239
+ ap::real_1d_array work0;
240
+ ap::real_1d_array work1;
241
+ ap::real_1d_array work2;
242
+ ap::integer_1d_array iwork;
243
+ double v;
244
+
245
+ ap::ap_error::make_assertion(n>=0, "");
246
+
247
+ //
248
+ // Check that the diagonal matrix D is nonsingular.
249
+ //
250
+ rcond = 0;
251
+ if( isupper )
252
+ {
253
+ for(i = n; i >= 1; i--)
254
+ {
255
+ if( pivots(i)>0&&l(i,i)==0 )
256
+ {
257
+ return;
258
+ }
259
+ }
260
+ }
261
+ else
262
+ {
263
+ for(i = 1; i <= n; i++)
264
+ {
265
+ if( pivots(i)>0&&l(i,i)==0 )
266
+ {
267
+ return;
268
+ }
269
+ }
270
+ }
271
+
272
+ //
273
+ // Estimate the norm of A.
274
+ //
275
+ if( !isnormprovided )
276
+ {
277
+ kase = 0;
278
+ anorm = 0;
279
+ while(true)
280
+ {
281
+ iterativeestimate1norm(n, work1, work0, iwork, anorm, kase);
282
+ if( kase==0 )
283
+ {
284
+ break;
285
+ }
286
+ if( isupper )
287
+ {
288
+
289
+ //
290
+ // Multiply by U'
291
+ //
292
+ k = n;
293
+ while(k>=1)
294
+ {
295
+ if( pivots(k)>0 )
296
+ {
297
+
298
+ //
299
+ // P(k)
300
+ //
301
+ v = work0(k);
302
+ work0(k) = work0(pivots(k));
303
+ work0(pivots(k)) = v;
304
+
305
+ //
306
+ // U(k)
307
+ //
308
+ km1 = k-1;
309
+ v = ap::vdotproduct(work0.getvector(1, km1), l.getcolumn(k, 1, km1));
310
+ work0(k) = work0(k)+v;
311
+
312
+ //
313
+ // Next k
314
+ //
315
+ k = k-1;
316
+ }
317
+ else
318
+ {
319
+
320
+ //
321
+ // P(k)
322
+ //
323
+ v = work0(k-1);
324
+ work0(k-1) = work0(-pivots(k-1));
325
+ work0(-pivots(k-1)) = v;
326
+
327
+ //
328
+ // U(k)
329
+ //
330
+ km1 = k-1;
331
+ km2 = k-2;
332
+ v = ap::vdotproduct(work0.getvector(1, km2), l.getcolumn(km1, 1, km2));
333
+ work0(km1) = work0(km1)+v;
334
+ v = ap::vdotproduct(work0.getvector(1, km2), l.getcolumn(k, 1, km2));
335
+ work0(k) = work0(k)+v;
336
+
337
+ //
338
+ // Next k
339
+ //
340
+ k = k-2;
341
+ }
342
+ }
343
+
344
+ //
345
+ // Multiply by D
346
+ //
347
+ k = n;
348
+ while(k>=1)
349
+ {
350
+ if( pivots(k)>0 )
351
+ {
352
+ work0(k) = work0(k)*l(k,k);
353
+ k = k-1;
354
+ }
355
+ else
356
+ {
357
+ v = work0(k-1);
358
+ work0(k-1) = l(k-1,k-1)*work0(k-1)+l(k-1,k)*work0(k);
359
+ work0(k) = l(k-1,k)*v+l(k,k)*work0(k);
360
+ k = k-2;
361
+ }
362
+ }
363
+
364
+ //
365
+ // Multiply by U
366
+ //
367
+ k = 1;
368
+ while(k<=n)
369
+ {
370
+ if( pivots(k)>0 )
371
+ {
372
+
373
+ //
374
+ // U(k)
375
+ //
376
+ km1 = k-1;
377
+ v = work0(k);
378
+ ap::vadd(work0.getvector(1, km1), l.getcolumn(k, 1, km1), v);
379
+
380
+ //
381
+ // P(k)
382
+ //
383
+ v = work0(k);
384
+ work0(k) = work0(pivots(k));
385
+ work0(pivots(k)) = v;
386
+
387
+ //
388
+ // Next k
389
+ //
390
+ k = k+1;
391
+ }
392
+ else
393
+ {
394
+
395
+ //
396
+ // U(k)
397
+ //
398
+ km1 = k-1;
399
+ kp1 = k+1;
400
+ v = work0(k);
401
+ ap::vadd(work0.getvector(1, km1), l.getcolumn(k, 1, km1), v);
402
+ v = work0(kp1);
403
+ ap::vadd(work0.getvector(1, km1), l.getcolumn(kp1, 1, km1), v);
404
+
405
+ //
406
+ // P(k)
407
+ //
408
+ v = work0(k);
409
+ work0(k) = work0(-pivots(k));
410
+ work0(-pivots(k)) = v;
411
+
412
+ //
413
+ // Next k
414
+ //
415
+ k = k+2;
416
+ }
417
+ }
418
+ }
419
+ else
420
+ {
421
+
422
+ //
423
+ // Multiply by L'
424
+ //
425
+ k = 1;
426
+ while(k<=n)
427
+ {
428
+ if( pivots(k)>0 )
429
+ {
430
+
431
+ //
432
+ // P(k)
433
+ //
434
+ v = work0(k);
435
+ work0(k) = work0(pivots(k));
436
+ work0(pivots(k)) = v;
437
+
438
+ //
439
+ // L(k)
440
+ //
441
+ kp1 = k+1;
442
+ v = ap::vdotproduct(work0.getvector(kp1, n), l.getcolumn(k, kp1, n));
443
+ work0(k) = work0(k)+v;
444
+
445
+ //
446
+ // Next k
447
+ //
448
+ k = k+1;
449
+ }
450
+ else
451
+ {
452
+
453
+ //
454
+ // P(k)
455
+ //
456
+ v = work0(k+1);
457
+ work0(k+1) = work0(-pivots(k+1));
458
+ work0(-pivots(k+1)) = v;
459
+
460
+ //
461
+ // L(k)
462
+ //
463
+ kp1 = k+1;
464
+ kp2 = k+2;
465
+ v = ap::vdotproduct(work0.getvector(kp2, n), l.getcolumn(k, kp2, n));
466
+ work0(k) = work0(k)+v;
467
+ v = ap::vdotproduct(work0.getvector(kp2, n), l.getcolumn(kp1, kp2, n));
468
+ work0(kp1) = work0(kp1)+v;
469
+
470
+ //
471
+ // Next k
472
+ //
473
+ k = k+2;
474
+ }
475
+ }
476
+
477
+ //
478
+ // Multiply by D
479
+ //
480
+ k = n;
481
+ while(k>=1)
482
+ {
483
+ if( pivots(k)>0 )
484
+ {
485
+ work0(k) = work0(k)*l(k,k);
486
+ k = k-1;
487
+ }
488
+ else
489
+ {
490
+ v = work0(k-1);
491
+ work0(k-1) = l(k-1,k-1)*work0(k-1)+l(k,k-1)*work0(k);
492
+ work0(k) = l(k,k-1)*v+l(k,k)*work0(k);
493
+ k = k-2;
494
+ }
495
+ }
496
+
497
+ //
498
+ // Multiply by L
499
+ //
500
+ k = n;
501
+ while(k>=1)
502
+ {
503
+ if( pivots(k)>0 )
504
+ {
505
+
506
+ //
507
+ // L(k)
508
+ //
509
+ kp1 = k+1;
510
+ v = work0(k);
511
+ ap::vadd(work0.getvector(kp1, n), l.getcolumn(k, kp1, n), v);
512
+
513
+ //
514
+ // P(k)
515
+ //
516
+ v = work0(k);
517
+ work0(k) = work0(pivots(k));
518
+ work0(pivots(k)) = v;
519
+
520
+ //
521
+ // Next k
522
+ //
523
+ k = k-1;
524
+ }
525
+ else
526
+ {
527
+
528
+ //
529
+ // L(k)
530
+ //
531
+ kp1 = k+1;
532
+ km1 = k-1;
533
+ v = work0(k);
534
+ ap::vadd(work0.getvector(kp1, n), l.getcolumn(k, kp1, n), v);
535
+ v = work0(km1);
536
+ ap::vadd(work0.getvector(kp1, n), l.getcolumn(km1, kp1, n), v);
537
+
538
+ //
539
+ // P(k)
540
+ //
541
+ v = work0(k);
542
+ work0(k) = work0(-pivots(k));
543
+ work0(-pivots(k)) = v;
544
+
545
+ //
546
+ // Next k
547
+ //
548
+ k = k-2;
549
+ }
550
+ }
551
+ }
552
+ }
553
+ }
554
+
555
+ //
556
+ // Quick return if possible
557
+ //
558
+ rcond = 0;
559
+ if( n==0 )
560
+ {
561
+ rcond = 1;
562
+ return;
563
+ }
564
+ if( anorm==0 )
565
+ {
566
+ return;
567
+ }
568
+
569
+ //
570
+ // Estimate the 1-norm of inv(A).
571
+ //
572
+ kase = 0;
573
+ while(true)
574
+ {
575
+ iterativeestimate1norm(n, work1, work0, iwork, ainvnm, kase);
576
+ if( kase==0 )
577
+ {
578
+ break;
579
+ }
580
+ solvesystemldlt(l, pivots, work0, n, isupper, work2);
581
+ ap::vmove(&work0(1), &work2(1), ap::vlen(1,n));
582
+ }
583
+
584
+ //
585
+ // Compute the estimate of the reciprocal condition number.
586
+ //
587
+ if( ainvnm!=0 )
588
+ {
589
+ v = 1/ainvnm;
590
+ rcond = v/anorm;
591
+ }
592
+ }
593
+
594
+
595
+