rb-gsl 1.15.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (660) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +6 -0
  3. data/COPYING +339 -0
  4. data/ChangeLog +567 -0
  5. data/README +32 -0
  6. data/Rakefile +99 -0
  7. data/THANKS +17 -0
  8. data/VERSION +1 -0
  9. data/examples/alf/alf.gp +15 -0
  10. data/examples/alf/alf.rb +32 -0
  11. data/examples/blas/blas.rb +13 -0
  12. data/examples/blas/dnrm2.rb +16 -0
  13. data/examples/blas/level1.rb +81 -0
  14. data/examples/blas/level2.rb +11 -0
  15. data/examples/blas/level3.rb +12 -0
  16. data/examples/bspline.rb +57 -0
  17. data/examples/cdf.rb +16 -0
  18. data/examples/cheb.rb +21 -0
  19. data/examples/combination.rb +23 -0
  20. data/examples/complex/RC-lpf.rb +47 -0
  21. data/examples/complex/add.rb +36 -0
  22. data/examples/complex/coerce.rb +14 -0
  23. data/examples/complex/complex.rb +25 -0
  24. data/examples/complex/fpmi.rb +70 -0
  25. data/examples/complex/functions.rb +77 -0
  26. data/examples/complex/michelson.rb +36 -0
  27. data/examples/complex/mul.rb +28 -0
  28. data/examples/complex/oscillator.rb +17 -0
  29. data/examples/complex/set.rb +37 -0
  30. data/examples/const/physconst.rb +151 -0
  31. data/examples/const/travel.rb +45 -0
  32. data/examples/deriv/demo.rb +13 -0
  33. data/examples/deriv/deriv.rb +36 -0
  34. data/examples/deriv/diff.rb +35 -0
  35. data/examples/dht.rb +42 -0
  36. data/examples/dirac.rb +56 -0
  37. data/examples/eigen/eigen.rb +34 -0
  38. data/examples/eigen/herm.rb +22 -0
  39. data/examples/eigen/narray.rb +9 -0
  40. data/examples/eigen/nonsymm.rb +37 -0
  41. data/examples/eigen/nonsymmv.rb +43 -0
  42. data/examples/eigen/qhoscillator.gp +35 -0
  43. data/examples/eigen/qhoscillator.rb +90 -0
  44. data/examples/eigen/vander.rb +41 -0
  45. data/examples/fft/fft.rb +17 -0
  46. data/examples/fft/fft2.rb +17 -0
  47. data/examples/fft/forward.rb +25 -0
  48. data/examples/fft/forward2.rb +26 -0
  49. data/examples/fft/radix2.rb +18 -0
  50. data/examples/fft/real-halfcomplex.rb +33 -0
  51. data/examples/fft/real-halfcomplex2.rb +30 -0
  52. data/examples/fft/realradix2.rb +19 -0
  53. data/examples/fft/sunspot.dat +256 -0
  54. data/examples/fft/sunspot.rb +16 -0
  55. data/examples/fit/expdata.dat +20 -0
  56. data/examples/fit/expfit.rb +31 -0
  57. data/examples/fit/gaussfit.rb +29 -0
  58. data/examples/fit/gaussian_2peaks.rb +34 -0
  59. data/examples/fit/hillfit.rb +40 -0
  60. data/examples/fit/lognormal.rb +26 -0
  61. data/examples/fit/lorentzfit.rb +22 -0
  62. data/examples/fit/multifit.rb +72 -0
  63. data/examples/fit/ndlinear.rb +133 -0
  64. data/examples/fit/nonlinearfit.rb +89 -0
  65. data/examples/fit/plot.gp +36 -0
  66. data/examples/fit/polyfit.rb +9 -0
  67. data/examples/fit/powerfit.rb +21 -0
  68. data/examples/fit/sigmoidfit.rb +40 -0
  69. data/examples/fit/sinfit.rb +22 -0
  70. data/examples/fit/wlinear.rb +46 -0
  71. data/examples/fresnel.rb +11 -0
  72. data/examples/function/function.rb +36 -0
  73. data/examples/function/log.rb +7 -0
  74. data/examples/function/min.rb +33 -0
  75. data/examples/function/sin.rb +10 -0
  76. data/examples/function/synchrotron.rb +18 -0
  77. data/examples/gallery/butterfly.rb +7 -0
  78. data/examples/gallery/cayley.rb +12 -0
  79. data/examples/gallery/cornu.rb +23 -0
  80. data/examples/gallery/eight.rb +11 -0
  81. data/examples/gallery/koch.rb +40 -0
  82. data/examples/gallery/lemniscate.rb +11 -0
  83. data/examples/gallery/polar.rb +11 -0
  84. data/examples/gallery/rgplot/cossin.rb +35 -0
  85. data/examples/gallery/rgplot/rgplot.replaced +0 -0
  86. data/examples/gallery/rgplot/roesller.rb +55 -0
  87. data/examples/gallery/roesller.rb +39 -0
  88. data/examples/gallery/scarabaeus.rb +14 -0
  89. data/examples/histogram/cauchy.rb +27 -0
  90. data/examples/histogram/cauchy.sh +2 -0
  91. data/examples/histogram/exponential.rb +19 -0
  92. data/examples/histogram/gauss.rb +16 -0
  93. data/examples/histogram/gsl-histogram.rb +40 -0
  94. data/examples/histogram/histo2d.rb +31 -0
  95. data/examples/histogram/histo3d.rb +34 -0
  96. data/examples/histogram/histogram-pdf.rb +27 -0
  97. data/examples/histogram/histogram.rb +26 -0
  98. data/examples/histogram/integral.rb +28 -0
  99. data/examples/histogram/poisson.rb +27 -0
  100. data/examples/histogram/power.rb +25 -0
  101. data/examples/histogram/rebin.rb +17 -0
  102. data/examples/histogram/smp.dat +5 -0
  103. data/examples/histogram/xexp.rb +21 -0
  104. data/examples/integration/ahmed.rb +21 -0
  105. data/examples/integration/cosmology.rb +75 -0
  106. data/examples/integration/friedmann.gp +16 -0
  107. data/examples/integration/friedmann.rb +35 -0
  108. data/examples/integration/gamma-zeta.rb +35 -0
  109. data/examples/integration/integration.rb +22 -0
  110. data/examples/integration/qag.rb +8 -0
  111. data/examples/integration/qag2.rb +14 -0
  112. data/examples/integration/qag3.rb +8 -0
  113. data/examples/integration/qagi.rb +28 -0
  114. data/examples/integration/qagi2.rb +49 -0
  115. data/examples/integration/qagiu.rb +29 -0
  116. data/examples/integration/qagp.rb +20 -0
  117. data/examples/integration/qags.rb +14 -0
  118. data/examples/integration/qawc.rb +18 -0
  119. data/examples/integration/qawf.rb +41 -0
  120. data/examples/integration/qawo.rb +29 -0
  121. data/examples/integration/qaws.rb +30 -0
  122. data/examples/integration/qng.rb +17 -0
  123. data/examples/interp/demo.gp +20 -0
  124. data/examples/interp/demo.rb +45 -0
  125. data/examples/interp/interp.rb +37 -0
  126. data/examples/interp/points +10 -0
  127. data/examples/interp/spline.rb +20 -0
  128. data/examples/jacobi/deriv.rb +40 -0
  129. data/examples/jacobi/integrate.rb +34 -0
  130. data/examples/jacobi/interp.rb +43 -0
  131. data/examples/jacobi/jacobi.rb +11 -0
  132. data/examples/linalg/HH.rb +15 -0
  133. data/examples/linalg/HH_narray.rb +13 -0
  134. data/examples/linalg/LQ_solve.rb +73 -0
  135. data/examples/linalg/LU.rb +84 -0
  136. data/examples/linalg/LU2.rb +31 -0
  137. data/examples/linalg/LU_narray.rb +24 -0
  138. data/examples/linalg/PTLQ.rb +47 -0
  139. data/examples/linalg/QR.rb +18 -0
  140. data/examples/linalg/QRPT.rb +47 -0
  141. data/examples/linalg/QR_solve.rb +78 -0
  142. data/examples/linalg/QR_solve_narray.rb +13 -0
  143. data/examples/linalg/SV.rb +16 -0
  144. data/examples/linalg/SV_narray.rb +12 -0
  145. data/examples/linalg/SV_solve.rb +49 -0
  146. data/examples/linalg/chol.rb +29 -0
  147. data/examples/linalg/chol_narray.rb +15 -0
  148. data/examples/linalg/complex.rb +57 -0
  149. data/examples/linalg/invert_narray.rb +10 -0
  150. data/examples/math/const.rb +67 -0
  151. data/examples/math/elementary.rb +35 -0
  152. data/examples/math/functions.rb +41 -0
  153. data/examples/math/inf_nan.rb +34 -0
  154. data/examples/math/minmax.rb +22 -0
  155. data/examples/math/power.rb +18 -0
  156. data/examples/math/test.rb +31 -0
  157. data/examples/matrix/a.dat +0 -0
  158. data/examples/matrix/add.rb +45 -0
  159. data/examples/matrix/b.dat +4 -0
  160. data/examples/matrix/cat.rb +31 -0
  161. data/examples/matrix/colvectors.rb +24 -0
  162. data/examples/matrix/complex.rb +41 -0
  163. data/examples/matrix/det.rb +29 -0
  164. data/examples/matrix/diagonal.rb +23 -0
  165. data/examples/matrix/get_all.rb +159 -0
  166. data/examples/matrix/hilbert.rb +31 -0
  167. data/examples/matrix/iterator.rb +19 -0
  168. data/examples/matrix/matrix.rb +57 -0
  169. data/examples/matrix/minmax.rb +53 -0
  170. data/examples/matrix/mul.rb +39 -0
  171. data/examples/matrix/rand.rb +20 -0
  172. data/examples/matrix/read.rb +29 -0
  173. data/examples/matrix/rowcol.rb +47 -0
  174. data/examples/matrix/set.rb +41 -0
  175. data/examples/matrix/set_all.rb +100 -0
  176. data/examples/matrix/view.rb +32 -0
  177. data/examples/matrix/view_all.rb +148 -0
  178. data/examples/matrix/write.rb +23 -0
  179. data/examples/min.rb +29 -0
  180. data/examples/monte/miser.rb +47 -0
  181. data/examples/monte/monte.rb +47 -0
  182. data/examples/monte/plain.rb +47 -0
  183. data/examples/monte/vegas.rb +46 -0
  184. data/examples/multimin/bundle.rb +66 -0
  185. data/examples/multimin/cqp.rb +109 -0
  186. data/examples/multimin/fdfminimizer.rb +40 -0
  187. data/examples/multimin/fminimizer.rb +41 -0
  188. data/examples/multiroot/demo.rb +36 -0
  189. data/examples/multiroot/fdfsolver.rb +50 -0
  190. data/examples/multiroot/fsolver.rb +33 -0
  191. data/examples/multiroot/fsolver2.rb +32 -0
  192. data/examples/multiroot/fsolver3.rb +26 -0
  193. data/examples/narray/histogram.rb +14 -0
  194. data/examples/narray/mandel.rb +27 -0
  195. data/examples/narray/narray.rb +28 -0
  196. data/examples/narray/narray2.rb +44 -0
  197. data/examples/narray/sf.rb +26 -0
  198. data/examples/ntuple/create.rb +17 -0
  199. data/examples/ntuple/project.rb +31 -0
  200. data/examples/odeiv/binarysystem.gp +23 -0
  201. data/examples/odeiv/binarysystem.rb +104 -0
  202. data/examples/odeiv/demo.gp +24 -0
  203. data/examples/odeiv/demo.rb +69 -0
  204. data/examples/odeiv/demo2.gp +26 -0
  205. data/examples/odeiv/duffing.rb +45 -0
  206. data/examples/odeiv/frei1.rb +109 -0
  207. data/examples/odeiv/frei2.rb +76 -0
  208. data/examples/odeiv/legendre.rb +52 -0
  209. data/examples/odeiv/odeiv.rb +32 -0
  210. data/examples/odeiv/odeiv2.rb +45 -0
  211. data/examples/odeiv/oscillator.rb +42 -0
  212. data/examples/odeiv/sedov.rb +97 -0
  213. data/examples/odeiv/whitedwarf.gp +40 -0
  214. data/examples/odeiv/whitedwarf.rb +158 -0
  215. data/examples/ool/conmin.rb +100 -0
  216. data/examples/ool/gencan.rb +99 -0
  217. data/examples/ool/pgrad.rb +100 -0
  218. data/examples/ool/spg.rb +100 -0
  219. data/examples/pdf/bernoulli.rb +5 -0
  220. data/examples/pdf/beta.rb +7 -0
  221. data/examples/pdf/binomiral.rb +10 -0
  222. data/examples/pdf/cauchy.rb +6 -0
  223. data/examples/pdf/chisq.rb +8 -0
  224. data/examples/pdf/exponential.rb +7 -0
  225. data/examples/pdf/exppow.rb +6 -0
  226. data/examples/pdf/fdist.rb +7 -0
  227. data/examples/pdf/flat.rb +7 -0
  228. data/examples/pdf/gamma.rb +8 -0
  229. data/examples/pdf/gauss-tail.rb +5 -0
  230. data/examples/pdf/gauss.rb +6 -0
  231. data/examples/pdf/geometric.rb +5 -0
  232. data/examples/pdf/gumbel.rb +6 -0
  233. data/examples/pdf/hypergeometric.rb +11 -0
  234. data/examples/pdf/landau.rb +5 -0
  235. data/examples/pdf/laplace.rb +7 -0
  236. data/examples/pdf/logarithmic.rb +5 -0
  237. data/examples/pdf/logistic.rb +6 -0
  238. data/examples/pdf/lognormal.rb +6 -0
  239. data/examples/pdf/neg-binomiral.rb +10 -0
  240. data/examples/pdf/pareto.rb +7 -0
  241. data/examples/pdf/pascal.rb +10 -0
  242. data/examples/pdf/poisson.rb +5 -0
  243. data/examples/pdf/rayleigh-tail.rb +6 -0
  244. data/examples/pdf/rayleigh.rb +6 -0
  245. data/examples/pdf/tdist.rb +6 -0
  246. data/examples/pdf/weibull.rb +8 -0
  247. data/examples/permutation/ex1.rb +22 -0
  248. data/examples/permutation/permutation.rb +16 -0
  249. data/examples/poly/bell.rb +6 -0
  250. data/examples/poly/bessel.rb +6 -0
  251. data/examples/poly/cheb.rb +6 -0
  252. data/examples/poly/cheb_II.rb +6 -0
  253. data/examples/poly/cubic.rb +9 -0
  254. data/examples/poly/demo.rb +20 -0
  255. data/examples/poly/eval.rb +28 -0
  256. data/examples/poly/eval_derivs.rb +14 -0
  257. data/examples/poly/fit.rb +21 -0
  258. data/examples/poly/hermite.rb +6 -0
  259. data/examples/poly/poly.rb +13 -0
  260. data/examples/poly/quadratic.rb +25 -0
  261. data/examples/random/diffusion.rb +34 -0
  262. data/examples/random/gaussian.rb +9 -0
  263. data/examples/random/generator.rb +27 -0
  264. data/examples/random/hdsobol.rb +21 -0
  265. data/examples/random/poisson.rb +9 -0
  266. data/examples/random/qrng.rb +19 -0
  267. data/examples/random/randomwalk.rb +37 -0
  268. data/examples/random/randomwalk2d.rb +19 -0
  269. data/examples/random/rayleigh.rb +36 -0
  270. data/examples/random/rng.rb +33 -0
  271. data/examples/random/rngextra.rb +14 -0
  272. data/examples/roots/bisection.rb +25 -0
  273. data/examples/roots/brent.rb +43 -0
  274. data/examples/roots/demo.rb +30 -0
  275. data/examples/roots/newton.rb +46 -0
  276. data/examples/roots/recombination.gp +12 -0
  277. data/examples/roots/recombination.rb +61 -0
  278. data/examples/roots/steffenson.rb +48 -0
  279. data/examples/sf/ShiChi.rb +6 -0
  280. data/examples/sf/SiCi.rb +6 -0
  281. data/examples/sf/airy_Ai.rb +8 -0
  282. data/examples/sf/airy_Bi.rb +8 -0
  283. data/examples/sf/bessel_IK.rb +12 -0
  284. data/examples/sf/bessel_JY.rb +13 -0
  285. data/examples/sf/beta_inc.rb +9 -0
  286. data/examples/sf/clausen.rb +6 -0
  287. data/examples/sf/dawson.rb +5 -0
  288. data/examples/sf/debye.rb +9 -0
  289. data/examples/sf/dilog.rb +6 -0
  290. data/examples/sf/ellint.rb +6 -0
  291. data/examples/sf/expint.rb +8 -0
  292. data/examples/sf/fermi.rb +10 -0
  293. data/examples/sf/gamma_inc_P.rb +9 -0
  294. data/examples/sf/gegenbauer.rb +8 -0
  295. data/examples/sf/hyperg.rb +7 -0
  296. data/examples/sf/laguerre.rb +19 -0
  297. data/examples/sf/lambertW.rb +5 -0
  298. data/examples/sf/legendre_P.rb +10 -0
  299. data/examples/sf/lngamma.rb +5 -0
  300. data/examples/sf/psi.rb +54 -0
  301. data/examples/sf/sphbessel.gp +27 -0
  302. data/examples/sf/sphbessel.rb +30 -0
  303. data/examples/sf/synchrotron.rb +5 -0
  304. data/examples/sf/transport.rb +10 -0
  305. data/examples/sf/zetam1.rb +5 -0
  306. data/examples/siman.rb +44 -0
  307. data/examples/sort/heapsort.rb +23 -0
  308. data/examples/sort/heapsort_vector_complex.rb +21 -0
  309. data/examples/sort/sort.rb +23 -0
  310. data/examples/sort/sort2.rb +16 -0
  311. data/examples/stats/mean.rb +17 -0
  312. data/examples/stats/statistics.rb +18 -0
  313. data/examples/stats/test.rb +9 -0
  314. data/examples/sum.rb +34 -0
  315. data/examples/tamu_anova.rb +18 -0
  316. data/examples/vector/a.dat +0 -0
  317. data/examples/vector/add.rb +56 -0
  318. data/examples/vector/b.dat +4 -0
  319. data/examples/vector/c.dat +3 -0
  320. data/examples/vector/collect.rb +26 -0
  321. data/examples/vector/compare.rb +28 -0
  322. data/examples/vector/complex.rb +51 -0
  323. data/examples/vector/complex_get_all.rb +85 -0
  324. data/examples/vector/complex_set_all.rb +131 -0
  325. data/examples/vector/complex_view_all.rb +77 -0
  326. data/examples/vector/connect.rb +22 -0
  327. data/examples/vector/decimate.rb +38 -0
  328. data/examples/vector/diff.rb +31 -0
  329. data/examples/vector/filescan.rb +17 -0
  330. data/examples/vector/floor.rb +23 -0
  331. data/examples/vector/get_all.rb +82 -0
  332. data/examples/vector/gnuplot.rb +38 -0
  333. data/examples/vector/graph.rb +28 -0
  334. data/examples/vector/histogram.rb +22 -0
  335. data/examples/vector/linspace.rb +24 -0
  336. data/examples/vector/log.rb +17 -0
  337. data/examples/vector/logic.rb +33 -0
  338. data/examples/vector/logspace.rb +25 -0
  339. data/examples/vector/minmax.rb +47 -0
  340. data/examples/vector/mul.rb +49 -0
  341. data/examples/vector/narray.rb +46 -0
  342. data/examples/vector/read.rb +29 -0
  343. data/examples/vector/set.rb +35 -0
  344. data/examples/vector/set_all.rb +121 -0
  345. data/examples/vector/smpv.dat +15 -0
  346. data/examples/vector/test.rb +43 -0
  347. data/examples/vector/test_gslblock.rb +58 -0
  348. data/examples/vector/vector.rb +110 -0
  349. data/examples/vector/view.rb +35 -0
  350. data/examples/vector/view_all.rb +73 -0
  351. data/examples/vector/where.rb +29 -0
  352. data/examples/vector/write.rb +24 -0
  353. data/examples/vector/zip.rb +34 -0
  354. data/examples/wavelet/ecg.dat +256 -0
  355. data/examples/wavelet/wavelet1.rb +50 -0
  356. data/ext/alf.c +206 -0
  357. data/ext/array.c +642 -0
  358. data/ext/array_complex.c +248 -0
  359. data/ext/blas.c +29 -0
  360. data/ext/blas1.c +734 -0
  361. data/ext/blas2.c +1093 -0
  362. data/ext/blas3.c +881 -0
  363. data/ext/block.c +44 -0
  364. data/ext/block_source.c +887 -0
  365. data/ext/bspline.c +130 -0
  366. data/ext/bundle.c +3 -0
  367. data/ext/cdf.c +754 -0
  368. data/ext/cheb.c +542 -0
  369. data/ext/combination.c +283 -0
  370. data/ext/common.c +325 -0
  371. data/ext/complex.c +1004 -0
  372. data/ext/const.c +673 -0
  373. data/ext/const_additional.c +120 -0
  374. data/ext/cqp.c +283 -0
  375. data/ext/deriv.c +195 -0
  376. data/ext/dht.c +361 -0
  377. data/ext/diff.c +166 -0
  378. data/ext/dirac.c +389 -0
  379. data/ext/eigen.c +2373 -0
  380. data/ext/error.c +193 -0
  381. data/ext/extconf.rb +303 -0
  382. data/ext/fcmp.c +66 -0
  383. data/ext/fft.c +1102 -0
  384. data/ext/fit.c +205 -0
  385. data/ext/fresnel.c +312 -0
  386. data/ext/function.c +524 -0
  387. data/ext/geometry.c +139 -0
  388. data/ext/graph.c +1640 -0
  389. data/ext/gsl.c +280 -0
  390. data/ext/gsl_narray.c +804 -0
  391. data/ext/histogram.c +1991 -0
  392. data/ext/histogram2d.c +1068 -0
  393. data/ext/histogram3d.c +884 -0
  394. data/ext/histogram3d_source.c +750 -0
  395. data/ext/histogram_find.c +101 -0
  396. data/ext/histogram_oper.c +159 -0
  397. data/ext/ieee.c +100 -0
  398. data/ext/integration.c +1179 -0
  399. data/ext/interp.c +512 -0
  400. data/ext/jacobi.c +739 -0
  401. data/ext/linalg.c +4042 -0
  402. data/ext/linalg_complex.c +739 -0
  403. data/ext/math.c +725 -0
  404. data/ext/matrix.c +39 -0
  405. data/ext/matrix_complex.c +1737 -0
  406. data/ext/matrix_double.c +560 -0
  407. data/ext/matrix_int.c +256 -0
  408. data/ext/matrix_source.c +2734 -0
  409. data/ext/min.c +250 -0
  410. data/ext/monte.c +992 -0
  411. data/ext/multifit.c +1871 -0
  412. data/ext/multimin.c +806 -0
  413. data/ext/multimin_fsdf.c +156 -0
  414. data/ext/multiroots.c +955 -0
  415. data/ext/multiset.c +214 -0
  416. data/ext/ndlinear.c +321 -0
  417. data/ext/nmf.c +171 -0
  418. data/ext/nmf_wrap.c +75 -0
  419. data/ext/ntuple.c +469 -0
  420. data/ext/odeiv.c +962 -0
  421. data/ext/ool.c +879 -0
  422. data/ext/oper_complex_source.c +253 -0
  423. data/ext/permutation.c +596 -0
  424. data/ext/poly.c +42 -0
  425. data/ext/poly2.c +265 -0
  426. data/ext/poly_source.c +1915 -0
  427. data/ext/qrng.c +171 -0
  428. data/ext/randist.c +1873 -0
  429. data/ext/rational.c +480 -0
  430. data/ext/rng.c +612 -0
  431. data/ext/root.c +408 -0
  432. data/ext/sf.c +1494 -0
  433. data/ext/sf_airy.c +200 -0
  434. data/ext/sf_bessel.c +871 -0
  435. data/ext/sf_clausen.c +28 -0
  436. data/ext/sf_coulomb.c +206 -0
  437. data/ext/sf_coupling.c +121 -0
  438. data/ext/sf_dawson.c +29 -0
  439. data/ext/sf_debye.c +157 -0
  440. data/ext/sf_dilog.c +43 -0
  441. data/ext/sf_elementary.c +46 -0
  442. data/ext/sf_ellint.c +206 -0
  443. data/ext/sf_elljac.c +30 -0
  444. data/ext/sf_erfc.c +93 -0
  445. data/ext/sf_exp.c +169 -0
  446. data/ext/sf_expint.c +211 -0
  447. data/ext/sf_fermi_dirac.c +148 -0
  448. data/ext/sf_gamma.c +347 -0
  449. data/ext/sf_gegenbauer.c +97 -0
  450. data/ext/sf_hyperg.c +203 -0
  451. data/ext/sf_laguerre.c +113 -0
  452. data/ext/sf_lambert.c +47 -0
  453. data/ext/sf_legendre.c +368 -0
  454. data/ext/sf_log.c +105 -0
  455. data/ext/sf_mathieu.c +238 -0
  456. data/ext/sf_power.c +47 -0
  457. data/ext/sf_psi.c +98 -0
  458. data/ext/sf_synchrotron.c +48 -0
  459. data/ext/sf_transport.c +76 -0
  460. data/ext/sf_trigonometric.c +210 -0
  461. data/ext/sf_zeta.c +119 -0
  462. data/ext/signal.c +308 -0
  463. data/ext/siman.c +717 -0
  464. data/ext/sort.c +208 -0
  465. data/ext/spline.c +395 -0
  466. data/ext/stats.c +800 -0
  467. data/ext/sum.c +168 -0
  468. data/ext/tamu_anova.c +56 -0
  469. data/ext/tensor.c +38 -0
  470. data/ext/tensor_source.c +1123 -0
  471. data/ext/vector.c +38 -0
  472. data/ext/vector_complex.c +2246 -0
  473. data/ext/vector_double.c +1438 -0
  474. data/ext/vector_int.c +204 -0
  475. data/ext/vector_source.c +3336 -0
  476. data/ext/wavelet.c +945 -0
  477. data/include/rb_gsl.h +158 -0
  478. data/include/rb_gsl_array.h +238 -0
  479. data/include/rb_gsl_cheb.h +21 -0
  480. data/include/rb_gsl_common.h +348 -0
  481. data/include/rb_gsl_complex.h +25 -0
  482. data/include/rb_gsl_config.h +62 -0
  483. data/include/rb_gsl_const.h +29 -0
  484. data/include/rb_gsl_dirac.h +13 -0
  485. data/include/rb_gsl_eigen.h +17 -0
  486. data/include/rb_gsl_fft.h +62 -0
  487. data/include/rb_gsl_fit.h +25 -0
  488. data/include/rb_gsl_function.h +27 -0
  489. data/include/rb_gsl_graph.h +70 -0
  490. data/include/rb_gsl_histogram.h +63 -0
  491. data/include/rb_gsl_histogram3d.h +97 -0
  492. data/include/rb_gsl_integration.h +17 -0
  493. data/include/rb_gsl_interp.h +46 -0
  494. data/include/rb_gsl_linalg.h +25 -0
  495. data/include/rb_gsl_math.h +26 -0
  496. data/include/rb_gsl_odeiv.h +21 -0
  497. data/include/rb_gsl_poly.h +71 -0
  498. data/include/rb_gsl_rational.h +37 -0
  499. data/include/rb_gsl_rng.h +21 -0
  500. data/include/rb_gsl_root.h +22 -0
  501. data/include/rb_gsl_sf.h +119 -0
  502. data/include/rb_gsl_statistics.h +17 -0
  503. data/include/rb_gsl_tensor.h +45 -0
  504. data/include/rb_gsl_with_narray.h +29 -0
  505. data/include/templates_off.h +87 -0
  506. data/include/templates_on.h +241 -0
  507. data/lib/gsl.rb +3 -0
  508. data/lib/gsl/gnuplot.rb +41 -0
  509. data/lib/gsl/oper.rb +68 -0
  510. data/lib/ool.rb +22 -0
  511. data/lib/ool/conmin.rb +30 -0
  512. data/lib/rbgsl.rb +3 -0
  513. data/rdoc/alf.rdoc +77 -0
  514. data/rdoc/blas.rdoc +269 -0
  515. data/rdoc/bspline.rdoc +42 -0
  516. data/rdoc/changes.rdoc +164 -0
  517. data/rdoc/cheb.rdoc +99 -0
  518. data/rdoc/cholesky_complex.rdoc +46 -0
  519. data/rdoc/combi.rdoc +125 -0
  520. data/rdoc/complex.rdoc +210 -0
  521. data/rdoc/const.rdoc +546 -0
  522. data/rdoc/dht.rdoc +122 -0
  523. data/rdoc/diff.rdoc +133 -0
  524. data/rdoc/ehandling.rdoc +50 -0
  525. data/rdoc/eigen.rdoc +401 -0
  526. data/rdoc/fft.rdoc +535 -0
  527. data/rdoc/fit.rdoc +284 -0
  528. data/rdoc/function.rdoc +94 -0
  529. data/rdoc/graph.rdoc +137 -0
  530. data/rdoc/hist.rdoc +409 -0
  531. data/rdoc/hist2d.rdoc +279 -0
  532. data/rdoc/hist3d.rdoc +112 -0
  533. data/rdoc/index.rdoc +62 -0
  534. data/rdoc/integration.rdoc +398 -0
  535. data/rdoc/interp.rdoc +231 -0
  536. data/rdoc/intro.rdoc +27 -0
  537. data/rdoc/linalg.rdoc +681 -0
  538. data/rdoc/linalg_complex.rdoc +88 -0
  539. data/rdoc/math.rdoc +276 -0
  540. data/rdoc/matrix.rdoc +1093 -0
  541. data/rdoc/min.rdoc +189 -0
  542. data/rdoc/monte.rdoc +234 -0
  543. data/rdoc/multimin.rdoc +312 -0
  544. data/rdoc/multiroot.rdoc +293 -0
  545. data/rdoc/narray.rdoc +177 -0
  546. data/rdoc/ndlinear.rdoc +250 -0
  547. data/rdoc/nonlinearfit.rdoc +348 -0
  548. data/rdoc/ntuple.rdoc +88 -0
  549. data/rdoc/odeiv.rdoc +378 -0
  550. data/rdoc/perm.rdoc +221 -0
  551. data/rdoc/poly.rdoc +335 -0
  552. data/rdoc/qrng.rdoc +90 -0
  553. data/rdoc/randist.rdoc +233 -0
  554. data/rdoc/ref.rdoc +93 -0
  555. data/rdoc/rng.rdoc +203 -0
  556. data/rdoc/rngextra.rdoc +11 -0
  557. data/rdoc/roots.rdoc +305 -0
  558. data/rdoc/screenshot.rdoc +40 -0
  559. data/rdoc/sf.rdoc +1622 -0
  560. data/rdoc/siman.rdoc +89 -0
  561. data/rdoc/sort.rdoc +94 -0
  562. data/rdoc/start.rdoc +16 -0
  563. data/rdoc/stats.rdoc +219 -0
  564. data/rdoc/sum.rdoc +65 -0
  565. data/rdoc/tensor.rdoc +251 -0
  566. data/rdoc/tut.rdoc +5 -0
  567. data/rdoc/use.rdoc +177 -0
  568. data/rdoc/vector.rdoc +1243 -0
  569. data/rdoc/vector_complex.rdoc +347 -0
  570. data/rdoc/wavelet.rdoc +218 -0
  571. data/setup.rb +1585 -0
  572. data/tests/blas/amax.rb +14 -0
  573. data/tests/blas/asum.rb +16 -0
  574. data/tests/blas/axpy.rb +25 -0
  575. data/tests/blas/copy.rb +23 -0
  576. data/tests/blas/dot.rb +23 -0
  577. data/tests/bspline.rb +53 -0
  578. data/tests/cdf.rb +1388 -0
  579. data/tests/cheb.rb +112 -0
  580. data/tests/combination.rb +123 -0
  581. data/tests/complex.rb +17 -0
  582. data/tests/const.rb +24 -0
  583. data/tests/deriv.rb +85 -0
  584. data/tests/dht/dht1.rb +17 -0
  585. data/tests/dht/dht2.rb +23 -0
  586. data/tests/dht/dht3.rb +23 -0
  587. data/tests/dht/dht4.rb +23 -0
  588. data/tests/diff.rb +78 -0
  589. data/tests/eigen/eigen.rb +220 -0
  590. data/tests/eigen/gen.rb +105 -0
  591. data/tests/eigen/genherm.rb +66 -0
  592. data/tests/eigen/gensymm.rb +68 -0
  593. data/tests/eigen/nonsymm.rb +53 -0
  594. data/tests/eigen/nonsymmv.rb +53 -0
  595. data/tests/eigen/symm-herm.rb +74 -0
  596. data/tests/err.rb +58 -0
  597. data/tests/fit.rb +124 -0
  598. data/tests/gsl_test.rb +118 -0
  599. data/tests/gsl_test2.rb +110 -0
  600. data/tests/histo.rb +12 -0
  601. data/tests/integration/integration1.rb +72 -0
  602. data/tests/integration/integration2.rb +71 -0
  603. data/tests/integration/integration3.rb +71 -0
  604. data/tests/integration/integration4.rb +71 -0
  605. data/tests/interp.rb +45 -0
  606. data/tests/linalg/HH.rb +64 -0
  607. data/tests/linalg/LU.rb +47 -0
  608. data/tests/linalg/QR.rb +77 -0
  609. data/tests/linalg/SV.rb +24 -0
  610. data/tests/linalg/TDN.rb +116 -0
  611. data/tests/linalg/TDS.rb +122 -0
  612. data/tests/linalg/bidiag.rb +73 -0
  613. data/tests/linalg/cholesky.rb +20 -0
  614. data/tests/linalg/linalg.rb +158 -0
  615. data/tests/matrix/matrix_complex_test.rb +36 -0
  616. data/tests/matrix/matrix_nmf_test.rb +39 -0
  617. data/tests/matrix/matrix_test.rb +48 -0
  618. data/tests/min.rb +99 -0
  619. data/tests/monte/miser.rb +31 -0
  620. data/tests/monte/vegas.rb +45 -0
  621. data/tests/multifit/test_2dgauss.rb +112 -0
  622. data/tests/multifit/test_brown.rb +90 -0
  623. data/tests/multifit/test_enso.rb +246 -0
  624. data/tests/multifit/test_filip.rb +155 -0
  625. data/tests/multifit/test_gauss.rb +97 -0
  626. data/tests/multifit/test_longley.rb +110 -0
  627. data/tests/multifit/test_multifit.rb +52 -0
  628. data/tests/multimin.rb +139 -0
  629. data/tests/multiroot.rb +131 -0
  630. data/tests/multiset.rb +52 -0
  631. data/tests/narray/blas_dnrm2.rb +20 -0
  632. data/tests/odeiv.rb +353 -0
  633. data/tests/poly/poly.rb +290 -0
  634. data/tests/poly/special.rb +65 -0
  635. data/tests/qrng.rb +131 -0
  636. data/tests/quartic.rb +29 -0
  637. data/tests/randist.rb +134 -0
  638. data/tests/rng.rb +305 -0
  639. data/tests/roots.rb +76 -0
  640. data/tests/run-test.sh +17 -0
  641. data/tests/sf/gsl_test_sf.rb +249 -0
  642. data/tests/sf/test_airy.rb +83 -0
  643. data/tests/sf/test_bessel.rb +306 -0
  644. data/tests/sf/test_coulomb.rb +17 -0
  645. data/tests/sf/test_dilog.rb +25 -0
  646. data/tests/sf/test_gamma.rb +209 -0
  647. data/tests/sf/test_hyperg.rb +356 -0
  648. data/tests/sf/test_legendre.rb +227 -0
  649. data/tests/sf/test_mathieu.rb +59 -0
  650. data/tests/sf/test_mode.rb +19 -0
  651. data/tests/sf/test_sf.rb +839 -0
  652. data/tests/stats.rb +174 -0
  653. data/tests/stats_mt.rb +16 -0
  654. data/tests/sum.rb +98 -0
  655. data/tests/sys.rb +323 -0
  656. data/tests/tensor.rb +419 -0
  657. data/tests/vector/vector_complex_test.rb +101 -0
  658. data/tests/vector/vector_test.rb +141 -0
  659. data/tests/wavelet.rb +142 -0
  660. metadata +789 -0
@@ -0,0 +1,1871 @@
1
+ /*
2
+ multifit.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2004 by Yoshiki Tsunesada
5
+
6
+ Ruby/GSL is free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License.
8
+ This library is distributed in the hope that it will be useful, but
9
+ WITHOUT ANY WARRANTY.
10
+ */
11
+ #include "rb_gsl_config.h"
12
+ #include "rb_gsl_fit.h"
13
+ #include "rb_gsl_function.h"
14
+ #include "rb_gsl_common.h"
15
+
16
+ #ifdef HAVE_NDLINEAR_GSL_MULTIFIT_NDLINEAR_H
17
+ #include <ndlinear/gsl_multifit_ndlinear.h>
18
+ void Init_ndlinear(VALUE module);
19
+ #endif
20
+
21
+ #ifndef CHECK_WORKSPACE
22
+ #define CHECK_WORKSPACE(x) if(CLASS_OF(x)!=cgsl_multifit_workspace)\
23
+ rb_raise(rb_eTypeError,\
24
+ "wrong argument type %s (GSL::MultiFit::Workspace expected)",\
25
+ rb_class2name(CLASS_OF(x)));
26
+ #endif
27
+
28
+ #ifndef CHECK_MULTIFIT_FUNCTION_FDF
29
+ #define CHECK_MULTIFIT_FUNCTION_FDF(x) if(CLASS_OF(x)!=cgsl_multifit_function_fdf)\
30
+ rb_raise(rb_eTypeError,\
31
+ "wrong argument type %s (GSL::MultiFit::Workspace expected)",\
32
+ rb_class2name(CLASS_OF(x)));
33
+ #endif
34
+
35
+ static VALUE cgsl_multifit_workspace;
36
+ static VALUE cgsl_multifit_function_fdf;
37
+
38
+ enum MultiFit_Solver_Type{
39
+ GSL_MULTIFIT_FDFSOLVER_LMSDER,
40
+ GSL_MULTIFIT_FDFSOLVER_LMDER,
41
+ };
42
+
43
+ static VALUE rb_gsl_multifit_workspace_new(VALUE klass, VALUE n, VALUE p)
44
+ {
45
+ gsl_multifit_linear_workspace *w = NULL;
46
+ CHECK_FIXNUM(n); CHECK_FIXNUM(p);
47
+ w = gsl_multifit_linear_alloc(FIX2INT(n), FIX2INT(p));
48
+ return Data_Wrap_Struct(cgsl_multifit_workspace, 0, gsl_multifit_linear_free, w);
49
+ }
50
+
51
+ static VALUE rb_gsl_multifit_linear(int argc, VALUE *argv, VALUE obj)
52
+ {
53
+ gsl_multifit_linear_workspace *space = NULL;
54
+ gsl_matrix *x = NULL, *cov = NULL;
55
+ gsl_vector *y = NULL, *c = NULL;
56
+ double chisq;
57
+ int status, flag = 0;
58
+ VALUE vc, vcov;
59
+ if (argc != 2 && argc != 3)
60
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
61
+ Data_Get_Matrix(argv[0], x);
62
+ Data_Get_Vector(argv[1], y);
63
+ if (argc == 3) {
64
+ CHECK_WORKSPACE(argv[2]);
65
+ Data_Get_Struct(argv[2], gsl_multifit_linear_workspace, space);
66
+ } else {
67
+ space = gsl_multifit_linear_alloc(x->size1, x->size2);
68
+ flag = 1;
69
+ }
70
+ cov = gsl_matrix_alloc(x->size2, x->size2);
71
+ c = gsl_vector_alloc(x->size2);
72
+ status = gsl_multifit_linear(x, y, c, cov, &chisq, space);
73
+ if (flag == 1) gsl_multifit_linear_free(space);
74
+ vc = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, c);
75
+ vcov = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, cov);
76
+ return rb_ary_new3(4, vc, vcov, rb_float_new(chisq), INT2FIX(status));
77
+ }
78
+
79
+ static VALUE rb_gsl_multifit_wlinear(int argc, VALUE *argv, VALUE obj)
80
+ {
81
+ gsl_multifit_linear_workspace *space = NULL;
82
+ gsl_matrix *x = NULL, *cov = NULL;
83
+ gsl_vector *w = NULL, *y = NULL, *c = NULL;
84
+ double chisq;
85
+ int status, flag = 0;
86
+ VALUE vc, vcov;
87
+ if (argc != 3 && argc != 4)
88
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
89
+ Data_Get_Matrix(argv[0], x);
90
+ Data_Get_Vector(argv[1], w);
91
+ Data_Get_Vector(argv[2], y);
92
+ if (argc == 4) {
93
+ CHECK_WORKSPACE(argv[3]);
94
+ Data_Get_Struct(argv[3], gsl_multifit_linear_workspace, space);
95
+ } else {
96
+ space = gsl_multifit_linear_alloc(x->size1, x->size2);
97
+ flag = 1;
98
+ }
99
+ cov = gsl_matrix_alloc(x->size2, x->size2);
100
+ c = gsl_vector_alloc(x->size2);
101
+ status = gsl_multifit_wlinear(x, w, y, c, cov, &chisq, space);
102
+ if (flag == 1) gsl_multifit_linear_free(space);
103
+ vc = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, c);
104
+ vcov = Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, cov);
105
+ return rb_ary_new3(4, vc, vcov, rb_float_new(chisq), INT2FIX(status));
106
+ }
107
+
108
+ static void calc_X_power(gsl_matrix *X, gsl_vector *x, size_t order)
109
+ {
110
+ size_t i, j;
111
+ double val;
112
+ for (i = 0; i < x->size; i++) {
113
+ val = 1.0;
114
+ gsl_matrix_set(X, i, 0, val);
115
+ for (j = 1; j <= order; j++) {
116
+ val *= gsl_vector_get(x, i);
117
+ gsl_matrix_set(X, i, j, val);
118
+ }
119
+ }
120
+ }
121
+
122
+ static void calc_X_legendre(gsl_matrix *X, gsl_vector *v, size_t order)
123
+ {
124
+ size_t i, n;
125
+ double a, b, c, x;
126
+ for (i = 0; i < v->size; i++) {
127
+ a = 1.0;
128
+ b = gsl_vector_get(v, i);
129
+ gsl_matrix_set(X, i, 0, a);
130
+ gsl_matrix_set(X, i, 1, b);
131
+ for (n = 2; n <= order; n++) {
132
+ x = gsl_vector_get(v, i);
133
+ c = ((2*n-1)*x*b - (n-1)*a)/n;
134
+ gsl_matrix_set(X, i, n, c);
135
+ a = b;
136
+ b = c;
137
+ }
138
+ }
139
+ }
140
+
141
+ static VALUE rb_gsl_multifit_XXXfit(int argc, VALUE *argv, VALUE obj,
142
+ void (*fn)(gsl_matrix*, gsl_vector*,size_t))
143
+ {
144
+ gsl_multifit_linear_workspace *space = NULL;
145
+ gsl_matrix *X = NULL, *cov = NULL;
146
+ gsl_vector *x, *y = NULL, *w, *c = NULL, *err;
147
+ gsl_vector_view xx, yy, ww;
148
+ size_t order, i;
149
+ double chisq;
150
+ int status, flag = 0, flagw = 0;
151
+ VALUE vc, verr;
152
+ if (argc != 3 && argc != 4 && argc != 5)
153
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
154
+ x = &xx.vector;
155
+ w = &ww.vector;
156
+ y = &yy.vector;
157
+ Data_Get_Vector(argv[0], x);
158
+ if (argc >= 3 && VECTOR_P(argv[2])) {
159
+ Data_Get_Vector(argv[1], w);
160
+ Data_Get_Vector(argv[2], y);
161
+ order = NUM2INT(argv[3]);
162
+ flagw = 1;
163
+ } else {
164
+ Data_Get_Vector(argv[1], y);
165
+ order = NUM2INT(argv[2]);
166
+ flagw = 0;
167
+ }
168
+ if (rb_obj_is_kind_of(argv[argc-1], cgsl_multifit_workspace)) {
169
+ Data_Get_Struct(argv[argc-1], gsl_multifit_linear_workspace, space);
170
+ } else {
171
+ space = gsl_multifit_linear_alloc(x->size, order + 1);
172
+ flag = 1;
173
+ }
174
+ cov = gsl_matrix_alloc(order + 1, order + 1);
175
+ c = gsl_vector_alloc(order + 1);
176
+ X = gsl_matrix_alloc(x->size, order + 1);
177
+ (*fn)(X, x, order);
178
+ if (flagw == 0) status = gsl_multifit_linear(X, y, c, cov, &chisq, space);
179
+ else status = gsl_multifit_wlinear(X, w, y, c, cov, &chisq, space);
180
+ if (flag == 1) gsl_multifit_linear_free(space);
181
+ err = gsl_vector_alloc(order + 1);
182
+ vc = Data_Wrap_Struct(cgsl_poly, 0, gsl_vector_free, c);
183
+ verr = Data_Wrap_Struct(cgsl_poly, 0, gsl_vector_free, err);
184
+ for (i = 0; i < err->size; i++)
185
+ gsl_vector_set(err, i, sqrt(chisq/((double)x->size-err->size)*gsl_matrix_get(cov, i, i)));
186
+
187
+ gsl_matrix_free(X);
188
+ gsl_matrix_free(cov);
189
+ return rb_ary_new3(4, vc, verr, rb_float_new(chisq), INT2FIX(status));
190
+ }
191
+
192
+ static VALUE rb_gsl_multifit_polyfit(int argc, VALUE *argv, VALUE obj)
193
+ {
194
+ return rb_gsl_multifit_XXXfit(argc, argv, obj, calc_X_power);
195
+ }
196
+
197
+ static VALUE rb_gsl_multifit_legfit(int argc, VALUE *argv, VALUE obj)
198
+ {
199
+ return rb_gsl_multifit_XXXfit(argc, argv, obj, calc_X_legendre);
200
+ }
201
+
202
+ /**********/
203
+
204
+ static VALUE rb_gsl_multifit_fdfsolver_new(int argc, VALUE *argv, VALUE klass)
205
+ {
206
+ const gsl_multifit_fdfsolver_type *T;
207
+ gsl_multifit_fdfsolver *solver = NULL;
208
+ size_t n, p;
209
+ char name[64];
210
+ switch (argc) {
211
+ case 3:
212
+ switch (TYPE(argv[0])) {
213
+ case T_STRING:
214
+ strcpy(name, STR2CSTR(argv[0]));
215
+ if (str_tail_grep(name, "lmsder") == 0) {
216
+ T = gsl_multifit_fdfsolver_lmsder;
217
+ } else if (str_tail_grep(name, "lmder") == 0) {
218
+ T = gsl_multifit_fdfsolver_lmder;
219
+ } else {
220
+ rb_raise(rb_eTypeError, "unknown solver type %s (lmsder of lmder)",
221
+ name);
222
+ }
223
+ break;
224
+ case T_FIXNUM:
225
+ switch (FIX2INT(argv[0])) {
226
+ case GSL_MULTIFIT_FDFSOLVER_LMSDER:
227
+ T = gsl_multifit_fdfsolver_lmsder;
228
+ break;
229
+ case GSL_MULTIFIT_FDFSOLVER_LMDER:
230
+ T = gsl_multifit_fdfsolver_lmder;
231
+ break;
232
+ default:
233
+ rb_raise(rb_eTypeError,
234
+ "unknown solver type (GSL::MultiFit::FdfSolver::LMSDER or LMDER expected)");
235
+ break;
236
+ }
237
+ break;
238
+ default:
239
+ rb_raise(rb_eTypeError, "wrong argument type %s (Fixnum or String)",
240
+ rb_class2name(CLASS_OF(argv[0])));
241
+ break;
242
+ }
243
+ CHECK_FIXNUM(argv[1]); CHECK_FIXNUM(argv[2]);
244
+ n = FIX2INT(argv[1]);
245
+ p = FIX2INT(argv[2]);
246
+ break;
247
+ case 2:
248
+ CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
249
+ T = gsl_multifit_fdfsolver_lmsder;
250
+ n = FIX2INT(argv[0]);
251
+ p = FIX2INT(argv[1]);
252
+ break;
253
+ default:
254
+ rb_raise(rb_eArgError, "wrong number of arguments");
255
+ break;
256
+ }
257
+ solver = gsl_multifit_fdfsolver_alloc(T, n, p);
258
+ return Data_Wrap_Struct(klass, 0, gsl_multifit_fdfsolver_free, solver);
259
+ }
260
+
261
+ static VALUE rb_gsl_multifit_fdfsolver_set(VALUE obj, VALUE ff, VALUE xx)
262
+ {
263
+ gsl_multifit_fdfsolver *solver = NULL;
264
+ gsl_multifit_function_fdf *f = NULL;
265
+ gsl_vector *x = NULL;
266
+ int status;
267
+ CHECK_MULTIFIT_FUNCTION_FDF(ff);
268
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
269
+ Data_Get_Struct(ff, gsl_multifit_function_fdf, f);
270
+ Data_Get_Vector(xx, x);
271
+ status = gsl_multifit_fdfsolver_set(solver, f, x);
272
+ return INT2FIX(status);
273
+ }
274
+
275
+ static VALUE rb_gsl_multifit_fdfsolver_name(VALUE obj)
276
+ {
277
+ gsl_multifit_fdfsolver *solver = NULL;
278
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
279
+ return rb_str_new2(gsl_multifit_fdfsolver_name(solver));
280
+ }
281
+
282
+ static VALUE rb_gsl_multifit_fdfsolver_iterate(VALUE obj)
283
+ {
284
+ gsl_multifit_fdfsolver *solver = NULL;
285
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
286
+ return INT2FIX(gsl_multifit_fdfsolver_iterate(solver));
287
+ }
288
+
289
+ static VALUE rb_gsl_multifit_fdfsolver_position(VALUE obj)
290
+ {
291
+ gsl_multifit_fdfsolver *solver = NULL;
292
+ gsl_vector *x = NULL;
293
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
294
+ x = gsl_multifit_fdfsolver_position(solver);
295
+ return Data_Wrap_Struct(cgsl_vector_view_ro, 0, NULL, x);
296
+ }
297
+
298
+ static VALUE rb_gsl_multifit_fdfsolver_print_state(VALUE obj, VALUE i)
299
+ {
300
+ gsl_multifit_fdfsolver *solver = NULL;
301
+ CHECK_FIXNUM(i);
302
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
303
+ printf("iter: %d x = %15.8f %15.8f %15.8f |f(x)| = %g\n",
304
+ (int) FIX2INT(i), gsl_vector_get(solver->x, 0), gsl_vector_get(solver->x, 1),
305
+ gsl_vector_get(solver->x, 2), gsl_blas_dnrm2(solver->f));
306
+ return Qtrue;
307
+ }
308
+
309
+ static VALUE rb_gsl_multifit_fdfsolver_fdf(VALUE obj)
310
+ {
311
+ gsl_multifit_fdfsolver *solver = NULL;
312
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
313
+ return Data_Wrap_Struct(cgsl_multifit_function_fdf, 0, NULL, solver->fdf);
314
+ }
315
+
316
+ static VALUE rb_gsl_multifit_fdfsolver_test_delta(VALUE obj, VALUE r, VALUE a)
317
+ {
318
+ gsl_multifit_fdfsolver *solver = NULL;
319
+ Need_Float(r); Need_Float(a);
320
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
321
+ return INT2FIX(gsl_multifit_test_delta(solver->dx, solver->x, NUM2DBL(r), NUM2DBL(a)));
322
+ }
323
+
324
+ static VALUE rb_gsl_multifit_fdfsolver_test_gradient(int argc, VALUE *argv, VALUE obj)
325
+ {
326
+ gsl_multifit_fdfsolver *solver = NULL;
327
+ gsl_vector *g = NULL;
328
+ int status;
329
+ double epsabs;
330
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
331
+ switch (argc) {
332
+ case 1:
333
+ Need_Float(argv[0]);
334
+ g = gsl_vector_alloc(solver->x->size);
335
+ gsl_multifit_gradient(solver->J, solver->f, g);
336
+ epsabs = NUM2DBL(argv[0]);
337
+ status = gsl_multifit_test_gradient(g, epsabs);
338
+ gsl_vector_free(g);
339
+ break;
340
+ case 2:
341
+ Need_Float(argv[1]);
342
+ Data_Get_Vector(argv[0], g);
343
+ epsabs = NUM2DBL(argv[1]);
344
+ status = gsl_multifit_test_gradient(g, epsabs);
345
+ break;
346
+ default:
347
+ rb_raise(rb_eArgError, "wrong number of arguments");
348
+ break;
349
+ }
350
+ return INT2FIX(status);
351
+ }
352
+
353
+ static VALUE rb_gsl_multifit_fdfsolver_gradient(int argc, VALUE *argv, VALUE obj)
354
+ {
355
+ gsl_multifit_fdfsolver *solver = NULL;
356
+ gsl_vector *g = NULL;
357
+ // local variable "status" declared and set, but never used
358
+ //int status;
359
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
360
+ if (argc == 1) {
361
+ Data_Get_Vector(argv[0], g);
362
+ return INT2FIX(gsl_multifit_gradient(solver->J, solver->f, g));
363
+ } else {
364
+ g = gsl_vector_alloc(solver->x->size);
365
+ /*status =*/ gsl_multifit_gradient(solver->J, solver->f, g);
366
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, g);
367
+ }
368
+ }
369
+
370
+ static VALUE rb_gsl_multifit_fdfsolver_covar(int argc, VALUE *argv, VALUE obj)
371
+ {
372
+ gsl_multifit_fdfsolver *solver = NULL;
373
+ gsl_matrix *covar = NULL;
374
+ double epsrel;
375
+ // local variable "status" declared and set, but never used
376
+ //int status;
377
+ if (argc < 1) rb_raise(rb_eArgError, "too few arguments");
378
+ Need_Float(argv[0]);
379
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
380
+ epsrel = NUM2DBL(argv[0]);
381
+ switch (argc) {
382
+ case 1:
383
+ covar = gsl_matrix_alloc(solver->x->size, solver->x->size);
384
+ /*status =*/ gsl_multifit_covar(solver->J, epsrel, covar);
385
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, covar);
386
+ break;
387
+ case 2:
388
+ Data_Get_Matrix(argv[1], covar);
389
+ return INT2FIX(gsl_multifit_covar(solver->J, epsrel, covar));
390
+ break;
391
+ default:
392
+ rb_raise(rb_eArgError, "wrong number of arguments");
393
+ break;
394
+ }
395
+ }
396
+
397
+ static VALUE rb_gsl_multifit_fdfsolver_x(VALUE obj)
398
+ {
399
+ gsl_multifit_fdfsolver *solver = NULL;
400
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
401
+ return Data_Wrap_Struct(cgsl_vector_view_ro, 0, NULL, solver->x);
402
+ }
403
+
404
+ static VALUE rb_gsl_multifit_fdfsolver_dx(VALUE obj)
405
+ {
406
+ gsl_multifit_fdfsolver *solver = NULL;
407
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
408
+ return Data_Wrap_Struct(cgsl_vector_view_ro, 0, NULL, solver->dx);
409
+ }
410
+
411
+ static VALUE rb_gsl_multifit_fdfsolver_f(VALUE obj)
412
+ {
413
+ gsl_multifit_fdfsolver *solver = NULL;
414
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
415
+ return Data_Wrap_Struct(cgsl_vector_view_ro, 0, NULL, solver->f);
416
+ }
417
+
418
+ static VALUE rb_gsl_multifit_fdfsolver_J(VALUE obj)
419
+ {
420
+ gsl_multifit_fdfsolver *solver = NULL;
421
+ Data_Get_Struct(obj, gsl_multifit_fdfsolver, solver);
422
+ return Data_Wrap_Struct(cgsl_matrix_view_ro, 0, NULL, solver->J);
423
+ }
424
+
425
+ /* singleton */
426
+ static VALUE rb_gsl_multifit_test_delta(VALUE obj, VALUE ddx, VALUE xx, VALUE a, VALUE r)
427
+ {
428
+ gsl_vector *dx = NULL, *x = NULL;
429
+ Need_Float(a); Need_Float(r);
430
+ Data_Get_Vector(ddx, dx);
431
+ Data_Get_Vector(xx, x);
432
+ return INT2FIX(gsl_multifit_test_delta(dx, x, NUM2DBL(a), NUM2DBL(r)));
433
+ }
434
+
435
+ static VALUE rb_gsl_multifit_test_gradient(VALUE obj, VALUE gg, VALUE a)
436
+ {
437
+ gsl_vector *g = NULL;
438
+ Need_Float(a);
439
+ Data_Get_Vector(gg, g);
440
+ return INT2FIX(gsl_multifit_test_gradient(g, NUM2DBL(a)));
441
+ }
442
+
443
+ static VALUE rb_gsl_multifit_gradient(int argc, VALUE *argv, VALUE obj)
444
+ {
445
+ gsl_vector *g = NULL, *f = NULL;
446
+ gsl_matrix *J = NULL;
447
+ // local variable "status" declared and set, but never used
448
+ //int status;
449
+ switch (argc) {
450
+ case 2:
451
+ Data_Get_Matrix(argv[0], J);
452
+ Data_Get_Vector(argv[1], f);
453
+ g = gsl_vector_alloc(f->size);
454
+ /*status =*/ gsl_multifit_gradient(J, f, g);
455
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, g);
456
+ break;
457
+ case 3:
458
+ Data_Get_Matrix(argv[0], J);
459
+ Data_Get_Vector(argv[1], f);
460
+ Data_Get_Vector(argv[2], g);
461
+ return INT2FIX(gsl_multifit_gradient(J, f, g));
462
+ break;
463
+ default:
464
+ rb_raise(rb_eArgError, "wrong number of arguments");
465
+ break;
466
+ }
467
+ }
468
+
469
+ static VALUE rb_gsl_multifit_covar(int argc, VALUE *argv, VALUE obj)
470
+ {
471
+ gsl_matrix *J = NULL, *covar = NULL;
472
+ double epsrel;
473
+ int status;
474
+ switch (argc) {
475
+ case 2:
476
+ Need_Float(argv[1]);
477
+ Data_Get_Matrix(argv[0], J);
478
+ epsrel = NUM2DBL(argv[1]);
479
+ covar = gsl_matrix_alloc(J->size2, J->size2);
480
+ /*status =*/ gsl_multifit_covar(J, epsrel, covar);
481
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, covar);
482
+ break;
483
+ case 3:
484
+ Need_Float(argv[1]);
485
+ Data_Get_Matrix(argv[0], J);
486
+ epsrel = NUM2DBL(argv[1]);
487
+ Data_Get_Matrix(argv[2], covar);
488
+ status = gsl_multifit_covar(J, epsrel, covar);
489
+ return INT2FIX(status);
490
+ break;
491
+ default:
492
+ rb_raise(rb_eArgError, "wrong number of arguments");
493
+ break;
494
+ }
495
+ }
496
+
497
+ static void rb_gsl_multifit_define_const(VALUE klass)
498
+ {
499
+ rb_define_const(klass, "LMSDER",
500
+ INT2FIX(GSL_MULTIFIT_FDFSOLVER_LMSDER));
501
+ rb_define_const(klass, "LMDER",
502
+ INT2FIX(GSL_MULTIFIT_FDFSOLVER_LMDER));
503
+
504
+ rb_define_const(klass, "Lmsder",
505
+ INT2FIX(GSL_MULTIFIT_FDFSOLVER_LMSDER));
506
+ rb_define_const(klass, "Lmder",
507
+ INT2FIX(GSL_MULTIFIT_FDFSOLVER_LMDER));
508
+ }
509
+
510
+ static void gsl_multifit_function_fdf_free(gsl_multifit_function_fdf *f);
511
+ static void gsl_multifit_function_fdf_free(gsl_multifit_function_fdf *f)
512
+ {
513
+ free((gsl_multifit_function_fdf *) f);
514
+ }
515
+
516
+ static void gsl_multifit_function_fdf_mark(gsl_multifit_function_fdf *F);
517
+ static void gsl_multifit_function_fdf_mark(gsl_multifit_function_fdf *F)
518
+ {
519
+ rb_gc_mark((VALUE) F->params);
520
+ }
521
+
522
+ static int gsl_multifit_function_fdf_f(const gsl_vector *x, void *params,
523
+ gsl_vector *f);
524
+ static int gsl_multifit_function_fdf_df(const gsl_vector *x, void *params,
525
+ gsl_matrix *J);
526
+ static int gsl_multifit_function_fdf_fdf(const gsl_vector *x, void *params,
527
+ gsl_vector *f, gsl_matrix *J);
528
+
529
+ static VALUE rb_gsl_multifit_function_fdf_set_procs(int argc, VALUE *argv, VALUE obj);
530
+
531
+ static VALUE rb_gsl_multifit_function_fdf_new(int argc, VALUE *argv, VALUE klass)
532
+ {
533
+ gsl_multifit_function_fdf *func = NULL;
534
+ VALUE obj;
535
+ func = ALLOC(gsl_multifit_function_fdf);
536
+ func->f = &gsl_multifit_function_fdf_f;
537
+ func->df = &gsl_multifit_function_fdf_df;
538
+ func->fdf = &gsl_multifit_function_fdf_fdf;
539
+ func->params = NULL;
540
+ obj = Data_Wrap_Struct(klass, gsl_multifit_function_fdf_mark, gsl_multifit_function_fdf_free, func);
541
+ switch (argc) {
542
+ case 0:
543
+ case 1:
544
+ break;
545
+ case 2:
546
+ case 3:
547
+ rb_gsl_multifit_function_fdf_set_procs(argc, argv, obj);
548
+ break;
549
+ default:
550
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0-3)", argc);
551
+ break;
552
+ }
553
+ return obj;
554
+ }
555
+
556
+ static VALUE rb_gsl_multifit_function_fdf_set_procs(int argc, VALUE *argv, VALUE obj)
557
+ {
558
+ gsl_multifit_function_fdf *func = NULL;
559
+ VALUE ary;
560
+ Data_Get_Struct(obj, gsl_multifit_function_fdf, func);
561
+ if (func->params == NULL) {
562
+ ary = rb_ary_new2(4);
563
+ /* (VALUE) func->params = ary;*/
564
+ func->params = (void *) ary;
565
+ } else {
566
+ ary = (VALUE) func->params;
567
+ }
568
+ rb_ary_store(ary, 0, argv[0]);
569
+ rb_ary_store(ary, 1, argv[1]);
570
+ switch (argc) {
571
+ case 2:
572
+ break;
573
+ case 3:
574
+ if (TYPE(argv[2]) == T_FIXNUM) {
575
+ func->p = FIX2INT(argv[2]);
576
+ rb_ary_store(ary, 2, Qnil);
577
+ } else rb_ary_store(ary, 2, argv[2]);
578
+ break;
579
+ case 4:
580
+ if (TYPE(argv[2]) == T_FIXNUM) {
581
+ func->p = FIX2INT(argv[2]);
582
+ rb_ary_store(ary, 2, argv[3]);
583
+ } else {
584
+ func->p = FIX2INT(argv[3]);
585
+ rb_ary_store(ary, 2, argv[2]);
586
+ }
587
+ break;
588
+ default:
589
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3 or 4)", argc);
590
+ break;
591
+ }
592
+ return obj;
593
+ }
594
+
595
+ static VALUE rb_gsl_multifit_function_fdf_set_data(int argc, VALUE *argv, VALUE obj)
596
+ {
597
+ VALUE ary, ary2;
598
+ gsl_multifit_function_fdf *func = NULL;
599
+ Data_Get_Struct(obj, gsl_multifit_function_fdf, func);
600
+ if (func->params == NULL) {
601
+ ary = rb_ary_new2(4);
602
+ /* (VALUE) func->params = ary;*/
603
+ func->params = (void *) ary;
604
+ } else {
605
+ ary = (VALUE) func->params;
606
+ }
607
+ switch (argc) {
608
+ case 2:
609
+ ary2 = rb_ary_new3(2, argv[0], argv[1]); /* t, y */
610
+ break;
611
+ case 3:
612
+ ary2 = rb_ary_new3(3, argv[0], argv[1], argv[2]); /* t, y, sigma */
613
+ break;
614
+ default:
615
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
616
+ break;
617
+ }
618
+ func->n = NUM2INT(rb_funcall(argv[0], rb_intern("size"), 0));
619
+ rb_ary_store(ary, 3, ary2);
620
+ return obj;
621
+ }
622
+
623
+ static int gsl_multifit_function_fdf_f(const gsl_vector *x, void *params,
624
+ gsl_vector *f)
625
+ {
626
+ VALUE vt_y_sigma, vt, vy, vsigma, vf, vx, proc, ary;
627
+ ary = (VALUE) params;
628
+ vt_y_sigma = rb_ary_entry(ary, 3);
629
+ proc = rb_ary_entry(ary, 0);
630
+ vx = Data_Wrap_Struct(cgsl_vector, 0, NULL, (gsl_vector *) x);
631
+ vf = Data_Wrap_Struct(cgsl_vector, 0, NULL, f);
632
+ switch (RARRAY_LEN(vt_y_sigma)) {
633
+ case 2:
634
+ vt = rb_ary_entry(vt_y_sigma, 0);
635
+ vy = rb_ary_entry(vt_y_sigma, 1);
636
+ rb_funcall(proc, RBGSL_ID_call, 4, vx, vt, vy, vf);
637
+ break;
638
+ case 3:
639
+ vt = rb_ary_entry(vt_y_sigma, 0);
640
+ vy = rb_ary_entry(vt_y_sigma, 1);
641
+ vsigma = rb_ary_entry(vt_y_sigma,2);
642
+ rb_funcall(proc, RBGSL_ID_call, 5, vx, vt, vy, vsigma, vf);
643
+ break;
644
+ default:
645
+ rb_raise(rb_eArgError, "bad argument");
646
+ break;
647
+ }
648
+ return GSL_SUCCESS;
649
+ }
650
+
651
+ static int gsl_multifit_function_fdf_df(const gsl_vector *x, void *params,
652
+ gsl_matrix *J)
653
+ {
654
+ VALUE vt_y_sigma, vt, vy, vsigma, vJ, vx, proc, ary;
655
+ ary = (VALUE) params;
656
+ vt_y_sigma = rb_ary_entry(ary, 3);
657
+ proc = rb_ary_entry(ary, 1);
658
+ vx = Data_Wrap_Struct(cgsl_vector, 0, NULL, (gsl_vector *) x);
659
+ vJ = Data_Wrap_Struct(cgsl_matrix, 0, NULL, J);
660
+ switch (RARRAY_LEN(vt_y_sigma)) {
661
+ case 2:
662
+ vt = rb_ary_entry(vt_y_sigma, 0);
663
+ vy = rb_ary_entry(vt_y_sigma, 1);
664
+ rb_funcall(proc, RBGSL_ID_call, 4, vx, vt, vy, vJ);
665
+ break;
666
+ case 3:
667
+ vt = rb_ary_entry(vt_y_sigma, 0);
668
+ vy = rb_ary_entry(vt_y_sigma, 1);
669
+ vsigma = rb_ary_entry(vt_y_sigma,2);
670
+ rb_funcall(proc, RBGSL_ID_call, 5, vx, vt, vy, vsigma, vJ);
671
+ break;
672
+ default:
673
+ rb_raise(rb_eArgError, "bad argument");
674
+ break;
675
+ }
676
+ return GSL_SUCCESS;
677
+ }
678
+
679
+ static int gsl_multifit_function_fdf_fdf(const gsl_vector *x, void *params,
680
+ gsl_vector *f, gsl_matrix *J)
681
+ {
682
+ VALUE vt_y_sigma, vt, vy, vsigma, vf, vJ, vx, proc_f, proc_df, proc_fdf;
683
+ VALUE ary;
684
+ ary = (VALUE) params;
685
+ vt_y_sigma = rb_ary_entry(ary, 3);
686
+ proc_f = rb_ary_entry(ary, 0);
687
+ proc_df = rb_ary_entry(ary, 1);
688
+ proc_fdf = rb_ary_entry(ary, 2);
689
+ vx = Data_Wrap_Struct(cgsl_vector, 0, NULL, (gsl_vector *) x);
690
+ vf = Data_Wrap_Struct(cgsl_vector, 0, NULL, f);
691
+ vJ = Data_Wrap_Struct(cgsl_matrix, 0, NULL, J);
692
+ switch (RARRAY_LEN(vt_y_sigma)) {
693
+ case 2:
694
+ vt = rb_ary_entry(vt_y_sigma, 0);
695
+ vy = rb_ary_entry(vt_y_sigma, 1);
696
+ if (NIL_P(proc_fdf)) {
697
+ rb_funcall(proc_f, RBGSL_ID_call, 4, vx, vt, vy, vf);
698
+ rb_funcall(proc_df, RBGSL_ID_call, 4, vx, vt, vy, vJ);
699
+ } else
700
+ rb_funcall(proc_fdf, RBGSL_ID_call, 5, vx, vt, vy, vf, vJ);
701
+ break;
702
+ case 3:
703
+ vt = rb_ary_entry(vt_y_sigma, 0);
704
+ vy = rb_ary_entry(vt_y_sigma, 1);
705
+ vsigma = rb_ary_entry(vt_y_sigma,2);
706
+ if (NIL_P(proc_fdf)) {
707
+ rb_funcall(proc_f, RBGSL_ID_call, 5, vx, vt, vy, vsigma, vf);
708
+ rb_funcall(proc_df, RBGSL_ID_call, 5, vx, vt, vy, vsigma, vJ);
709
+ } else
710
+ rb_funcall(proc_fdf, RBGSL_ID_call, 6, vx, vt, vy, vsigma, vf, vJ);
711
+ break;
712
+ default:
713
+ rb_raise(rb_eArgError, "bad argument");
714
+ break;
715
+ }
716
+ return GSL_SUCCESS;
717
+ }
718
+
719
+ static VALUE rb_gsl_multifit_function_fdf_params(VALUE obj)
720
+ {
721
+ gsl_multifit_function_fdf *f = NULL;
722
+ Data_Get_Struct(obj, gsl_multifit_function_fdf, f);
723
+ return (VALUE) f->params;
724
+ }
725
+
726
+ static VALUE rb_gsl_multifit_function_fdf_n(VALUE obj)
727
+ {
728
+ gsl_multifit_function_fdf *f = NULL;
729
+ Data_Get_Struct(obj, gsl_multifit_function_fdf, f);
730
+ return INT2FIX(f->n);
731
+ }
732
+
733
+ static VALUE rb_gsl_multifit_function_fdf_set_n(VALUE obj, VALUE n)
734
+ {
735
+ gsl_multifit_function_fdf *f = NULL;
736
+ Data_Get_Struct(obj, gsl_multifit_function_fdf, f);
737
+ f->n = FIX2INT(n);
738
+ return obj;
739
+ }
740
+
741
+ static VALUE rb_gsl_multifit_function_fdf_p(VALUE obj)
742
+ {
743
+ gsl_multifit_function_fdf *f = NULL;
744
+ Data_Get_Struct(obj, gsl_multifit_function_fdf, f);
745
+ return INT2FIX(f->p);
746
+ }
747
+
748
+ /*****/
749
+ struct fitting_xydata {
750
+ gsl_vector *x, *y, *w;
751
+ };
752
+
753
+ /* Gaussian fit
754
+ y = y0 + A exp(-(x-x0/sigma)^2)
755
+ v[0] = y0
756
+ v[1] = A
757
+ v[2] = x0
758
+ v[3] = var = sigma^2
759
+ */
760
+ static int Gaussian_f(const gsl_vector *v, void *data, gsl_vector *f)
761
+ {
762
+ gsl_vector *x, *y, *w;
763
+ double y0, A, x0, var, xi, yi, wi;
764
+ size_t i;
765
+ struct fitting_xydata *xydata;
766
+ xydata = (struct fitting_xydata*) data;
767
+ x = xydata->x;
768
+ y = xydata->y;
769
+ w = xydata->w;
770
+ var = gsl_vector_get(v, 3);
771
+ x0 = gsl_vector_get(v, 2);
772
+ A = gsl_vector_get(v, 1);
773
+ y0 = gsl_vector_get(v, 0);
774
+ for (i = 0; i < x->size; i++) {
775
+ xi = gsl_vector_get(x, i);
776
+ yi = gsl_vector_get(y, i);
777
+ if (w) wi = gsl_vector_get(w, i);
778
+ else wi = 1.0;
779
+ gsl_vector_set(f, i, (A*exp(-(xi - x0)*(xi - x0)/var/2.0) + y0 - yi)*wi);
780
+ }
781
+ return GSL_SUCCESS;
782
+ }
783
+
784
+ static int Gaussian_df(const gsl_vector *v, void *data, gsl_matrix *J)
785
+ {
786
+ double A, x0, var, xi, yy, wi;
787
+ size_t i;
788
+ struct fitting_xydata *xydata;
789
+ gsl_vector *x, *w;
790
+ xydata = (struct fitting_xydata*) data;
791
+ x = xydata->x;
792
+ w = xydata->w;
793
+ var = gsl_vector_get(v, 3);
794
+ x0 = gsl_vector_get(v, 2);
795
+ A = gsl_vector_get(v, 1);
796
+ for (i = 0; i < x->size; i++) {
797
+ xi = gsl_vector_get(x, i);
798
+ if (w) wi = gsl_vector_get(w, i);
799
+ else wi = 1.0;
800
+ yy = exp(-(xi - x0)*(xi - x0)/var/2.0);
801
+ gsl_matrix_set(J, i, 3, A*yy*(xi - x0)*(xi - x0)/2/var/var*wi);
802
+ gsl_matrix_set(J, i, 2, A*yy*(xi - x0)/var*wi);
803
+ gsl_matrix_set(J, i, 1, yy*wi);
804
+ gsl_matrix_set(J, i, 0, 1.0*wi);
805
+ }
806
+ return GSL_SUCCESS;
807
+ }
808
+
809
+ static int Gaussian_fdf(const gsl_vector *v, void *data,
810
+ gsl_vector *f, gsl_matrix *J)
811
+ {
812
+ Gaussian_f(v, data, f);
813
+ Gaussian_df(v, data, J);
814
+ return GSL_SUCCESS;
815
+ }
816
+
817
+ /* 2 Gaussian fit
818
+ y = y0 + A1 exp(-(x-x01/sigma1)^2) + A2 exp(-(x-x02/sigma2)^2)
819
+ v[0] = y0
820
+ v[1] = A1
821
+ v[2] = x01
822
+ v[3] = var1 = sigma1^2
823
+ v[4] = A2
824
+ v[5] = x02
825
+ v[6] = var2 = sigma2^2
826
+ */
827
+ static int Gaussian_2peaks_f(const gsl_vector *v, void *data, gsl_vector *f)
828
+ {
829
+ gsl_vector *x, *y, *w;
830
+ double y0, A1, x01, var1, A2, x02, var2, xi, yi, wi;
831
+ size_t i;
832
+ struct fitting_xydata *xydata;
833
+ xydata = (struct fitting_xydata*) data;
834
+ x = xydata->x;
835
+ y = xydata->y;
836
+ w = xydata->w;
837
+ y0 = gsl_vector_get(v, 0);
838
+ A1 = gsl_vector_get(v, 1);
839
+ x01 = gsl_vector_get(v, 2);
840
+ var1 = gsl_vector_get(v, 3);
841
+ A2 = gsl_vector_get(v, 4);
842
+ x02 = gsl_vector_get(v, 5);
843
+ var2 = gsl_vector_get(v, 6);
844
+ for (i = 0; i < x->size; i++) {
845
+ xi = gsl_vector_get(x, i);
846
+ yi = gsl_vector_get(y, i);
847
+ if (w) wi = gsl_vector_get(w, i);
848
+ else wi = 1.0;
849
+ gsl_vector_set(f, i, (A1*exp(-(xi - x01)*(xi - x01)/var1/2.0) + A2*exp(-(xi - x02)*(xi - x02)/var2/2.0) + y0 - yi)*wi);
850
+ }
851
+ return GSL_SUCCESS;
852
+ }
853
+
854
+ static int Gaussian_2peaks_df(const gsl_vector *v, void *data, gsl_matrix *J)
855
+ {
856
+ double A1, x01, var1, A2, x02, var2, xi, yy, wi;
857
+ size_t i;
858
+ struct fitting_xydata *xydata;
859
+ gsl_vector *x, *w;
860
+ xydata = (struct fitting_xydata*) data;
861
+ x = xydata->x;
862
+ w = xydata->w;
863
+ A1 = gsl_vector_get(v, 1);
864
+ x01 = gsl_vector_get(v, 2);
865
+ var1 = gsl_vector_get(v, 3);
866
+ A2 = gsl_vector_get(v, 4);
867
+ x02 = gsl_vector_get(v, 5);
868
+ var2 = gsl_vector_get(v, 6);
869
+ for (i = 0; i < x->size; i++) {
870
+ xi = gsl_vector_get(x, i);
871
+ if (w) wi = gsl_vector_get(w, i);
872
+ else wi = 1.0;
873
+ yy = exp(-(xi - x01)*(xi - x01)/var1/2.0);
874
+ gsl_matrix_set(J, i, 0, 1.0*wi);
875
+ gsl_matrix_set(J, i, 1, yy*wi);
876
+ gsl_matrix_set(J, i, 2, A1*yy*(xi - x01)/var1*wi);
877
+ gsl_matrix_set(J, i, 3, A1*yy*(xi - x01)*(xi - x01)/2/var1/var1*wi);
878
+
879
+ yy = exp(-(xi - x02)*(xi - x02)/var2/2.0);
880
+ gsl_matrix_set(J, i, 4, yy*wi);
881
+ gsl_matrix_set(J, i, 5, A2*yy*(xi - x02)/var2*wi);
882
+ gsl_matrix_set(J, i, 6, A2*yy*(xi - x02)*(xi - x02)/2/var2/var2*wi);
883
+ }
884
+ return GSL_SUCCESS;
885
+ }
886
+
887
+ static int Gaussian_2peaks_fdf(const gsl_vector *v, void *data,
888
+ gsl_vector *f, gsl_matrix *J)
889
+ {
890
+ Gaussian_2peaks_f(v, data, f);
891
+ Gaussian_2peaks_df(v, data, J);
892
+ return GSL_SUCCESS;
893
+ }
894
+
895
+ /* Exponential fit
896
+ y = y0 + A exp(-bx)
897
+ v[0] = y0
898
+ v[1] = A
899
+ v[2] = b
900
+ */
901
+ static int Exponential_f(const gsl_vector *v, void *data, gsl_vector *f)
902
+ {
903
+ gsl_vector *x, *y, *w;
904
+ double y0, A, b, xi, yi, wi;
905
+ size_t i;
906
+ struct fitting_xydata *xydata;
907
+ xydata = (struct fitting_xydata*) data;
908
+ x = xydata->x;
909
+ y = xydata->y;
910
+ w = xydata->w;
911
+ y0 = gsl_vector_get(v, 0);
912
+ A = gsl_vector_get(v, 1);
913
+ b = gsl_vector_get(v, 2);
914
+ for (i = 0; i < x->size; i++) {
915
+ xi = gsl_vector_get(x, i);
916
+ if (w) wi = gsl_vector_get(w, i);
917
+ else wi = 1.0;
918
+ yi = gsl_vector_get(y, i);
919
+ gsl_vector_set(f, i, (A*exp(-b*xi) + y0 - yi)*wi);
920
+ }
921
+ return GSL_SUCCESS;
922
+ }
923
+
924
+ static int Exponential_df(const gsl_vector *v, void *data, gsl_matrix *J)
925
+ {
926
+ double A, b, xi, yy, wi;
927
+ size_t i;
928
+ struct fitting_xydata *xydata;
929
+ gsl_vector *x, *w;
930
+ xydata = (struct fitting_xydata*) data;
931
+ x = xydata->x;
932
+ w = xydata->w;
933
+ A = gsl_vector_get(v, 1);
934
+ b = gsl_vector_get(v, 2);
935
+ for (i = 0; i < x->size; i++) {
936
+ xi = gsl_vector_get(x, i);
937
+ if (w) wi = gsl_vector_get(w, i);
938
+ else wi = 1.0;
939
+ yy = exp(-xi*b);
940
+ gsl_matrix_set(J, i, 0, 1.0*wi);
941
+ gsl_matrix_set(J, i, 1, yy*wi);
942
+ gsl_matrix_set(J, i, 2, -A*yy*xi*wi);
943
+ }
944
+ return GSL_SUCCESS;
945
+ }
946
+
947
+ static int Exponential_fdf(const gsl_vector *v, void *data,
948
+ gsl_vector *f, gsl_matrix *J)
949
+ {
950
+ Exponential_f(v, data, f);
951
+ Exponential_df(v, data, J);
952
+ return GSL_SUCCESS;
953
+ }
954
+
955
+
956
+ /* Double Exponential fit
957
+ y = y0 + A1 exp(-b1 x) + A2 exp(-b2 x)
958
+ v[0] = y0
959
+ v[1] = A1
960
+ v[2] = b1
961
+ v[3] = A2
962
+ v[4] = b2
963
+ */
964
+ static int DblExponential_f(const gsl_vector *v, void *data, gsl_vector *f)
965
+ {
966
+ gsl_vector *x, *y, *w;
967
+ double y0, A1, b1, A2, b2, xi, yi, wi;
968
+ size_t i;
969
+ struct fitting_xydata *xydata;
970
+ xydata = (struct fitting_xydata*) data;
971
+ x = xydata->x;
972
+ y = xydata->y;
973
+ w = xydata->w;
974
+ y0 = gsl_vector_get(v, 0);
975
+ A1 = gsl_vector_get(v, 1);
976
+ b1 = gsl_vector_get(v, 2);
977
+ A2 = gsl_vector_get(v, 3);
978
+ b2 = gsl_vector_get(v, 4);
979
+ for (i = 0; i < x->size; i++) {
980
+ xi = gsl_vector_get(x, i);
981
+ if (w) wi = gsl_vector_get(w, i);
982
+ else wi = 1.0;
983
+ yi = gsl_vector_get(y, i);
984
+ gsl_vector_set(f, i, (A1*exp(-b1*xi) + A2*exp(-b2*xi) + y0 - yi)*wi);
985
+ }
986
+ return GSL_SUCCESS;
987
+ }
988
+
989
+ static int DblExponential_df(const gsl_vector *v, void *data, gsl_matrix *J)
990
+ {
991
+ double A1, b1, A2, b2, xi, yy1, yy2, wi;
992
+ size_t i;
993
+ struct fitting_xydata *xydata;
994
+ gsl_vector *x, *w;
995
+ xydata = (struct fitting_xydata*) data;
996
+ x = xydata->x;
997
+ w = xydata->w;
998
+ A1 = gsl_vector_get(v, 1);
999
+ b1 = gsl_vector_get(v, 2);
1000
+ A2 = gsl_vector_get(v, 3);
1001
+ b2 = gsl_vector_get(v, 4);
1002
+ for (i = 0; i < x->size; i++) {
1003
+ xi = gsl_vector_get(x, i);
1004
+ if (w) wi = gsl_vector_get(w, i);
1005
+ else wi = 1.0;
1006
+ yy1 = exp(-xi*b1);
1007
+ yy2 = exp(-xi*b2);
1008
+ gsl_matrix_set(J, i, 0, 1.0*wi);
1009
+ gsl_matrix_set(J, i, 1, yy1*wi);
1010
+ gsl_matrix_set(J, i, 2, -A1*yy1*xi*wi);
1011
+ gsl_matrix_set(J, i, 3, yy2*wi);
1012
+ gsl_matrix_set(J, i, 4, -A2*yy2*xi*wi);
1013
+ }
1014
+ return GSL_SUCCESS;
1015
+ }
1016
+
1017
+ static int DblExponential_fdf(const gsl_vector *v, void *data,
1018
+ gsl_vector *f, gsl_matrix *J)
1019
+ {
1020
+ DblExponential_f(v, data, f);
1021
+ DblExponential_df(v, data, J);
1022
+ return GSL_SUCCESS;
1023
+ }
1024
+
1025
+ /* Lorentzian fit
1026
+ y = y0 + A/((x-x0)^2 + B)
1027
+ v[0] = y0
1028
+ v[1] = A
1029
+ v[2] = x0
1030
+ v[3] = B
1031
+ */
1032
+ static int Lorentzian_f(const gsl_vector *v, void *data, gsl_vector *f)
1033
+ {
1034
+ gsl_vector *x, *y, *w;
1035
+ double y0, A, x0, B, xi, yi, wi;
1036
+ size_t i;
1037
+ struct fitting_xydata *xydata;
1038
+ xydata = (struct fitting_xydata*) data;
1039
+ x = xydata->x;
1040
+ y = xydata->y;
1041
+ w = xydata->w;
1042
+ y0 = gsl_vector_get(v, 0);
1043
+ A = gsl_vector_get(v, 1);
1044
+ x0 = gsl_vector_get(v, 2);
1045
+ B = gsl_vector_get(v, 3);
1046
+ for (i = 0; i < x->size; i++) {
1047
+ xi = gsl_vector_get(x, i);
1048
+ if (w) wi = gsl_vector_get(w, i);
1049
+ else wi = 1.0;
1050
+ yi = gsl_vector_get(y, i);
1051
+ gsl_vector_set(f, i, (A/(gsl_pow_2(xi-x0)+B) + y0 - yi)*wi);
1052
+ }
1053
+ return GSL_SUCCESS;
1054
+ }
1055
+
1056
+ static int Lorentzian_df(const gsl_vector *v, void *data, gsl_matrix *J)
1057
+ {
1058
+ double A, B, x0, xi, yy, wi;
1059
+ size_t i;
1060
+ struct fitting_xydata *xydata;
1061
+ gsl_vector *x, *w;
1062
+ xydata = (struct fitting_xydata*) data;
1063
+ x = xydata->x;
1064
+ w = xydata->w;
1065
+ A = gsl_vector_get(v, 1);
1066
+ x0 = gsl_vector_get(v, 2);
1067
+ B = gsl_vector_get(v, 3);
1068
+ for (i = 0; i < x->size; i++) {
1069
+ xi = gsl_vector_get(x, i);
1070
+ if (w) wi = gsl_vector_get(w, i);
1071
+ else wi = 1.0;
1072
+ yy = gsl_pow_2(xi-x0)+B;
1073
+ gsl_matrix_set(J, i, 0, 1.0*wi);
1074
+ gsl_matrix_set(J, i, 1, 1.0/yy*wi);
1075
+ gsl_matrix_set(J, i, 2, 2.0*A*(xi-x0)/yy/yy*wi);
1076
+ gsl_matrix_set(J, i, 3, -A/yy/yy*wi);
1077
+ }
1078
+ return GSL_SUCCESS;
1079
+ }
1080
+
1081
+ static int Lorentzian_fdf(const gsl_vector *v, void *data,
1082
+ gsl_vector *f, gsl_matrix *J)
1083
+ {
1084
+ Lorentzian_f(v, data, f);
1085
+ Lorentzian_df(v, data, J);
1086
+ return GSL_SUCCESS;
1087
+ }
1088
+
1089
+ /* Sinusoldal fit
1090
+ y = y0 + A sin(fc x + phi)
1091
+ v[0] = y0
1092
+ v[1] = A
1093
+ v[2] = fc
1094
+ v[3] = phi
1095
+ */
1096
+ static int Sin_f(const gsl_vector *v, void *data, gsl_vector *f)
1097
+ {
1098
+ gsl_vector *x, *y, *w;
1099
+ double y0, A, fc, phi, xi, yi, wi;
1100
+ size_t i;
1101
+ struct fitting_xydata *xydata;
1102
+ xydata = (struct fitting_xydata*) data;
1103
+ x = xydata->x;
1104
+ y = xydata->y;
1105
+ w = xydata->w;
1106
+ y0 = gsl_vector_get(v, 0);
1107
+ A = gsl_vector_get(v, 1);
1108
+ fc = gsl_vector_get(v, 2);
1109
+ phi = gsl_vector_get(v, 3);
1110
+ for (i = 0; i < x->size; i++) {
1111
+ xi = gsl_vector_get(x, i);
1112
+ if (w) wi = gsl_vector_get(w, i);
1113
+ else wi = 1.0;
1114
+ yi = gsl_vector_get(y, i);
1115
+ gsl_vector_set(f, i, (A*sin(fc*xi+phi) + y0 - yi)*wi);
1116
+ }
1117
+ return GSL_SUCCESS;
1118
+ }
1119
+
1120
+ static int Sin_df(const gsl_vector *v, void *data, gsl_matrix *J)
1121
+ {
1122
+ double A, fc, phi, xi, ys, yc, wi;
1123
+ size_t i;
1124
+ struct fitting_xydata *xydata;
1125
+ gsl_vector *x, *w;
1126
+ xydata = (struct fitting_xydata*) data;
1127
+ x = xydata->x;
1128
+ w = xydata->w;
1129
+ A = gsl_vector_get(v, 1);
1130
+ fc = gsl_vector_get(v, 2);
1131
+ phi = gsl_vector_get(v, 3);
1132
+ for (i = 0; i < x->size; i++) {
1133
+ xi = gsl_vector_get(x, i);
1134
+ if (w) wi = gsl_vector_get(w, i);
1135
+ else wi = 1.0;
1136
+ ys = sin(fc*xi + phi);
1137
+ yc = cos(fc*xi + phi);
1138
+ gsl_matrix_set(J, i, 0, 1.0*wi);
1139
+ gsl_matrix_set(J, i, 1, ys*wi);
1140
+ gsl_matrix_set(J, i, 2, A*yc*xi*wi);
1141
+ gsl_matrix_set(J, i, 3, A*yc*wi);
1142
+ }
1143
+ return GSL_SUCCESS;
1144
+ }
1145
+
1146
+ static int Sin_fdf(const gsl_vector *v, void *data,
1147
+ gsl_vector *f, gsl_matrix *J)
1148
+ {
1149
+ Sin_f(v, data, f);
1150
+ Sin_df(v, data, J);
1151
+ return GSL_SUCCESS;
1152
+ }
1153
+
1154
+ /* Hill's equation fit
1155
+ y = y0 + (m - y0)/(1 + (xhalf/x)^r)
1156
+ v[0] = y0
1157
+ v[1] = m
1158
+ v[2] = xhalf
1159
+ v[3] = r
1160
+ */
1161
+ static int Hill_f(const gsl_vector *v, void *data, gsl_vector *f)
1162
+ {
1163
+ gsl_vector *x, *y, *w;
1164
+ double y0, m, xhalf, r, xi, yi, wi;
1165
+ size_t i;
1166
+ struct fitting_xydata *xydata;
1167
+ xydata = (struct fitting_xydata*) data;
1168
+ x = xydata->x;
1169
+ y = xydata->y;
1170
+ w = xydata->w;
1171
+ y0 = gsl_vector_get(v, 0);
1172
+ m = gsl_vector_get(v, 1);
1173
+ xhalf = gsl_vector_get(v, 2);
1174
+ r = gsl_vector_get(v, 3);
1175
+ for (i = 0; i < x->size; i++) {
1176
+ xi = gsl_vector_get(x, i);
1177
+ if (w) wi = gsl_vector_get(w, i);
1178
+ else wi = 1.0;
1179
+ yi = gsl_vector_get(y, i);
1180
+ gsl_vector_set(f, i, ((m-y0)/(1.0+pow(xhalf/xi, r)) + y0 - yi)*wi);
1181
+ }
1182
+ return GSL_SUCCESS;
1183
+ }
1184
+
1185
+ static int Hill_df(const gsl_vector *v, void *data, gsl_matrix *J)
1186
+ {
1187
+ double y0, m, xhalf, r, yy, xi, wi, a;
1188
+ size_t i;
1189
+ struct fitting_xydata *xydata;
1190
+ gsl_vector *x, *w;
1191
+ xydata = (struct fitting_xydata*) data;
1192
+ x = xydata->x;
1193
+ w = xydata->w;
1194
+ y0 = gsl_vector_get(v, 0);
1195
+ m = gsl_vector_get(v, 1);
1196
+ xhalf = gsl_vector_get(v, 2);
1197
+ r = gsl_vector_get(v, 3);
1198
+ for (i = 0; i < x->size; i++) {
1199
+ xi = gsl_vector_get(x, i);
1200
+ if (w) wi = gsl_vector_get(w, i);
1201
+ else wi = 1.0;
1202
+ a = pow(xhalf/xi, r);
1203
+ yy = (1.0 + a);
1204
+ gsl_matrix_set(J, i, 0, (1.0 - 1.0/yy)*wi);
1205
+ gsl_matrix_set(J, i, 1, 1.0/yy*wi);
1206
+ gsl_matrix_set(J, i, 2, -(m-y0)*r/xhalf*a/yy/yy*wi);
1207
+ gsl_matrix_set(J, i, 3, -(m-y0)/yy/yy*a*log(xhalf/xi)*wi);
1208
+ }
1209
+ return GSL_SUCCESS;
1210
+ }
1211
+
1212
+ static int Hill_fdf(const gsl_vector *v, void *data,
1213
+ gsl_vector *f, gsl_matrix *J)
1214
+ {
1215
+ Hill_f(v, data, f);
1216
+ Hill_df(v, data, J);
1217
+ return GSL_SUCCESS;
1218
+ }
1219
+
1220
+ /* Sigmoidal fit
1221
+ y = y0 + m/(1 + exp((x0-x)/r))
1222
+ v[0] = y0
1223
+ v[1] = m
1224
+ v[2] = x0
1225
+ v[3] = r
1226
+ */
1227
+ static int Sigmoid_f(const gsl_vector *v, void *data, gsl_vector *f)
1228
+ {
1229
+ gsl_vector *x, *y, *w;
1230
+ double y0, m, x0, r, xi, yi, wi;
1231
+ size_t i;
1232
+ struct fitting_xydata *xydata;
1233
+ xydata = (struct fitting_xydata*) data;
1234
+ x = xydata->x;
1235
+ y = xydata->y;
1236
+ w = xydata->w;
1237
+ y0 = gsl_vector_get(v, 0);
1238
+ m = gsl_vector_get(v, 1);
1239
+ x0 = gsl_vector_get(v, 2);
1240
+ r = gsl_vector_get(v, 3);
1241
+ for (i = 0; i < x->size; i++) {
1242
+ xi = gsl_vector_get(x, i);
1243
+ if (w) wi = gsl_vector_get(w, i);
1244
+ else wi = 1.0;
1245
+ yi = gsl_vector_get(y, i);
1246
+ gsl_vector_set(f, i, (m/(1.0+exp((x0-xi)/r)) + y0 - yi)*wi);
1247
+ }
1248
+ return GSL_SUCCESS;
1249
+ }
1250
+
1251
+ static int Sigmoid_df(const gsl_vector *v, void *data, gsl_matrix *J)
1252
+ {
1253
+ double m, x0, r, xi, wi, a, yy;
1254
+ size_t i;
1255
+ struct fitting_xydata *xydata;
1256
+ gsl_vector *x, *w;
1257
+ xydata = (struct fitting_xydata*) data;
1258
+ x = xydata->x;
1259
+ w = xydata->w;
1260
+ m = gsl_vector_get(v, 1);
1261
+ x0 = gsl_vector_get(v, 2);
1262
+ r = gsl_vector_get(v, 3);
1263
+ for (i = 0; i < x->size; i++) {
1264
+ xi = gsl_vector_get(x, i);
1265
+ if (w) wi = gsl_vector_get(w, i);
1266
+ else wi = 1.0;
1267
+ a = exp((x0 - xi)/r);
1268
+ yy = 1.0 + a;
1269
+ gsl_matrix_set(J, i, 0, wi);
1270
+ gsl_matrix_set(J, i, 1, 1.0/yy*wi);
1271
+ gsl_matrix_set(J, i, 2, -m*a/r/yy/yy*wi);
1272
+ gsl_matrix_set(J, i, 3, m*a*(x0-xi)/r/r/yy/yy*wi);
1273
+ }
1274
+ return GSL_SUCCESS;
1275
+ }
1276
+
1277
+ static int Sigmoid_fdf(const gsl_vector *v, void *data,
1278
+ gsl_vector *f, gsl_matrix *J)
1279
+ {
1280
+ Sigmoid_f(v, data, f);
1281
+ Sigmoid_df(v, data, J);
1282
+ return GSL_SUCCESS;
1283
+ }
1284
+
1285
+
1286
+ /* Power-law fit
1287
+ y = y0 + A x^r
1288
+ v[0] = y0
1289
+ v[1] = A
1290
+ v[2] = r
1291
+ */
1292
+ static int Power_f(const gsl_vector *v, void *data, gsl_vector *f)
1293
+ {
1294
+ gsl_vector *x, *y, *w;
1295
+ double y0, A, r, xi, yi, wi;
1296
+ size_t i;
1297
+ struct fitting_xydata *xydata;
1298
+ xydata = (struct fitting_xydata*) data;
1299
+ x = xydata->x;
1300
+ y = xydata->y;
1301
+ w = xydata->w;
1302
+ y0 = gsl_vector_get(v, 0);
1303
+ A = gsl_vector_get(v, 1);
1304
+ r = gsl_vector_get(v, 2);
1305
+ for (i = 0; i < x->size; i++) {
1306
+ xi = gsl_vector_get(x, i);
1307
+ if (w) wi = gsl_vector_get(w, i);
1308
+ else wi = 1.0;
1309
+ yi = gsl_vector_get(y, i);
1310
+ gsl_vector_set(f, i, (A*pow(xi, r) + y0 - yi)*wi);
1311
+ }
1312
+ return GSL_SUCCESS;
1313
+ }
1314
+
1315
+ static int Power_df(const gsl_vector *v, void *data, gsl_matrix *J)
1316
+ {
1317
+ double A, r, xi, wi, a;
1318
+ size_t i;
1319
+ struct fitting_xydata *xydata;
1320
+ gsl_vector *x, *w;
1321
+ xydata = (struct fitting_xydata*) data;
1322
+ x = xydata->x;
1323
+ w = xydata->w;
1324
+ A = gsl_vector_get(v, 1);
1325
+ r = gsl_vector_get(v, 2);
1326
+ for (i = 0; i < x->size; i++) {
1327
+ xi = gsl_vector_get(x, i);
1328
+ if (w) wi = gsl_vector_get(w, i);
1329
+ else wi = 1.0;
1330
+ a = pow(xi, r);
1331
+ gsl_matrix_set(J, i, 0, wi);
1332
+ gsl_matrix_set(J, i, 1, a*wi);
1333
+ gsl_matrix_set(J, i, 2, A*a*log(xi)*wi);
1334
+
1335
+ }
1336
+ return GSL_SUCCESS;
1337
+ }
1338
+
1339
+ static int Power_fdf(const gsl_vector *v, void *data,
1340
+ gsl_vector *f, gsl_matrix *J)
1341
+ {
1342
+ Power_f(v, data, f);
1343
+ Power_df(v, data, J);
1344
+ return GSL_SUCCESS;
1345
+ }
1346
+
1347
+
1348
+ /* Lognormal fit
1349
+ y = y0 + A exp[ -(log(x/x0)/width)^2 ]
1350
+ v[0] = y0
1351
+ v[1] = A
1352
+ v[2] = x0
1353
+ v[3] = width
1354
+ */
1355
+ static int Lognormal_f(const gsl_vector *v, void *data, gsl_vector *f)
1356
+ {
1357
+ gsl_vector *x, *y, *w;
1358
+ double y0, A, x0, width, xi, yi, wi;
1359
+ size_t i;
1360
+ struct fitting_xydata *xydata;
1361
+ xydata = (struct fitting_xydata*) data;
1362
+ x = xydata->x;
1363
+ y = xydata->y;
1364
+ w = xydata->w;
1365
+ y0 = gsl_vector_get(v, 0);
1366
+ A = gsl_vector_get(v, 1);
1367
+ x0 = gsl_vector_get(v, 2);
1368
+ width = gsl_vector_get(v, 3);
1369
+ for (i = 0; i < x->size; i++) {
1370
+ xi = gsl_vector_get(x, i);
1371
+ if (w) wi = gsl_vector_get(w, i);
1372
+ else wi = 1.0;
1373
+ yi = gsl_vector_get(y, i);
1374
+ gsl_vector_set(f, i, (A*exp(-gsl_pow_2(log(xi/x0)/width)) + y0 - yi)*wi);
1375
+ }
1376
+ return GSL_SUCCESS;
1377
+ }
1378
+
1379
+ static int Lognormal_df(const gsl_vector *v, void *data, gsl_matrix *J)
1380
+ {
1381
+ double A, x0, width, xi, wi, a, b;
1382
+ size_t i;
1383
+ struct fitting_xydata *xydata;
1384
+ gsl_vector *x, *w;
1385
+ xydata = (struct fitting_xydata*) data;
1386
+ x = xydata->x;
1387
+ w = xydata->w;
1388
+ A = gsl_vector_get(v, 1);
1389
+ x0 = gsl_vector_get(v, 2);
1390
+ width = gsl_vector_get(v, 3);
1391
+ for (i = 0; i < x->size; i++) {
1392
+ xi = gsl_vector_get(x, i);
1393
+ if (w) wi = gsl_vector_get(w, i);
1394
+ else wi = 1.0;
1395
+ a = log(xi/x0)/width;
1396
+ b = exp(-a*a);
1397
+ gsl_matrix_set(J, i, 0, wi);
1398
+ gsl_matrix_set(J, i, 1, b*wi);
1399
+ gsl_matrix_set(J, i, 2, 2.0*A*b*a*a*a/width/x0*wi);
1400
+ gsl_matrix_set(J, i, 3, 2.0*A*b*a*a*a*a/width*wi);
1401
+ }
1402
+ return GSL_SUCCESS;
1403
+ }
1404
+
1405
+ static int Lognormal_fdf(const gsl_vector *v, void *data,
1406
+ gsl_vector *f, gsl_matrix *J)
1407
+ {
1408
+ Lognormal_f(v, data, f);
1409
+ Lognormal_df(v, data, J);
1410
+ return GSL_SUCCESS;
1411
+ }
1412
+
1413
+ /* Rayleigh fit
1414
+ y = A exp(-x*x/2/var)
1415
+ v[0] = A
1416
+ v[1] = var = sigma^2
1417
+ */
1418
+ static int Rayleigh_f(const gsl_vector *v, void *data, gsl_vector *f)
1419
+ {
1420
+ gsl_vector *x, *y, *w;
1421
+ double A, var, xi, yi, wi;
1422
+ size_t i;
1423
+ struct fitting_xydata *xydata;
1424
+ xydata = (struct fitting_xydata*) data;
1425
+ x = xydata->x;
1426
+ y = xydata->y;
1427
+ w = xydata->w;
1428
+ var = gsl_vector_get(v, 1);
1429
+ A = gsl_vector_get(v, 0);
1430
+ for (i = 0; i < x->size; i++) {
1431
+ xi = gsl_vector_get(x, i);
1432
+ yi = gsl_vector_get(y, i);
1433
+ if (w) wi = gsl_vector_get(w, i);
1434
+ else wi = 1.0;
1435
+ gsl_vector_set(f, i, (A*xi*exp(-xi*xi/var/2.0) - yi)*wi);
1436
+ }
1437
+ return GSL_SUCCESS;
1438
+ }
1439
+
1440
+ static int Rayleigh_df(const gsl_vector *v, void *data, gsl_matrix *J)
1441
+ {
1442
+ double A, var, xi, yy, wi;
1443
+ size_t i;
1444
+ struct fitting_xydata *xydata;
1445
+ gsl_vector *x, *w;
1446
+ xydata = (struct fitting_xydata*) data;
1447
+ x = xydata->x;
1448
+ w = xydata->w;
1449
+ var = gsl_vector_get(v, 1);
1450
+ A = gsl_vector_get(v, 0);
1451
+ for (i = 0; i < x->size; i++) {
1452
+ xi = gsl_vector_get(x, i);
1453
+ if (w) wi = gsl_vector_get(w, i);
1454
+ else wi = 1.0;
1455
+ yy = xi*exp(-xi*xi/var/2.0);
1456
+ gsl_matrix_set(J, i, 1, A*yy*xi*xi/2/var/var*wi);
1457
+ gsl_matrix_set(J, i, 0, yy*wi);
1458
+ }
1459
+ return GSL_SUCCESS;
1460
+ }
1461
+
1462
+ static int Rayleigh_fdf(const gsl_vector *v, void *data,
1463
+ gsl_vector *f, gsl_matrix *J)
1464
+ {
1465
+ Rayleigh_f(v, data, f);
1466
+ Rayleigh_df(v, data, J);
1467
+ return GSL_SUCCESS;
1468
+ }
1469
+
1470
+ static void set_fittype(gsl_multifit_function_fdf *f, const char *fittype, size_t *p, gsl_vector **v, int *flag)
1471
+ {
1472
+ if (str_tail_grep(fittype, "aussian_2peaks") == 0) {
1473
+ f->f = Gaussian_2peaks_f;
1474
+ f->df = Gaussian_2peaks_df;
1475
+ f->fdf = Gaussian_2peaks_fdf;
1476
+ *p = 7;
1477
+ if (*v == NULL) {
1478
+ *v = gsl_vector_alloc(*p);
1479
+ gsl_vector_set(*v, 0, 0); /* y0 = 0 */
1480
+ gsl_vector_set(*v, 1, 1); /* A = 1 */
1481
+ gsl_vector_set(*v, 2, 0.0); /* x0 = 0 */
1482
+ gsl_vector_set(*v, 3, 1); /* initial values, var = 1 */
1483
+ gsl_vector_set(*v, 4, 1); /* A = 1 */
1484
+ gsl_vector_set(*v, 5, 1.0); /* x0 = 1 */
1485
+ gsl_vector_set(*v, 6, 1); /* initial values, var = 1 */
1486
+ *flag = 1;
1487
+ }
1488
+ } else if (str_head_grep(fittype, "gaus") == 0) {
1489
+ f->f = Gaussian_f;
1490
+ f->df = Gaussian_df;
1491
+ f->fdf = Gaussian_fdf;
1492
+ *p = 4;
1493
+ if (*v == NULL) {
1494
+ *v = gsl_vector_alloc(*p);
1495
+ gsl_vector_set(*v, 3, 1); /* initial values, var = 1 */
1496
+ gsl_vector_set(*v, 2, 0.0); /* x0 = 0 */
1497
+ gsl_vector_set(*v, 1, 1); /* A = 1 */
1498
+ gsl_vector_set(*v, 0, 0); /* y0 = 0 */
1499
+ *flag = 1;
1500
+ }
1501
+ } else if (str_head_grep(fittype, "exp") == 0) {
1502
+ f->f = Exponential_f;
1503
+ f->df = Exponential_df;
1504
+ f->fdf = Exponential_fdf;
1505
+ *p = 3;
1506
+ if (*v == NULL) {
1507
+ *v = gsl_vector_alloc(*p);
1508
+ gsl_vector_set(*v, 0, 0); /* y0 = 0 */
1509
+ gsl_vector_set(*v, 1, 1); /* A = 1 */
1510
+ gsl_vector_set(*v, 2, 1);
1511
+ *flag = 1;
1512
+ }
1513
+ } else if (str_head_grep(fittype, "rayleigh") == 0) {
1514
+ f->f = Rayleigh_f;
1515
+ f->df = Rayleigh_df;
1516
+ f->fdf = Rayleigh_fdf;
1517
+ *p = 2;
1518
+ if (*v == NULL) {
1519
+ *v = gsl_vector_alloc(*p);
1520
+ gsl_vector_set(*v, 0, 1); /* A = 1 */
1521
+ gsl_vector_set(*v, 1, 1); /* sigma = 1 */
1522
+ *flag = 1;
1523
+ }
1524
+ } else if (str_head_grep(fittype, "dblexp") == 0) {
1525
+ f->f = DblExponential_f;
1526
+ f->df = DblExponential_df;
1527
+ f->fdf = DblExponential_fdf;
1528
+ *p = 5;
1529
+ if (*v == NULL) {
1530
+ *v = gsl_vector_alloc(*p);
1531
+ gsl_vector_set(*v, 0, 0); /* y0 = 0 */
1532
+ gsl_vector_set(*v, 1, 1); /* A = 1 */
1533
+ gsl_vector_set(*v, 2, 1);
1534
+ gsl_vector_set(*v, 3, 1); /* A = 1 */
1535
+ gsl_vector_set(*v, 4, 1);
1536
+ *flag = 1;
1537
+ }
1538
+ } else if (str_head_grep(fittype, "lor") == 0) {
1539
+ f->f = Lorentzian_f;
1540
+ f->df = Lorentzian_df;
1541
+ f->fdf = Lorentzian_fdf;
1542
+ *p = 4;
1543
+ if (*v == NULL) {
1544
+ *v = gsl_vector_alloc(*p);
1545
+ gsl_vector_set(*v, 0, 0);
1546
+ gsl_vector_set(*v, 1, 1);
1547
+ gsl_vector_set(*v, 2, 0);
1548
+ gsl_vector_set(*v, 3, 1);
1549
+ *flag = 1;
1550
+ }
1551
+ } else if (str_head_grep(fittype, "sin") == 0) {
1552
+ f->f = Sin_f;
1553
+ f->df = Sin_df;
1554
+ f->fdf = Sin_fdf;
1555
+ *p = 4;
1556
+ if (*v == NULL) {
1557
+ *v = gsl_vector_alloc(*p);
1558
+ gsl_vector_set(*v, 0, 0);
1559
+ gsl_vector_set(*v, 1, 1);
1560
+ gsl_vector_set(*v, 2, 1);
1561
+ gsl_vector_set(*v, 3, 0);
1562
+ *flag = 1;
1563
+ }
1564
+ } else if (str_head_grep(fittype, "hill") == 0) {
1565
+ f->f = Hill_f;
1566
+ f->df = Hill_df;
1567
+ f->fdf = Hill_fdf;
1568
+ *p = 4;
1569
+ if (*v == NULL) {
1570
+ *v = gsl_vector_alloc(*p);
1571
+ gsl_vector_set(*v, 0, 0);
1572
+ gsl_vector_set(*v, 1, 1);
1573
+ gsl_vector_set(*v, 2, 1);
1574
+ gsl_vector_set(*v, 3, 1);
1575
+ *flag = 1;
1576
+ }
1577
+ } else if (str_head_grep(fittype, "sigmoid") == 0 || str_head_grep(fittype, "fermi") == 0) {
1578
+ f->f = Sigmoid_f;
1579
+ f->df = Sigmoid_df;
1580
+ f->fdf = Sigmoid_fdf;
1581
+ *p = 4;
1582
+ if (*v == NULL) {
1583
+ *v = gsl_vector_alloc(*p);
1584
+ gsl_vector_set(*v, 0, 0);
1585
+ gsl_vector_set(*v, 1, 1);
1586
+ gsl_vector_set(*v, 2, 0);
1587
+ gsl_vector_set(*v, 3, 1);
1588
+ *flag = 1;
1589
+ }
1590
+ } else if (str_head_grep(fittype, "power") == 0) {
1591
+ f->f = Power_f;
1592
+ f->df = Power_df;
1593
+ f->fdf = Power_fdf;
1594
+ *p = 3;
1595
+ if (*v == NULL) {
1596
+ *v = gsl_vector_alloc(*p);
1597
+ gsl_vector_set(*v, 0, 0);
1598
+ gsl_vector_set(*v, 1, 1);
1599
+ gsl_vector_set(*v, 2, -1);
1600
+ *flag = 1;
1601
+ }
1602
+ } else if (str_head_grep(fittype, "lognormal") == 0) {
1603
+ f->f = Lognormal_f;
1604
+ f->df = Lognormal_df;
1605
+ f->fdf = Lognormal_fdf;
1606
+ *p = 4;
1607
+ if (*v == NULL) {
1608
+ *v = gsl_vector_alloc(*p);
1609
+ gsl_vector_set(*v, 0, 0);
1610
+ gsl_vector_set(*v, 1, 1);
1611
+ gsl_vector_set(*v, 2, 1);
1612
+ gsl_vector_set(*v, 3, 1);
1613
+ *flag = 1;
1614
+ }
1615
+ } else {
1616
+ rb_raise(rb_eRuntimeError, "Unknown fit type (gaussian expected)");
1617
+ }
1618
+
1619
+ }
1620
+
1621
+ /* Singleton method */
1622
+ static VALUE rb_gsl_multifit_fit(int argc, VALUE *argv, VALUE klass)
1623
+ {
1624
+ const gsl_multifit_fdfsolver_type *T;
1625
+ gsl_multifit_fdfsolver *solver;
1626
+ int status;
1627
+ size_t iter = 0, i;
1628
+ size_t n, dof; /* # of data points */
1629
+ size_t p; /* # of fitting parameters */
1630
+ gsl_multifit_function_fdf f;
1631
+ gsl_matrix *covar = NULL;
1632
+ gsl_vector *v = NULL;
1633
+ gsl_vector *x, *y, *w = NULL;
1634
+ gsl_vector_view xx, yy, ww;
1635
+ gsl_vector *vout, *verr;
1636
+ int flag = 0;
1637
+ double chi2;
1638
+ char fittype[256];
1639
+ struct fitting_xydata xydata;
1640
+ if (argc < 3) rb_raise(rb_eArgError, "too few arguments");
1641
+ switch (TYPE(argv[argc-1])) {
1642
+ case T_ARRAY:
1643
+ v = get_vector(argv[argc-1]);
1644
+ flag = 1;
1645
+ argc--;
1646
+ break;
1647
+ case T_STRING:
1648
+ /* do nothing */
1649
+ break;
1650
+ default:
1651
+ Data_Get_Vector(argv[argc-1], v);
1652
+ flag = 0;
1653
+ argc--;
1654
+ break;
1655
+ }
1656
+ x = &xx.vector;
1657
+ y = &yy.vector;
1658
+ w = &ww.vector;
1659
+ switch (argc) {
1660
+ case 3:
1661
+ Data_Get_Vector(argv[0], x);
1662
+ Data_Get_Vector(argv[1], y);
1663
+ w = NULL;
1664
+ strcpy(fittype, STR2CSTR(argv[2]));
1665
+ break;
1666
+ case 4:
1667
+ Data_Get_Vector(argv[0], x);
1668
+ Data_Get_Vector(argv[1], w);
1669
+ Data_Get_Vector(argv[2], y);
1670
+ strcpy(fittype, STR2CSTR(argv[3]));
1671
+ break;
1672
+ default:
1673
+ rb_raise(rb_eArgError, "wrong number of arguments");
1674
+ break;
1675
+ }
1676
+
1677
+ xydata.x = x;
1678
+ xydata.y = y;
1679
+ xydata.w = w;
1680
+ n = x->size;
1681
+
1682
+ set_fittype(&f, fittype, &p, &v, &flag);
1683
+
1684
+ f.n = n;
1685
+ f.p = p;
1686
+ f.params = &xydata;
1687
+
1688
+ T = gsl_multifit_fdfsolver_lmsder;
1689
+ solver = gsl_multifit_fdfsolver_alloc(T, n, p);
1690
+ gsl_multifit_fdfsolver_set(solver, &f, v);
1691
+
1692
+ do {
1693
+ iter++;
1694
+ status = gsl_multifit_fdfsolver_iterate(solver);
1695
+ if (status) break;
1696
+ status = gsl_multifit_test_delta(solver->dx, solver->x, 1e-6, 1e-6);
1697
+ } while (status == GSL_CONTINUE);
1698
+ vout = gsl_vector_alloc(p);
1699
+ verr = gsl_vector_alloc(p);
1700
+ gsl_vector_memcpy(vout, solver->x);
1701
+ covar = gsl_matrix_alloc(p, p);
1702
+ chi2 = gsl_pow_2(gsl_blas_dnrm2(solver->f)); /* not reduced chi-square */
1703
+ dof = n - p;
1704
+ gsl_multifit_covar(solver->J, 0.0, covar);
1705
+ for (i = 0; i < p; i++)
1706
+ gsl_vector_set(verr, i, sqrt(chi2/dof*gsl_matrix_get(covar, i, i)));
1707
+ gsl_matrix_free(covar);
1708
+ if (flag == 1) gsl_vector_free(v);
1709
+ gsl_multifit_fdfsolver_free(solver);
1710
+ return rb_ary_new3(4,
1711
+ Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vout),
1712
+ Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, verr),
1713
+ rb_float_new(chi2), INT2FIX(dof));
1714
+ }
1715
+
1716
+ #ifdef GSL_1_8_LATER
1717
+ static VALUE rb_gsl_multifit_linear_est(VALUE module, VALUE xx, VALUE cc, VALUE ccov)
1718
+ {
1719
+ gsl_vector *x, *c;
1720
+ gsl_matrix *cov;
1721
+ double y, y_err;
1722
+
1723
+ Data_Get_Vector(xx, x);
1724
+ Data_Get_Vector(cc, c);
1725
+ Data_Get_Matrix(ccov, cov);
1726
+ gsl_multifit_linear_est(x, c, cov, &y, &y_err);
1727
+ return rb_ary_new3(2, rb_float_new(y), rb_float_new(y_err));
1728
+ }
1729
+ #endif
1730
+ #ifdef GSL_1_11_LATER
1731
+ static VALUE rb_gsl_multifit_linear_residuals(int argc, VALUE argv[], VALUE module)
1732
+ {
1733
+ gsl_vector *y, *c, *r;
1734
+ gsl_matrix *X;
1735
+ VALUE ret;
1736
+ switch (argc) {
1737
+ case 3:
1738
+ Data_Get_Matrix(argv[0], X);
1739
+ Data_Get_Vector(argv[1], y);
1740
+ Data_Get_Vector(argv[2], c);
1741
+ r = gsl_vector_alloc(y->size);
1742
+ ret = Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, r);
1743
+ break;
1744
+ case 4:
1745
+ Data_Get_Matrix(argv[0], X);
1746
+ Data_Get_Vector(argv[1], y);
1747
+ Data_Get_Vector(argv[2], c);
1748
+ Data_Get_Vector(argv[3], r);
1749
+ ret = argv[3];
1750
+ break;
1751
+ default:
1752
+ rb_raise(rb_eArgError, "Wrong number of arguments %d (3 or 4).\n", argc);
1753
+ }
1754
+ gsl_multifit_linear_residuals(X, y, c, r);
1755
+ return ret;
1756
+ }
1757
+
1758
+ #endif
1759
+
1760
+ void Init_gsl_multifit(VALUE module)
1761
+ {
1762
+ VALUE mgsl_multifit;
1763
+ VALUE cgsl_multifit_fdfsolver;
1764
+ VALUE cgsl_multifit_solver;
1765
+
1766
+ mgsl_multifit = rb_define_module_under(module, "MultiFit");
1767
+
1768
+ cgsl_multifit_workspace = rb_define_class_under(mgsl_multifit, "Workspace",
1769
+ cGSL_Object);
1770
+ rb_define_singleton_method(cgsl_multifit_workspace, "new",
1771
+ rb_gsl_multifit_workspace_new, 2);
1772
+ rb_define_singleton_method(cgsl_multifit_workspace, "alloc",
1773
+ rb_gsl_multifit_workspace_new, 2);
1774
+ rb_define_singleton_method(mgsl_multifit, "alloc",
1775
+ rb_gsl_multifit_workspace_new, 2);
1776
+ rb_define_module_function(mgsl_multifit, "linear", rb_gsl_multifit_linear, -1);
1777
+ rb_define_module_function(mgsl_multifit, "wlinear", rb_gsl_multifit_wlinear, -1);
1778
+
1779
+ cgsl_multifit_solver = rb_define_class_under(mgsl_multifit, "Solver", cGSL_Object);
1780
+ cgsl_multifit_fdfsolver = rb_define_class_under(mgsl_multifit, "FdfSolver",
1781
+ cgsl_multifit_solver);
1782
+ cgsl_multifit_function_fdf = rb_define_class_under(mgsl_multifit, "Function_fdf",
1783
+ cGSL_Object);
1784
+
1785
+ /*****/
1786
+
1787
+ rb_define_singleton_method(cgsl_multifit_fdfsolver, "new",
1788
+ rb_gsl_multifit_fdfsolver_new, -1);
1789
+ rb_define_singleton_method(cgsl_multifit_fdfsolver, "alloc",
1790
+ rb_gsl_multifit_fdfsolver_new, -1);
1791
+
1792
+ rb_define_singleton_method(cgsl_multifit_function_fdf, "new",
1793
+ rb_gsl_multifit_function_fdf_new, -1);
1794
+ rb_define_singleton_method(cgsl_multifit_function_fdf, "alloc",
1795
+ rb_gsl_multifit_function_fdf_new, -1);
1796
+
1797
+ /*****/
1798
+
1799
+ rb_define_method(cgsl_multifit_fdfsolver, "set", rb_gsl_multifit_fdfsolver_set, 2);
1800
+ rb_define_method(cgsl_multifit_fdfsolver, "name", rb_gsl_multifit_fdfsolver_name, 0);
1801
+ rb_define_method(cgsl_multifit_fdfsolver, "iterate", rb_gsl_multifit_fdfsolver_iterate, 0);
1802
+ rb_define_method(cgsl_multifit_fdfsolver, "position", rb_gsl_multifit_fdfsolver_position, 0);
1803
+ // rb_define_alias(cgsl_multifit_fdfsolver, "x", "position");
1804
+ rb_define_method(cgsl_multifit_fdfsolver, "print_state", rb_gsl_multifit_fdfsolver_print_state, 1);
1805
+ rb_define_method(cgsl_multifit_fdfsolver, "fdf", rb_gsl_multifit_fdfsolver_fdf, 0);
1806
+ rb_define_method(cgsl_multifit_fdfsolver, "test_delta", rb_gsl_multifit_fdfsolver_test_delta, 2);
1807
+ rb_define_method(cgsl_multifit_fdfsolver, "test_gradient", rb_gsl_multifit_fdfsolver_test_gradient, -1);
1808
+ rb_define_method(cgsl_multifit_fdfsolver, "covar", rb_gsl_multifit_fdfsolver_covar, -1);
1809
+ rb_define_method(cgsl_multifit_fdfsolver, "gradient", rb_gsl_multifit_fdfsolver_gradient, -1);
1810
+ rb_define_method(cgsl_multifit_fdfsolver, "x", rb_gsl_multifit_fdfsolver_x, 0);
1811
+ rb_define_method(cgsl_multifit_fdfsolver, "dx", rb_gsl_multifit_fdfsolver_dx, 0);
1812
+ rb_define_method(cgsl_multifit_fdfsolver, "f", rb_gsl_multifit_fdfsolver_f, 0);
1813
+ rb_define_method(cgsl_multifit_fdfsolver, "J", rb_gsl_multifit_fdfsolver_J, 0);
1814
+ rb_define_alias(cgsl_multifit_fdfsolver, "jac", "J");
1815
+ rb_define_alias(cgsl_multifit_fdfsolver, "jacobian", "J");
1816
+ rb_define_alias(cgsl_multifit_fdfsolver, "Jacobian", "J");
1817
+
1818
+ /*****/
1819
+ rb_define_module_function(mgsl_multifit, "polyfit", rb_gsl_multifit_polyfit, -1);
1820
+ rb_define_module_function(mgsl_multifit, "legfit", rb_gsl_multifit_legfit, -1);
1821
+ /*****/
1822
+
1823
+ rb_define_singleton_method(mgsl_multifit, "test_delta", rb_gsl_multifit_test_delta, 4);
1824
+ rb_define_singleton_method(mgsl_multifit, "test_gradient", rb_gsl_multifit_test_gradient, 2);
1825
+ rb_define_singleton_method(mgsl_multifit, "gradient", rb_gsl_multifit_gradient, -1);
1826
+ rb_define_singleton_method(mgsl_multifit, "covar", rb_gsl_multifit_covar, -1);
1827
+
1828
+ rb_gsl_multifit_define_const(cgsl_multifit_fdfsolver);
1829
+
1830
+ rb_define_method(cgsl_multifit_function_fdf, "set_procs",
1831
+ rb_gsl_multifit_function_fdf_set_procs, -1);
1832
+ rb_define_method(cgsl_multifit_function_fdf, "set_data",
1833
+ rb_gsl_multifit_function_fdf_set_data, -1);
1834
+ rb_define_method(cgsl_multifit_function_fdf, "params",
1835
+ rb_gsl_multifit_function_fdf_params, 0);
1836
+ rb_define_alias(cgsl_multifit_function_fdf, "param", "params");
1837
+
1838
+ rb_define_method(cgsl_multifit_function_fdf, "n",
1839
+ rb_gsl_multifit_function_fdf_n, 0);
1840
+ rb_define_method(cgsl_multifit_function_fdf, "set_n",
1841
+ rb_gsl_multifit_function_fdf_set_n, 1);
1842
+ rb_define_alias(cgsl_multifit_function_fdf, "n=", "set_n");
1843
+ rb_define_method(cgsl_multifit_function_fdf, "p",
1844
+ rb_gsl_multifit_function_fdf_p, 0);
1845
+ rb_define_alias(cgsl_multifit_function_fdf, "np", "p");
1846
+
1847
+ /*****/
1848
+ rb_define_singleton_method(cgsl_multifit_fdfsolver, "fit", rb_gsl_multifit_fit, -1);
1849
+
1850
+ /***/
1851
+ #ifdef GSL_1_8_LATER
1852
+ rb_define_module_function(mgsl_multifit, "linear_est", rb_gsl_multifit_linear_est, 3);
1853
+ rb_define_module_function(module, "multifit_linear_est", rb_gsl_multifit_linear_est, 3);
1854
+ #endif
1855
+ #ifdef GSL_1_11_LATER
1856
+ rb_define_module_function(mgsl_multifit, "linear_residuals", rb_gsl_multifit_linear_residuals, -1);
1857
+ rb_define_module_function(module, "multifit_linear_residuals", rb_gsl_multifit_linear_residuals, -1);
1858
+ #endif
1859
+
1860
+ #ifdef HAVE_NDLINEAR_GSL_MULTIFIT_NDLINEAR_H
1861
+ Init_ndlinear(mgsl_multifit);
1862
+ #endif
1863
+
1864
+ }
1865
+
1866
+ #ifdef CHECK_WORKSPACE
1867
+ #undef CHECK_WORKSPACE
1868
+ #endif
1869
+ #ifdef CHECK_MULTIFIT_FUNCTION_FDF
1870
+ #undef CHECK_MULTIFIT_FUNCTION_FDF
1871
+ #endif