rb-gsl 1.15.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/AUTHORS +6 -0
- data/COPYING +339 -0
- data/ChangeLog +567 -0
- data/README +32 -0
- data/Rakefile +99 -0
- data/THANKS +17 -0
- data/VERSION +1 -0
- data/examples/alf/alf.gp +15 -0
- data/examples/alf/alf.rb +32 -0
- data/examples/blas/blas.rb +13 -0
- data/examples/blas/dnrm2.rb +16 -0
- data/examples/blas/level1.rb +81 -0
- data/examples/blas/level2.rb +11 -0
- data/examples/blas/level3.rb +12 -0
- data/examples/bspline.rb +57 -0
- data/examples/cdf.rb +16 -0
- data/examples/cheb.rb +21 -0
- data/examples/combination.rb +23 -0
- data/examples/complex/RC-lpf.rb +47 -0
- data/examples/complex/add.rb +36 -0
- data/examples/complex/coerce.rb +14 -0
- data/examples/complex/complex.rb +25 -0
- data/examples/complex/fpmi.rb +70 -0
- data/examples/complex/functions.rb +77 -0
- data/examples/complex/michelson.rb +36 -0
- data/examples/complex/mul.rb +28 -0
- data/examples/complex/oscillator.rb +17 -0
- data/examples/complex/set.rb +37 -0
- data/examples/const/physconst.rb +151 -0
- data/examples/const/travel.rb +45 -0
- data/examples/deriv/demo.rb +13 -0
- data/examples/deriv/deriv.rb +36 -0
- data/examples/deriv/diff.rb +35 -0
- data/examples/dht.rb +42 -0
- data/examples/dirac.rb +56 -0
- data/examples/eigen/eigen.rb +34 -0
- data/examples/eigen/herm.rb +22 -0
- data/examples/eigen/narray.rb +9 -0
- data/examples/eigen/nonsymm.rb +37 -0
- data/examples/eigen/nonsymmv.rb +43 -0
- data/examples/eigen/qhoscillator.gp +35 -0
- data/examples/eigen/qhoscillator.rb +90 -0
- data/examples/eigen/vander.rb +41 -0
- data/examples/fft/fft.rb +17 -0
- data/examples/fft/fft2.rb +17 -0
- data/examples/fft/forward.rb +25 -0
- data/examples/fft/forward2.rb +26 -0
- data/examples/fft/radix2.rb +18 -0
- data/examples/fft/real-halfcomplex.rb +33 -0
- data/examples/fft/real-halfcomplex2.rb +30 -0
- data/examples/fft/realradix2.rb +19 -0
- data/examples/fft/sunspot.dat +256 -0
- data/examples/fft/sunspot.rb +16 -0
- data/examples/fit/expdata.dat +20 -0
- data/examples/fit/expfit.rb +31 -0
- data/examples/fit/gaussfit.rb +29 -0
- data/examples/fit/gaussian_2peaks.rb +34 -0
- data/examples/fit/hillfit.rb +40 -0
- data/examples/fit/lognormal.rb +26 -0
- data/examples/fit/lorentzfit.rb +22 -0
- data/examples/fit/multifit.rb +72 -0
- data/examples/fit/ndlinear.rb +133 -0
- data/examples/fit/nonlinearfit.rb +89 -0
- data/examples/fit/plot.gp +36 -0
- data/examples/fit/polyfit.rb +9 -0
- data/examples/fit/powerfit.rb +21 -0
- data/examples/fit/sigmoidfit.rb +40 -0
- data/examples/fit/sinfit.rb +22 -0
- data/examples/fit/wlinear.rb +46 -0
- data/examples/fresnel.rb +11 -0
- data/examples/function/function.rb +36 -0
- data/examples/function/log.rb +7 -0
- data/examples/function/min.rb +33 -0
- data/examples/function/sin.rb +10 -0
- data/examples/function/synchrotron.rb +18 -0
- data/examples/gallery/butterfly.rb +7 -0
- data/examples/gallery/cayley.rb +12 -0
- data/examples/gallery/cornu.rb +23 -0
- data/examples/gallery/eight.rb +11 -0
- data/examples/gallery/koch.rb +40 -0
- data/examples/gallery/lemniscate.rb +11 -0
- data/examples/gallery/polar.rb +11 -0
- data/examples/gallery/rgplot/cossin.rb +35 -0
- data/examples/gallery/rgplot/rgplot.replaced +0 -0
- data/examples/gallery/rgplot/roesller.rb +55 -0
- data/examples/gallery/roesller.rb +39 -0
- data/examples/gallery/scarabaeus.rb +14 -0
- data/examples/histogram/cauchy.rb +27 -0
- data/examples/histogram/cauchy.sh +2 -0
- data/examples/histogram/exponential.rb +19 -0
- data/examples/histogram/gauss.rb +16 -0
- data/examples/histogram/gsl-histogram.rb +40 -0
- data/examples/histogram/histo2d.rb +31 -0
- data/examples/histogram/histo3d.rb +34 -0
- data/examples/histogram/histogram-pdf.rb +27 -0
- data/examples/histogram/histogram.rb +26 -0
- data/examples/histogram/integral.rb +28 -0
- data/examples/histogram/poisson.rb +27 -0
- data/examples/histogram/power.rb +25 -0
- data/examples/histogram/rebin.rb +17 -0
- data/examples/histogram/smp.dat +5 -0
- data/examples/histogram/xexp.rb +21 -0
- data/examples/integration/ahmed.rb +21 -0
- data/examples/integration/cosmology.rb +75 -0
- data/examples/integration/friedmann.gp +16 -0
- data/examples/integration/friedmann.rb +35 -0
- data/examples/integration/gamma-zeta.rb +35 -0
- data/examples/integration/integration.rb +22 -0
- data/examples/integration/qag.rb +8 -0
- data/examples/integration/qag2.rb +14 -0
- data/examples/integration/qag3.rb +8 -0
- data/examples/integration/qagi.rb +28 -0
- data/examples/integration/qagi2.rb +49 -0
- data/examples/integration/qagiu.rb +29 -0
- data/examples/integration/qagp.rb +20 -0
- data/examples/integration/qags.rb +14 -0
- data/examples/integration/qawc.rb +18 -0
- data/examples/integration/qawf.rb +41 -0
- data/examples/integration/qawo.rb +29 -0
- data/examples/integration/qaws.rb +30 -0
- data/examples/integration/qng.rb +17 -0
- data/examples/interp/demo.gp +20 -0
- data/examples/interp/demo.rb +45 -0
- data/examples/interp/interp.rb +37 -0
- data/examples/interp/points +10 -0
- data/examples/interp/spline.rb +20 -0
- data/examples/jacobi/deriv.rb +40 -0
- data/examples/jacobi/integrate.rb +34 -0
- data/examples/jacobi/interp.rb +43 -0
- data/examples/jacobi/jacobi.rb +11 -0
- data/examples/linalg/HH.rb +15 -0
- data/examples/linalg/HH_narray.rb +13 -0
- data/examples/linalg/LQ_solve.rb +73 -0
- data/examples/linalg/LU.rb +84 -0
- data/examples/linalg/LU2.rb +31 -0
- data/examples/linalg/LU_narray.rb +24 -0
- data/examples/linalg/PTLQ.rb +47 -0
- data/examples/linalg/QR.rb +18 -0
- data/examples/linalg/QRPT.rb +47 -0
- data/examples/linalg/QR_solve.rb +78 -0
- data/examples/linalg/QR_solve_narray.rb +13 -0
- data/examples/linalg/SV.rb +16 -0
- data/examples/linalg/SV_narray.rb +12 -0
- data/examples/linalg/SV_solve.rb +49 -0
- data/examples/linalg/chol.rb +29 -0
- data/examples/linalg/chol_narray.rb +15 -0
- data/examples/linalg/complex.rb +57 -0
- data/examples/linalg/invert_narray.rb +10 -0
- data/examples/math/const.rb +67 -0
- data/examples/math/elementary.rb +35 -0
- data/examples/math/functions.rb +41 -0
- data/examples/math/inf_nan.rb +34 -0
- data/examples/math/minmax.rb +22 -0
- data/examples/math/power.rb +18 -0
- data/examples/math/test.rb +31 -0
- data/examples/matrix/a.dat +0 -0
- data/examples/matrix/add.rb +45 -0
- data/examples/matrix/b.dat +4 -0
- data/examples/matrix/cat.rb +31 -0
- data/examples/matrix/colvectors.rb +24 -0
- data/examples/matrix/complex.rb +41 -0
- data/examples/matrix/det.rb +29 -0
- data/examples/matrix/diagonal.rb +23 -0
- data/examples/matrix/get_all.rb +159 -0
- data/examples/matrix/hilbert.rb +31 -0
- data/examples/matrix/iterator.rb +19 -0
- data/examples/matrix/matrix.rb +57 -0
- data/examples/matrix/minmax.rb +53 -0
- data/examples/matrix/mul.rb +39 -0
- data/examples/matrix/rand.rb +20 -0
- data/examples/matrix/read.rb +29 -0
- data/examples/matrix/rowcol.rb +47 -0
- data/examples/matrix/set.rb +41 -0
- data/examples/matrix/set_all.rb +100 -0
- data/examples/matrix/view.rb +32 -0
- data/examples/matrix/view_all.rb +148 -0
- data/examples/matrix/write.rb +23 -0
- data/examples/min.rb +29 -0
- data/examples/monte/miser.rb +47 -0
- data/examples/monte/monte.rb +47 -0
- data/examples/monte/plain.rb +47 -0
- data/examples/monte/vegas.rb +46 -0
- data/examples/multimin/bundle.rb +66 -0
- data/examples/multimin/cqp.rb +109 -0
- data/examples/multimin/fdfminimizer.rb +40 -0
- data/examples/multimin/fminimizer.rb +41 -0
- data/examples/multiroot/demo.rb +36 -0
- data/examples/multiroot/fdfsolver.rb +50 -0
- data/examples/multiroot/fsolver.rb +33 -0
- data/examples/multiroot/fsolver2.rb +32 -0
- data/examples/multiroot/fsolver3.rb +26 -0
- data/examples/narray/histogram.rb +14 -0
- data/examples/narray/mandel.rb +27 -0
- data/examples/narray/narray.rb +28 -0
- data/examples/narray/narray2.rb +44 -0
- data/examples/narray/sf.rb +26 -0
- data/examples/ntuple/create.rb +17 -0
- data/examples/ntuple/project.rb +31 -0
- data/examples/odeiv/binarysystem.gp +23 -0
- data/examples/odeiv/binarysystem.rb +104 -0
- data/examples/odeiv/demo.gp +24 -0
- data/examples/odeiv/demo.rb +69 -0
- data/examples/odeiv/demo2.gp +26 -0
- data/examples/odeiv/duffing.rb +45 -0
- data/examples/odeiv/frei1.rb +109 -0
- data/examples/odeiv/frei2.rb +76 -0
- data/examples/odeiv/legendre.rb +52 -0
- data/examples/odeiv/odeiv.rb +32 -0
- data/examples/odeiv/odeiv2.rb +45 -0
- data/examples/odeiv/oscillator.rb +42 -0
- data/examples/odeiv/sedov.rb +97 -0
- data/examples/odeiv/whitedwarf.gp +40 -0
- data/examples/odeiv/whitedwarf.rb +158 -0
- data/examples/ool/conmin.rb +100 -0
- data/examples/ool/gencan.rb +99 -0
- data/examples/ool/pgrad.rb +100 -0
- data/examples/ool/spg.rb +100 -0
- data/examples/pdf/bernoulli.rb +5 -0
- data/examples/pdf/beta.rb +7 -0
- data/examples/pdf/binomiral.rb +10 -0
- data/examples/pdf/cauchy.rb +6 -0
- data/examples/pdf/chisq.rb +8 -0
- data/examples/pdf/exponential.rb +7 -0
- data/examples/pdf/exppow.rb +6 -0
- data/examples/pdf/fdist.rb +7 -0
- data/examples/pdf/flat.rb +7 -0
- data/examples/pdf/gamma.rb +8 -0
- data/examples/pdf/gauss-tail.rb +5 -0
- data/examples/pdf/gauss.rb +6 -0
- data/examples/pdf/geometric.rb +5 -0
- data/examples/pdf/gumbel.rb +6 -0
- data/examples/pdf/hypergeometric.rb +11 -0
- data/examples/pdf/landau.rb +5 -0
- data/examples/pdf/laplace.rb +7 -0
- data/examples/pdf/logarithmic.rb +5 -0
- data/examples/pdf/logistic.rb +6 -0
- data/examples/pdf/lognormal.rb +6 -0
- data/examples/pdf/neg-binomiral.rb +10 -0
- data/examples/pdf/pareto.rb +7 -0
- data/examples/pdf/pascal.rb +10 -0
- data/examples/pdf/poisson.rb +5 -0
- data/examples/pdf/rayleigh-tail.rb +6 -0
- data/examples/pdf/rayleigh.rb +6 -0
- data/examples/pdf/tdist.rb +6 -0
- data/examples/pdf/weibull.rb +8 -0
- data/examples/permutation/ex1.rb +22 -0
- data/examples/permutation/permutation.rb +16 -0
- data/examples/poly/bell.rb +6 -0
- data/examples/poly/bessel.rb +6 -0
- data/examples/poly/cheb.rb +6 -0
- data/examples/poly/cheb_II.rb +6 -0
- data/examples/poly/cubic.rb +9 -0
- data/examples/poly/demo.rb +20 -0
- data/examples/poly/eval.rb +28 -0
- data/examples/poly/eval_derivs.rb +14 -0
- data/examples/poly/fit.rb +21 -0
- data/examples/poly/hermite.rb +6 -0
- data/examples/poly/poly.rb +13 -0
- data/examples/poly/quadratic.rb +25 -0
- data/examples/random/diffusion.rb +34 -0
- data/examples/random/gaussian.rb +9 -0
- data/examples/random/generator.rb +27 -0
- data/examples/random/hdsobol.rb +21 -0
- data/examples/random/poisson.rb +9 -0
- data/examples/random/qrng.rb +19 -0
- data/examples/random/randomwalk.rb +37 -0
- data/examples/random/randomwalk2d.rb +19 -0
- data/examples/random/rayleigh.rb +36 -0
- data/examples/random/rng.rb +33 -0
- data/examples/random/rngextra.rb +14 -0
- data/examples/roots/bisection.rb +25 -0
- data/examples/roots/brent.rb +43 -0
- data/examples/roots/demo.rb +30 -0
- data/examples/roots/newton.rb +46 -0
- data/examples/roots/recombination.gp +12 -0
- data/examples/roots/recombination.rb +61 -0
- data/examples/roots/steffenson.rb +48 -0
- data/examples/sf/ShiChi.rb +6 -0
- data/examples/sf/SiCi.rb +6 -0
- data/examples/sf/airy_Ai.rb +8 -0
- data/examples/sf/airy_Bi.rb +8 -0
- data/examples/sf/bessel_IK.rb +12 -0
- data/examples/sf/bessel_JY.rb +13 -0
- data/examples/sf/beta_inc.rb +9 -0
- data/examples/sf/clausen.rb +6 -0
- data/examples/sf/dawson.rb +5 -0
- data/examples/sf/debye.rb +9 -0
- data/examples/sf/dilog.rb +6 -0
- data/examples/sf/ellint.rb +6 -0
- data/examples/sf/expint.rb +8 -0
- data/examples/sf/fermi.rb +10 -0
- data/examples/sf/gamma_inc_P.rb +9 -0
- data/examples/sf/gegenbauer.rb +8 -0
- data/examples/sf/hyperg.rb +7 -0
- data/examples/sf/laguerre.rb +19 -0
- data/examples/sf/lambertW.rb +5 -0
- data/examples/sf/legendre_P.rb +10 -0
- data/examples/sf/lngamma.rb +5 -0
- data/examples/sf/psi.rb +54 -0
- data/examples/sf/sphbessel.gp +27 -0
- data/examples/sf/sphbessel.rb +30 -0
- data/examples/sf/synchrotron.rb +5 -0
- data/examples/sf/transport.rb +10 -0
- data/examples/sf/zetam1.rb +5 -0
- data/examples/siman.rb +44 -0
- data/examples/sort/heapsort.rb +23 -0
- data/examples/sort/heapsort_vector_complex.rb +21 -0
- data/examples/sort/sort.rb +23 -0
- data/examples/sort/sort2.rb +16 -0
- data/examples/stats/mean.rb +17 -0
- data/examples/stats/statistics.rb +18 -0
- data/examples/stats/test.rb +9 -0
- data/examples/sum.rb +34 -0
- data/examples/tamu_anova.rb +18 -0
- data/examples/vector/a.dat +0 -0
- data/examples/vector/add.rb +56 -0
- data/examples/vector/b.dat +4 -0
- data/examples/vector/c.dat +3 -0
- data/examples/vector/collect.rb +26 -0
- data/examples/vector/compare.rb +28 -0
- data/examples/vector/complex.rb +51 -0
- data/examples/vector/complex_get_all.rb +85 -0
- data/examples/vector/complex_set_all.rb +131 -0
- data/examples/vector/complex_view_all.rb +77 -0
- data/examples/vector/connect.rb +22 -0
- data/examples/vector/decimate.rb +38 -0
- data/examples/vector/diff.rb +31 -0
- data/examples/vector/filescan.rb +17 -0
- data/examples/vector/floor.rb +23 -0
- data/examples/vector/get_all.rb +82 -0
- data/examples/vector/gnuplot.rb +38 -0
- data/examples/vector/graph.rb +28 -0
- data/examples/vector/histogram.rb +22 -0
- data/examples/vector/linspace.rb +24 -0
- data/examples/vector/log.rb +17 -0
- data/examples/vector/logic.rb +33 -0
- data/examples/vector/logspace.rb +25 -0
- data/examples/vector/minmax.rb +47 -0
- data/examples/vector/mul.rb +49 -0
- data/examples/vector/narray.rb +46 -0
- data/examples/vector/read.rb +29 -0
- data/examples/vector/set.rb +35 -0
- data/examples/vector/set_all.rb +121 -0
- data/examples/vector/smpv.dat +15 -0
- data/examples/vector/test.rb +43 -0
- data/examples/vector/test_gslblock.rb +58 -0
- data/examples/vector/vector.rb +110 -0
- data/examples/vector/view.rb +35 -0
- data/examples/vector/view_all.rb +73 -0
- data/examples/vector/where.rb +29 -0
- data/examples/vector/write.rb +24 -0
- data/examples/vector/zip.rb +34 -0
- data/examples/wavelet/ecg.dat +256 -0
- data/examples/wavelet/wavelet1.rb +50 -0
- data/ext/alf.c +206 -0
- data/ext/array.c +642 -0
- data/ext/array_complex.c +248 -0
- data/ext/blas.c +29 -0
- data/ext/blas1.c +734 -0
- data/ext/blas2.c +1093 -0
- data/ext/blas3.c +881 -0
- data/ext/block.c +44 -0
- data/ext/block_source.c +887 -0
- data/ext/bspline.c +130 -0
- data/ext/bundle.c +3 -0
- data/ext/cdf.c +754 -0
- data/ext/cheb.c +542 -0
- data/ext/combination.c +283 -0
- data/ext/common.c +325 -0
- data/ext/complex.c +1004 -0
- data/ext/const.c +673 -0
- data/ext/const_additional.c +120 -0
- data/ext/cqp.c +283 -0
- data/ext/deriv.c +195 -0
- data/ext/dht.c +361 -0
- data/ext/diff.c +166 -0
- data/ext/dirac.c +389 -0
- data/ext/eigen.c +2373 -0
- data/ext/error.c +193 -0
- data/ext/extconf.rb +303 -0
- data/ext/fcmp.c +66 -0
- data/ext/fft.c +1102 -0
- data/ext/fit.c +205 -0
- data/ext/fresnel.c +312 -0
- data/ext/function.c +524 -0
- data/ext/geometry.c +139 -0
- data/ext/graph.c +1640 -0
- data/ext/gsl.c +280 -0
- data/ext/gsl_narray.c +804 -0
- data/ext/histogram.c +1991 -0
- data/ext/histogram2d.c +1068 -0
- data/ext/histogram3d.c +884 -0
- data/ext/histogram3d_source.c +750 -0
- data/ext/histogram_find.c +101 -0
- data/ext/histogram_oper.c +159 -0
- data/ext/ieee.c +100 -0
- data/ext/integration.c +1179 -0
- data/ext/interp.c +512 -0
- data/ext/jacobi.c +739 -0
- data/ext/linalg.c +4042 -0
- data/ext/linalg_complex.c +739 -0
- data/ext/math.c +725 -0
- data/ext/matrix.c +39 -0
- data/ext/matrix_complex.c +1737 -0
- data/ext/matrix_double.c +560 -0
- data/ext/matrix_int.c +256 -0
- data/ext/matrix_source.c +2734 -0
- data/ext/min.c +250 -0
- data/ext/monte.c +992 -0
- data/ext/multifit.c +1871 -0
- data/ext/multimin.c +806 -0
- data/ext/multimin_fsdf.c +156 -0
- data/ext/multiroots.c +955 -0
- data/ext/multiset.c +214 -0
- data/ext/ndlinear.c +321 -0
- data/ext/nmf.c +171 -0
- data/ext/nmf_wrap.c +75 -0
- data/ext/ntuple.c +469 -0
- data/ext/odeiv.c +962 -0
- data/ext/ool.c +879 -0
- data/ext/oper_complex_source.c +253 -0
- data/ext/permutation.c +596 -0
- data/ext/poly.c +42 -0
- data/ext/poly2.c +265 -0
- data/ext/poly_source.c +1915 -0
- data/ext/qrng.c +171 -0
- data/ext/randist.c +1873 -0
- data/ext/rational.c +480 -0
- data/ext/rng.c +612 -0
- data/ext/root.c +408 -0
- data/ext/sf.c +1494 -0
- data/ext/sf_airy.c +200 -0
- data/ext/sf_bessel.c +871 -0
- data/ext/sf_clausen.c +28 -0
- data/ext/sf_coulomb.c +206 -0
- data/ext/sf_coupling.c +121 -0
- data/ext/sf_dawson.c +29 -0
- data/ext/sf_debye.c +157 -0
- data/ext/sf_dilog.c +43 -0
- data/ext/sf_elementary.c +46 -0
- data/ext/sf_ellint.c +206 -0
- data/ext/sf_elljac.c +30 -0
- data/ext/sf_erfc.c +93 -0
- data/ext/sf_exp.c +169 -0
- data/ext/sf_expint.c +211 -0
- data/ext/sf_fermi_dirac.c +148 -0
- data/ext/sf_gamma.c +347 -0
- data/ext/sf_gegenbauer.c +97 -0
- data/ext/sf_hyperg.c +203 -0
- data/ext/sf_laguerre.c +113 -0
- data/ext/sf_lambert.c +47 -0
- data/ext/sf_legendre.c +368 -0
- data/ext/sf_log.c +105 -0
- data/ext/sf_mathieu.c +238 -0
- data/ext/sf_power.c +47 -0
- data/ext/sf_psi.c +98 -0
- data/ext/sf_synchrotron.c +48 -0
- data/ext/sf_transport.c +76 -0
- data/ext/sf_trigonometric.c +210 -0
- data/ext/sf_zeta.c +119 -0
- data/ext/signal.c +308 -0
- data/ext/siman.c +717 -0
- data/ext/sort.c +208 -0
- data/ext/spline.c +395 -0
- data/ext/stats.c +800 -0
- data/ext/sum.c +168 -0
- data/ext/tamu_anova.c +56 -0
- data/ext/tensor.c +38 -0
- data/ext/tensor_source.c +1123 -0
- data/ext/vector.c +38 -0
- data/ext/vector_complex.c +2246 -0
- data/ext/vector_double.c +1438 -0
- data/ext/vector_int.c +204 -0
- data/ext/vector_source.c +3336 -0
- data/ext/wavelet.c +945 -0
- data/include/rb_gsl.h +158 -0
- data/include/rb_gsl_array.h +238 -0
- data/include/rb_gsl_cheb.h +21 -0
- data/include/rb_gsl_common.h +348 -0
- data/include/rb_gsl_complex.h +25 -0
- data/include/rb_gsl_config.h +62 -0
- data/include/rb_gsl_const.h +29 -0
- data/include/rb_gsl_dirac.h +13 -0
- data/include/rb_gsl_eigen.h +17 -0
- data/include/rb_gsl_fft.h +62 -0
- data/include/rb_gsl_fit.h +25 -0
- data/include/rb_gsl_function.h +27 -0
- data/include/rb_gsl_graph.h +70 -0
- data/include/rb_gsl_histogram.h +63 -0
- data/include/rb_gsl_histogram3d.h +97 -0
- data/include/rb_gsl_integration.h +17 -0
- data/include/rb_gsl_interp.h +46 -0
- data/include/rb_gsl_linalg.h +25 -0
- data/include/rb_gsl_math.h +26 -0
- data/include/rb_gsl_odeiv.h +21 -0
- data/include/rb_gsl_poly.h +71 -0
- data/include/rb_gsl_rational.h +37 -0
- data/include/rb_gsl_rng.h +21 -0
- data/include/rb_gsl_root.h +22 -0
- data/include/rb_gsl_sf.h +119 -0
- data/include/rb_gsl_statistics.h +17 -0
- data/include/rb_gsl_tensor.h +45 -0
- data/include/rb_gsl_with_narray.h +29 -0
- data/include/templates_off.h +87 -0
- data/include/templates_on.h +241 -0
- data/lib/gsl.rb +3 -0
- data/lib/gsl/gnuplot.rb +41 -0
- data/lib/gsl/oper.rb +68 -0
- data/lib/ool.rb +22 -0
- data/lib/ool/conmin.rb +30 -0
- data/lib/rbgsl.rb +3 -0
- data/rdoc/alf.rdoc +77 -0
- data/rdoc/blas.rdoc +269 -0
- data/rdoc/bspline.rdoc +42 -0
- data/rdoc/changes.rdoc +164 -0
- data/rdoc/cheb.rdoc +99 -0
- data/rdoc/cholesky_complex.rdoc +46 -0
- data/rdoc/combi.rdoc +125 -0
- data/rdoc/complex.rdoc +210 -0
- data/rdoc/const.rdoc +546 -0
- data/rdoc/dht.rdoc +122 -0
- data/rdoc/diff.rdoc +133 -0
- data/rdoc/ehandling.rdoc +50 -0
- data/rdoc/eigen.rdoc +401 -0
- data/rdoc/fft.rdoc +535 -0
- data/rdoc/fit.rdoc +284 -0
- data/rdoc/function.rdoc +94 -0
- data/rdoc/graph.rdoc +137 -0
- data/rdoc/hist.rdoc +409 -0
- data/rdoc/hist2d.rdoc +279 -0
- data/rdoc/hist3d.rdoc +112 -0
- data/rdoc/index.rdoc +62 -0
- data/rdoc/integration.rdoc +398 -0
- data/rdoc/interp.rdoc +231 -0
- data/rdoc/intro.rdoc +27 -0
- data/rdoc/linalg.rdoc +681 -0
- data/rdoc/linalg_complex.rdoc +88 -0
- data/rdoc/math.rdoc +276 -0
- data/rdoc/matrix.rdoc +1093 -0
- data/rdoc/min.rdoc +189 -0
- data/rdoc/monte.rdoc +234 -0
- data/rdoc/multimin.rdoc +312 -0
- data/rdoc/multiroot.rdoc +293 -0
- data/rdoc/narray.rdoc +177 -0
- data/rdoc/ndlinear.rdoc +250 -0
- data/rdoc/nonlinearfit.rdoc +348 -0
- data/rdoc/ntuple.rdoc +88 -0
- data/rdoc/odeiv.rdoc +378 -0
- data/rdoc/perm.rdoc +221 -0
- data/rdoc/poly.rdoc +335 -0
- data/rdoc/qrng.rdoc +90 -0
- data/rdoc/randist.rdoc +233 -0
- data/rdoc/ref.rdoc +93 -0
- data/rdoc/rng.rdoc +203 -0
- data/rdoc/rngextra.rdoc +11 -0
- data/rdoc/roots.rdoc +305 -0
- data/rdoc/screenshot.rdoc +40 -0
- data/rdoc/sf.rdoc +1622 -0
- data/rdoc/siman.rdoc +89 -0
- data/rdoc/sort.rdoc +94 -0
- data/rdoc/start.rdoc +16 -0
- data/rdoc/stats.rdoc +219 -0
- data/rdoc/sum.rdoc +65 -0
- data/rdoc/tensor.rdoc +251 -0
- data/rdoc/tut.rdoc +5 -0
- data/rdoc/use.rdoc +177 -0
- data/rdoc/vector.rdoc +1243 -0
- data/rdoc/vector_complex.rdoc +347 -0
- data/rdoc/wavelet.rdoc +218 -0
- data/setup.rb +1585 -0
- data/tests/blas/amax.rb +14 -0
- data/tests/blas/asum.rb +16 -0
- data/tests/blas/axpy.rb +25 -0
- data/tests/blas/copy.rb +23 -0
- data/tests/blas/dot.rb +23 -0
- data/tests/bspline.rb +53 -0
- data/tests/cdf.rb +1388 -0
- data/tests/cheb.rb +112 -0
- data/tests/combination.rb +123 -0
- data/tests/complex.rb +17 -0
- data/tests/const.rb +24 -0
- data/tests/deriv.rb +85 -0
- data/tests/dht/dht1.rb +17 -0
- data/tests/dht/dht2.rb +23 -0
- data/tests/dht/dht3.rb +23 -0
- data/tests/dht/dht4.rb +23 -0
- data/tests/diff.rb +78 -0
- data/tests/eigen/eigen.rb +220 -0
- data/tests/eigen/gen.rb +105 -0
- data/tests/eigen/genherm.rb +66 -0
- data/tests/eigen/gensymm.rb +68 -0
- data/tests/eigen/nonsymm.rb +53 -0
- data/tests/eigen/nonsymmv.rb +53 -0
- data/tests/eigen/symm-herm.rb +74 -0
- data/tests/err.rb +58 -0
- data/tests/fit.rb +124 -0
- data/tests/gsl_test.rb +118 -0
- data/tests/gsl_test2.rb +110 -0
- data/tests/histo.rb +12 -0
- data/tests/integration/integration1.rb +72 -0
- data/tests/integration/integration2.rb +71 -0
- data/tests/integration/integration3.rb +71 -0
- data/tests/integration/integration4.rb +71 -0
- data/tests/interp.rb +45 -0
- data/tests/linalg/HH.rb +64 -0
- data/tests/linalg/LU.rb +47 -0
- data/tests/linalg/QR.rb +77 -0
- data/tests/linalg/SV.rb +24 -0
- data/tests/linalg/TDN.rb +116 -0
- data/tests/linalg/TDS.rb +122 -0
- data/tests/linalg/bidiag.rb +73 -0
- data/tests/linalg/cholesky.rb +20 -0
- data/tests/linalg/linalg.rb +158 -0
- data/tests/matrix/matrix_complex_test.rb +36 -0
- data/tests/matrix/matrix_nmf_test.rb +39 -0
- data/tests/matrix/matrix_test.rb +48 -0
- data/tests/min.rb +99 -0
- data/tests/monte/miser.rb +31 -0
- data/tests/monte/vegas.rb +45 -0
- data/tests/multifit/test_2dgauss.rb +112 -0
- data/tests/multifit/test_brown.rb +90 -0
- data/tests/multifit/test_enso.rb +246 -0
- data/tests/multifit/test_filip.rb +155 -0
- data/tests/multifit/test_gauss.rb +97 -0
- data/tests/multifit/test_longley.rb +110 -0
- data/tests/multifit/test_multifit.rb +52 -0
- data/tests/multimin.rb +139 -0
- data/tests/multiroot.rb +131 -0
- data/tests/multiset.rb +52 -0
- data/tests/narray/blas_dnrm2.rb +20 -0
- data/tests/odeiv.rb +353 -0
- data/tests/poly/poly.rb +290 -0
- data/tests/poly/special.rb +65 -0
- data/tests/qrng.rb +131 -0
- data/tests/quartic.rb +29 -0
- data/tests/randist.rb +134 -0
- data/tests/rng.rb +305 -0
- data/tests/roots.rb +76 -0
- data/tests/run-test.sh +17 -0
- data/tests/sf/gsl_test_sf.rb +249 -0
- data/tests/sf/test_airy.rb +83 -0
- data/tests/sf/test_bessel.rb +306 -0
- data/tests/sf/test_coulomb.rb +17 -0
- data/tests/sf/test_dilog.rb +25 -0
- data/tests/sf/test_gamma.rb +209 -0
- data/tests/sf/test_hyperg.rb +356 -0
- data/tests/sf/test_legendre.rb +227 -0
- data/tests/sf/test_mathieu.rb +59 -0
- data/tests/sf/test_mode.rb +19 -0
- data/tests/sf/test_sf.rb +839 -0
- data/tests/stats.rb +174 -0
- data/tests/stats_mt.rb +16 -0
- data/tests/sum.rb +98 -0
- data/tests/sys.rb +323 -0
- data/tests/tensor.rb +419 -0
- data/tests/vector/vector_complex_test.rb +101 -0
- data/tests/vector/vector_test.rb +141 -0
- data/tests/wavelet.rb +142 -0
- metadata +789 -0
data/ext/histogram.c
ADDED
@@ -0,0 +1,1991 @@
|
|
1
|
+
/*
|
2
|
+
histogram.c
|
3
|
+
Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
|
4
|
+
(C) Copyright 2001-2006 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
|
+
|
12
|
+
#include "rb_gsl_config.h"
|
13
|
+
#include "rb_gsl_histogram.h"
|
14
|
+
#include "rb_gsl_array.h"
|
15
|
+
#include <gsl/gsl_fit.h>
|
16
|
+
#include <gsl/gsl_multifit_nlin.h>
|
17
|
+
#include <gsl/gsl_blas.h>
|
18
|
+
|
19
|
+
VALUE cgsl_histogram;
|
20
|
+
VALUE cgsl_histogram_range;
|
21
|
+
VALUE cgsl_histogram_bin;
|
22
|
+
static VALUE cgsl_histogram_integ;
|
23
|
+
|
24
|
+
static VALUE rb_gsl_histogram_alloc_from_file(VALUE klass, VALUE name);
|
25
|
+
#ifdef GSL_0_9_4_LATER
|
26
|
+
static VALUE rb_gsl_histogram_alloc(int argc, VALUE *argv, VALUE klass)
|
27
|
+
{
|
28
|
+
gsl_histogram *h = NULL;
|
29
|
+
gsl_vector *v;
|
30
|
+
double min, max;
|
31
|
+
size_t n, size;
|
32
|
+
switch (argc) {
|
33
|
+
case 1:
|
34
|
+
switch (TYPE(argv[0])) {
|
35
|
+
case T_FIXNUM:
|
36
|
+
n = FIX2INT(argv[0]);
|
37
|
+
h = gsl_histogram_alloc(n);
|
38
|
+
break;
|
39
|
+
case T_ARRAY:
|
40
|
+
v = make_cvector_from_rarray(argv[0]);
|
41
|
+
h = gsl_histogram_alloc(v->size-1);
|
42
|
+
gsl_histogram_set_ranges(h, v->data, v->size);
|
43
|
+
gsl_vector_free(v);
|
44
|
+
break;
|
45
|
+
case T_STRING:
|
46
|
+
return rb_gsl_histogram_alloc_from_file(klass, argv[0]);
|
47
|
+
break;
|
48
|
+
default:
|
49
|
+
CHECK_VECTOR(argv[0]);
|
50
|
+
Data_Get_Struct(argv[0], gsl_vector, v);
|
51
|
+
h = gsl_histogram_alloc(v->size-1);
|
52
|
+
gsl_histogram_set_ranges(h, v->data, v->size);
|
53
|
+
break;
|
54
|
+
}
|
55
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
|
56
|
+
break;
|
57
|
+
case 3:
|
58
|
+
CHECK_FIXNUM(argv[0]);
|
59
|
+
Need_Float(argv[1]); Need_Float(argv[2]);
|
60
|
+
n = FIX2INT(argv[0]);
|
61
|
+
min = NUM2DBL(argv[1]);
|
62
|
+
max = NUM2DBL(argv[2]);
|
63
|
+
h = gsl_histogram_calloc(n);
|
64
|
+
gsl_histogram_set_ranges_uniform(h, min, max);
|
65
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
|
66
|
+
break;
|
67
|
+
case 2:
|
68
|
+
switch (TYPE(argv[0])) {
|
69
|
+
case T_FIXNUM:
|
70
|
+
CHECK_FIXNUM(argv[0]);
|
71
|
+
if (TYPE(argv[1]) != T_ARRAY) {
|
72
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (Array expected)",
|
73
|
+
rb_class2name(CLASS_OF(argv[1])));
|
74
|
+
}
|
75
|
+
n = FIX2INT(argv[0]);
|
76
|
+
min = NUM2DBL(rb_ary_entry(argv[1], 0));
|
77
|
+
max = NUM2DBL(rb_ary_entry(argv[1], 1));
|
78
|
+
h = gsl_histogram_calloc(n);
|
79
|
+
gsl_histogram_set_ranges_uniform(h, min, max);
|
80
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
|
81
|
+
break;
|
82
|
+
case T_ARRAY:
|
83
|
+
CHECK_FIXNUM(argv[1]);
|
84
|
+
v = make_cvector_from_rarray(argv[0]);
|
85
|
+
size = FIX2INT(argv[1]);
|
86
|
+
h = gsl_histogram_calloc(size-1);
|
87
|
+
gsl_histogram_set_ranges(h, v->data, size);
|
88
|
+
gsl_vector_free(v);
|
89
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
|
90
|
+
break;
|
91
|
+
default:
|
92
|
+
CHECK_VECTOR(argv[0]);
|
93
|
+
CHECK_FIXNUM(argv[1]);
|
94
|
+
Data_Get_Struct(argv[0], gsl_vector, v);
|
95
|
+
size = FIX2INT(argv[1]);
|
96
|
+
h = gsl_histogram_calloc(size-1);
|
97
|
+
gsl_histogram_set_ranges(h, v->data, size);
|
98
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
|
99
|
+
break;
|
100
|
+
}
|
101
|
+
break;
|
102
|
+
default:
|
103
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1, 2, 3)", argc);
|
104
|
+
break;
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
static VALUE rb_gsl_histogram_alloc_from_file(VALUE klass, VALUE name)
|
110
|
+
{
|
111
|
+
char filename[1024], buf[1024];
|
112
|
+
gsl_histogram *h;
|
113
|
+
int nn;
|
114
|
+
size_t n, i;
|
115
|
+
FILE *fp = NULL;
|
116
|
+
double upper;
|
117
|
+
strcpy(filename, STR2CHARPTR(name));
|
118
|
+
sprintf(buf, "wc %s", filename);
|
119
|
+
fp = popen(buf, "r");
|
120
|
+
if (fp == NULL) rb_raise(rb_eIOError, "popen failed.");
|
121
|
+
fgets(buf, 1024, fp);
|
122
|
+
pclose(fp);
|
123
|
+
sscanf(buf, "%d", &nn);
|
124
|
+
n = (size_t) nn; /* vector length */
|
125
|
+
fp = fopen(filename, "r");
|
126
|
+
if (fp == NULL) rb_raise(rb_eIOError, "cannot open file %s.", filename);
|
127
|
+
h = gsl_histogram_alloc(n);
|
128
|
+
i = 0;
|
129
|
+
while (fgets(buf, 1024, fp)) {
|
130
|
+
sscanf(buf, "%lg %lg %lg", h->range+i, &upper, h->bin+i);
|
131
|
+
i++;
|
132
|
+
}
|
133
|
+
h->range[n] = upper;
|
134
|
+
fclose(fp);
|
135
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
/* initialization + set uniform ranges (equal spacing from min to max) */
|
140
|
+
static VALUE rb_gsl_histogram_alloc_uniform(int argc, VALUE *argv, VALUE klass)
|
141
|
+
{
|
142
|
+
gsl_histogram *h = NULL;
|
143
|
+
double min, max, tmp;
|
144
|
+
size_t n;
|
145
|
+
switch (argc) {
|
146
|
+
case 3:
|
147
|
+
CHECK_FIXNUM(argv[0]);
|
148
|
+
Need_Float(argv[1]); Need_Float(argv[2]);
|
149
|
+
n = FIX2INT(argv[0]);
|
150
|
+
min = NUM2DBL(argv[1]);
|
151
|
+
max = NUM2DBL(argv[2]);
|
152
|
+
break;
|
153
|
+
case 2:
|
154
|
+
CHECK_FIXNUM(argv[0]);
|
155
|
+
n = FIX2INT(argv[0]);
|
156
|
+
Check_Type(argv[1], T_ARRAY);
|
157
|
+
min = NUM2DBL(rb_ary_entry(argv[1], 0));
|
158
|
+
max = NUM2DBL(rb_ary_entry(argv[1], 1));
|
159
|
+
break;
|
160
|
+
default:
|
161
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
|
162
|
+
break;
|
163
|
+
}
|
164
|
+
if (min > max) {
|
165
|
+
tmp = min;
|
166
|
+
min = max;
|
167
|
+
max = tmp;
|
168
|
+
}
|
169
|
+
h = gsl_histogram_alloc(n);
|
170
|
+
gsl_histogram_set_ranges_uniform(h, min, max);
|
171
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
|
172
|
+
}
|
173
|
+
|
174
|
+
/* initialization + set ranges with a given spacing from min to max */
|
175
|
+
static VALUE rb_gsl_histogram_alloc_with_min_max_step(VALUE klass, VALUE vmin,
|
176
|
+
VALUE vmax, VALUE ss)
|
177
|
+
{
|
178
|
+
gsl_histogram *h = NULL;
|
179
|
+
gsl_vector *v = NULL;
|
180
|
+
double min, max, tmp, step;
|
181
|
+
size_t i, n;
|
182
|
+
Need_Float(vmin); Need_Float(vmax); Need_Float(ss);
|
183
|
+
min = NUM2DBL(vmin);
|
184
|
+
max = NUM2DBL(vmax);
|
185
|
+
step = NUM2DBL(ss);
|
186
|
+
if (min > max) {
|
187
|
+
tmp = min;
|
188
|
+
min = max;
|
189
|
+
max = tmp;
|
190
|
+
}
|
191
|
+
n = (int) ((max - min)/step);
|
192
|
+
h = gsl_histogram_alloc(n);
|
193
|
+
v = gsl_vector_alloc(n + 1);
|
194
|
+
for (i = 0; i < n + 1; i++) gsl_vector_set(v, i, min + step*i);
|
195
|
+
gsl_histogram_set_ranges(h, v->data, v->size);
|
196
|
+
gsl_vector_free(v);
|
197
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
|
198
|
+
}
|
199
|
+
#endif
|
200
|
+
|
201
|
+
static VALUE rb_gsl_histogram_calloc(VALUE klass, VALUE nn)
|
202
|
+
{
|
203
|
+
gsl_histogram *h = NULL;
|
204
|
+
CHECK_FIXNUM(nn);
|
205
|
+
h = gsl_histogram_calloc(FIX2INT(nn));
|
206
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
|
207
|
+
}
|
208
|
+
|
209
|
+
static VALUE rb_gsl_histogram_calloc_range(int argc, VALUE *argv, VALUE klass)
|
210
|
+
{
|
211
|
+
gsl_histogram *h = NULL;
|
212
|
+
gsl_vector *v = NULL;
|
213
|
+
size_t n;
|
214
|
+
switch (argc) {
|
215
|
+
case 1:
|
216
|
+
CHECK_VECTOR(argv[0]);
|
217
|
+
Data_Get_Struct(argv[0], gsl_vector, v);
|
218
|
+
n = v->size;
|
219
|
+
break;
|
220
|
+
case 2:
|
221
|
+
CHECK_FIXNUM(argv[0]);
|
222
|
+
CHECK_VECTOR(argv[1]);
|
223
|
+
n = FIX2INT(argv[0]);
|
224
|
+
Data_Get_Struct(argv[1], gsl_vector, v);
|
225
|
+
break;
|
226
|
+
default:
|
227
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
228
|
+
break;
|
229
|
+
}
|
230
|
+
h = gsl_histogram_calloc_range(n, v->data);
|
231
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_free, h);
|
232
|
+
}
|
233
|
+
|
234
|
+
static VALUE rb_gsl_histogram_bins(VALUE obj)
|
235
|
+
{
|
236
|
+
gsl_histogram *h = NULL;
|
237
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
238
|
+
return INT2FIX(gsl_histogram_bins(h));
|
239
|
+
}
|
240
|
+
|
241
|
+
static VALUE rb_gsl_histogram_set_ranges(int argc, VALUE *argv, VALUE obj)
|
242
|
+
{
|
243
|
+
gsl_histogram *h = NULL;
|
244
|
+
gsl_vector *v = NULL;
|
245
|
+
size_t size;
|
246
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
247
|
+
if (argc != 1 && argc != 2)
|
248
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
249
|
+
if (TYPE(argv[0]) == T_ARRAY) {
|
250
|
+
v = make_cvector_from_rarray(argv[0]);
|
251
|
+
if (argc == 1) size = v->size;
|
252
|
+
else size = FIX2INT(argv[1]);
|
253
|
+
gsl_histogram_set_ranges(h, v->data, size);
|
254
|
+
gsl_vector_free(v);
|
255
|
+
} else {
|
256
|
+
CHECK_VECTOR(argv[0]);
|
257
|
+
Data_Get_Struct(argv[0], gsl_vector, v);
|
258
|
+
if (argc == 1) size = v->size;
|
259
|
+
else size = FIX2INT(argv[1]);
|
260
|
+
gsl_histogram_set_ranges(h, v->data, size);
|
261
|
+
}
|
262
|
+
return obj;
|
263
|
+
}
|
264
|
+
|
265
|
+
static VALUE rb_gsl_histogram_range(VALUE obj)
|
266
|
+
{
|
267
|
+
gsl_histogram *h = NULL;
|
268
|
+
gsl_vector_view *v = NULL;
|
269
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
270
|
+
v = gsl_vector_view_alloc();
|
271
|
+
v->vector.data = h->range;
|
272
|
+
v->vector.size = h->n + 1;
|
273
|
+
v->vector.stride = 1;
|
274
|
+
return Data_Wrap_Struct(cgsl_histogram_range, 0, gsl_vector_view_free, v);
|
275
|
+
}
|
276
|
+
|
277
|
+
static VALUE rb_gsl_histogram_bin(VALUE obj)
|
278
|
+
{
|
279
|
+
gsl_histogram *h = NULL;
|
280
|
+
gsl_vector_view *v = NULL;
|
281
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
282
|
+
v = gsl_vector_view_alloc();
|
283
|
+
v->vector.data = h->bin;
|
284
|
+
v->vector.size = h->n;
|
285
|
+
v->vector.stride = 1;
|
286
|
+
return Data_Wrap_Struct(cgsl_histogram_bin, 0, gsl_vector_view_free, v);
|
287
|
+
}
|
288
|
+
|
289
|
+
static VALUE rb_gsl_histogram_set_ranges_uniform(int argc, VALUE *argv, VALUE obj)
|
290
|
+
{
|
291
|
+
gsl_histogram *h = NULL;
|
292
|
+
double xmin, xmax;
|
293
|
+
switch (argc) {
|
294
|
+
case 1:
|
295
|
+
Check_Type(argv[0], T_ARRAY);
|
296
|
+
xmin = NUM2DBL(rb_ary_entry(argv[0], 0));
|
297
|
+
xmax = NUM2DBL(rb_ary_entry(argv[0], 1));
|
298
|
+
break;
|
299
|
+
case 2:
|
300
|
+
xmin = NUM2DBL(argv[0]);
|
301
|
+
xmax = NUM2DBL(argv[1]);
|
302
|
+
break;
|
303
|
+
default:
|
304
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
305
|
+
break;
|
306
|
+
}
|
307
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
308
|
+
gsl_histogram_set_ranges_uniform(h, xmin, xmax);
|
309
|
+
return obj;
|
310
|
+
}
|
311
|
+
|
312
|
+
/* singleton */
|
313
|
+
static VALUE rb_gsl_histogram_memcpy(VALUE obj, VALUE vhdest, VALUE vhsrc)
|
314
|
+
{
|
315
|
+
gsl_histogram *hdest = NULL, *hsrc = NULL;
|
316
|
+
CHECK_HISTOGRAM(vhdest);
|
317
|
+
CHECK_HISTOGRAM(vhsrc);
|
318
|
+
Data_Get_Struct(vhdest, gsl_histogram, hdest);
|
319
|
+
Data_Get_Struct(vhsrc, gsl_histogram, hsrc);
|
320
|
+
gsl_histogram_memcpy(hdest, hsrc);
|
321
|
+
return vhdest;
|
322
|
+
}
|
323
|
+
|
324
|
+
static VALUE rb_gsl_histogram_clone(VALUE obj)
|
325
|
+
{
|
326
|
+
gsl_histogram *hsrc = NULL, *hnew = NULL;
|
327
|
+
Data_Get_Struct(obj, gsl_histogram, hsrc);
|
328
|
+
hnew = gsl_histogram_clone(hsrc);
|
329
|
+
return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
|
330
|
+
}
|
331
|
+
|
332
|
+
static VALUE rb_gsl_histogram_accumulate(int argc, VALUE *argv, VALUE obj)
|
333
|
+
{
|
334
|
+
gsl_histogram *h = NULL;
|
335
|
+
gsl_vector *v;
|
336
|
+
gsl_vector_int *vi;
|
337
|
+
size_t i;
|
338
|
+
double weight = 1;
|
339
|
+
#ifdef HAVE_NARRAY_H
|
340
|
+
double *ptr;
|
341
|
+
size_t size, stride;
|
342
|
+
#endif
|
343
|
+
switch (argc) {
|
344
|
+
case 2:
|
345
|
+
Need_Float(argv[1]);
|
346
|
+
weight = NUM2DBL(argv[1]);
|
347
|
+
break;
|
348
|
+
case 1:
|
349
|
+
weight = 1;
|
350
|
+
break;
|
351
|
+
default:
|
352
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
353
|
+
break;
|
354
|
+
}
|
355
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
356
|
+
if (TYPE(argv[0]) == T_ARRAY) {
|
357
|
+
// for (i = 0; i < RARRAY(argv[0])->len; i++)
|
358
|
+
for (i = 0; i < RARRAY_LEN(argv[0]); i++)
|
359
|
+
gsl_histogram_accumulate(h, NUM2DBL(rb_ary_entry(argv[0], i)), weight);
|
360
|
+
} else if (VECTOR_P(argv[0])) {
|
361
|
+
Data_Get_Struct(argv[0], gsl_vector, v);
|
362
|
+
for (i = 0; i < v->size; i++)
|
363
|
+
gsl_histogram_accumulate(h, gsl_vector_get(v, i), weight);
|
364
|
+
} else if (VECTOR_INT_P(argv[0])) {
|
365
|
+
Data_Get_Struct(argv[0], gsl_vector_int, vi);
|
366
|
+
for (i = 0; i < vi->size; i++)
|
367
|
+
gsl_histogram_accumulate(h, (double)gsl_vector_int_get(vi, i), weight);
|
368
|
+
#ifdef HAVE_NARRAY_H
|
369
|
+
} else if (NA_IsNArray(argv[0])) {
|
370
|
+
ptr = get_vector_ptr(argv[0], &stride, &size);
|
371
|
+
for (i = 0; i < size; i++)
|
372
|
+
gsl_histogram_accumulate(h, ptr[i], weight);
|
373
|
+
#endif
|
374
|
+
} else {
|
375
|
+
gsl_histogram_accumulate(h, NUM2DBL(argv[0]), weight);
|
376
|
+
}
|
377
|
+
return argv[0];
|
378
|
+
}
|
379
|
+
|
380
|
+
static VALUE rb_gsl_histogram_accumulate2(int argc, VALUE *argv, VALUE obj)
|
381
|
+
{
|
382
|
+
gsl_histogram *h = NULL;
|
383
|
+
double weight = 1;
|
384
|
+
double x;
|
385
|
+
switch (argc) {
|
386
|
+
case 2:
|
387
|
+
Need_Float(argv[1]);
|
388
|
+
weight = NUM2DBL(argv[1]);
|
389
|
+
/* no break; */
|
390
|
+
case 1:
|
391
|
+
Need_Float(argv[0]);
|
392
|
+
x = NUM2DBL(argv[0]);
|
393
|
+
break;
|
394
|
+
default:
|
395
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
396
|
+
break;
|
397
|
+
}
|
398
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
399
|
+
if (x < h->range[0]) x = h->range[0] + 4*GSL_DBL_EPSILON;
|
400
|
+
if (x > h->range[h->n]) x = h->range[h->n] - 4*GSL_DBL_EPSILON;
|
401
|
+
gsl_histogram_accumulate(h, x, weight);
|
402
|
+
return argv[0];
|
403
|
+
}
|
404
|
+
|
405
|
+
static VALUE rb_gsl_histogram_get(VALUE obj, VALUE i)
|
406
|
+
{
|
407
|
+
gsl_histogram *h = NULL;
|
408
|
+
CHECK_FIXNUM(i);
|
409
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
410
|
+
return rb_float_new(gsl_histogram_get(h, FIX2INT(i)));
|
411
|
+
}
|
412
|
+
|
413
|
+
static VALUE rb_gsl_histogram_get_range(VALUE obj, VALUE i)
|
414
|
+
{
|
415
|
+
gsl_histogram *h = NULL;
|
416
|
+
double lower, upper;
|
417
|
+
CHECK_FIXNUM(i);
|
418
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
419
|
+
gsl_histogram_get_range(h, FIX2INT(i), &lower, &upper);
|
420
|
+
return rb_ary_new3(2, rb_float_new(lower), rb_float_new(upper));
|
421
|
+
}
|
422
|
+
|
423
|
+
static VALUE rb_gsl_histogram_max(VALUE obj)
|
424
|
+
{
|
425
|
+
gsl_histogram *h = NULL;
|
426
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
427
|
+
return rb_float_new(gsl_histogram_max(h));
|
428
|
+
}
|
429
|
+
|
430
|
+
static VALUE rb_gsl_histogram_min(VALUE obj)
|
431
|
+
{
|
432
|
+
gsl_histogram *h = NULL;
|
433
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
434
|
+
return rb_float_new(gsl_histogram_min(h));
|
435
|
+
}
|
436
|
+
|
437
|
+
static VALUE rb_gsl_histogram_reset(VALUE obj)
|
438
|
+
{
|
439
|
+
gsl_histogram *h = NULL;
|
440
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
441
|
+
gsl_histogram_reset(h);
|
442
|
+
return obj;
|
443
|
+
}
|
444
|
+
|
445
|
+
static VALUE rb_gsl_histogram_find(VALUE obj, VALUE x)
|
446
|
+
{
|
447
|
+
gsl_histogram *h = NULL;
|
448
|
+
size_t i;
|
449
|
+
Need_Float(x);
|
450
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
451
|
+
gsl_histogram_find(h, NUM2DBL(x), &i);
|
452
|
+
return INT2FIX(i);
|
453
|
+
}
|
454
|
+
|
455
|
+
static VALUE rb_gsl_histogram_max_val(VALUE obj)
|
456
|
+
{
|
457
|
+
gsl_histogram *h = NULL;
|
458
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
459
|
+
return rb_float_new(gsl_histogram_max_val(h));
|
460
|
+
}
|
461
|
+
|
462
|
+
static VALUE rb_gsl_histogram_max_bin(VALUE obj)
|
463
|
+
{
|
464
|
+
gsl_histogram *h = NULL;
|
465
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
466
|
+
return INT2FIX(gsl_histogram_max_bin(h));
|
467
|
+
}
|
468
|
+
|
469
|
+
static VALUE rb_gsl_histogram_min_val(VALUE obj)
|
470
|
+
{
|
471
|
+
gsl_histogram *h = NULL;
|
472
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
473
|
+
return rb_float_new(gsl_histogram_min_val(h));
|
474
|
+
}
|
475
|
+
|
476
|
+
static VALUE rb_gsl_histogram_min_bin(VALUE obj)
|
477
|
+
{
|
478
|
+
gsl_histogram *h = NULL;
|
479
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
480
|
+
return INT2FIX(gsl_histogram_min_bin(h));
|
481
|
+
}
|
482
|
+
|
483
|
+
static VALUE rb_gsl_histogram_mean(VALUE obj)
|
484
|
+
{
|
485
|
+
gsl_histogram *h = NULL;
|
486
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
487
|
+
return rb_float_new(gsl_histogram_mean(h));
|
488
|
+
}
|
489
|
+
|
490
|
+
static VALUE rb_gsl_histogram_sigma(VALUE obj)
|
491
|
+
{
|
492
|
+
gsl_histogram *h = NULL;
|
493
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
494
|
+
return rb_float_new(gsl_histogram_sigma(h));
|
495
|
+
}
|
496
|
+
|
497
|
+
#ifndef GSL_1_1_LATER
|
498
|
+
double gsl_histogram_sum(const gsl_histogram * h)
|
499
|
+
{
|
500
|
+
double sum=0;
|
501
|
+
size_t i=0, n;
|
502
|
+
n=h->n;
|
503
|
+
while(i < n) sum += h->bin[i++];
|
504
|
+
return sum;
|
505
|
+
}
|
506
|
+
#endif
|
507
|
+
|
508
|
+
static VALUE rb_gsl_histogram_sum(VALUE obj)
|
509
|
+
{
|
510
|
+
gsl_histogram *h = NULL;
|
511
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
512
|
+
if (CLASS_OF(obj) == cgsl_histogram_integ)
|
513
|
+
return rb_float_new(gsl_histogram_get(h, h->n-1));
|
514
|
+
else
|
515
|
+
return rb_float_new(gsl_histogram_sum(h));
|
516
|
+
}
|
517
|
+
|
518
|
+
static VALUE rb_gsl_histogram_normalize_bang(VALUE obj)
|
519
|
+
{
|
520
|
+
gsl_histogram *h = NULL;
|
521
|
+
double scale;
|
522
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
523
|
+
if (CLASS_OF(obj) == cgsl_histogram_integ)
|
524
|
+
scale = 1.0/gsl_histogram_get(h, h->n-1);
|
525
|
+
else
|
526
|
+
scale = 1.0/gsl_histogram_sum(h);
|
527
|
+
gsl_histogram_scale(h, scale);
|
528
|
+
return obj;
|
529
|
+
}
|
530
|
+
|
531
|
+
static VALUE rb_gsl_histogram_normalize(VALUE obj)
|
532
|
+
{
|
533
|
+
gsl_histogram *h = NULL, *hnew = NULL;
|
534
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
535
|
+
hnew = gsl_histogram_clone(h);
|
536
|
+
return rb_gsl_histogram_normalize_bang(Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew));
|
537
|
+
}
|
538
|
+
|
539
|
+
static VALUE rb_gsl_histogram_integral(int argc, VALUE *argv, VALUE obj)
|
540
|
+
{
|
541
|
+
gsl_histogram *h = NULL;
|
542
|
+
size_t istart = 0, iend, i = 0;
|
543
|
+
double sum = 0.0;
|
544
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
545
|
+
switch (argc) {
|
546
|
+
case 0:
|
547
|
+
return rb_gsl_histogram_sum(obj);
|
548
|
+
break;
|
549
|
+
case 1:
|
550
|
+
CHECK_FIXNUM(argv[0]);
|
551
|
+
istart = 0; iend = FIX2INT(argv[0]);
|
552
|
+
break;
|
553
|
+
case 2:
|
554
|
+
CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
|
555
|
+
istart = FIX2INT(argv[0]);
|
556
|
+
iend = FIX2INT(argv[1]);
|
557
|
+
break;
|
558
|
+
default:
|
559
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0-2)", argc);
|
560
|
+
break;
|
561
|
+
}
|
562
|
+
if (iend >= h->n) iend = h->n - 1;
|
563
|
+
i = istart;
|
564
|
+
while (i <= iend) sum += h->bin[i++];
|
565
|
+
return rb_float_new(sum);
|
566
|
+
}
|
567
|
+
|
568
|
+
static VALUE rb_gsl_histogram_equal_bins_p(int argc, VALUE *argv, VALUE obj)
|
569
|
+
{
|
570
|
+
gsl_histogram *h1 = NULL, *h2 = NULL;
|
571
|
+
switch (TYPE(obj)) {
|
572
|
+
case T_MODULE:
|
573
|
+
case T_CLASS:
|
574
|
+
case T_OBJECT:
|
575
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
576
|
+
argc);
|
577
|
+
CHECK_HISTOGRAM(argv[0]);
|
578
|
+
CHECK_HISTOGRAM(argv[1]);
|
579
|
+
Data_Get_Struct(argv[0], gsl_histogram, h1);
|
580
|
+
Data_Get_Struct(argv[1], gsl_histogram, h2);
|
581
|
+
break;
|
582
|
+
default:
|
583
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
584
|
+
argc);
|
585
|
+
Data_Get_Struct(obj, gsl_histogram, h1);
|
586
|
+
CHECK_HISTOGRAM(argv[0]);
|
587
|
+
Data_Get_Struct(argv[0], gsl_histogram, h2);
|
588
|
+
break;
|
589
|
+
}
|
590
|
+
return INT2FIX(gsl_histogram_equal_bins_p(h1, h2));
|
591
|
+
}
|
592
|
+
|
593
|
+
static VALUE rb_gsl_histogram_equal_bins_p2(int argc, VALUE *argv, VALUE obj)
|
594
|
+
{
|
595
|
+
gsl_histogram *h1 = NULL, *h2 = NULL;
|
596
|
+
switch (TYPE(obj)) {
|
597
|
+
case T_MODULE:
|
598
|
+
case T_CLASS:
|
599
|
+
case T_OBJECT:
|
600
|
+
if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
601
|
+
argc);
|
602
|
+
CHECK_HISTOGRAM(argv[0]);
|
603
|
+
CHECK_HISTOGRAM(argv[1]);
|
604
|
+
Data_Get_Struct(argv[0], gsl_histogram, h1);
|
605
|
+
Data_Get_Struct(argv[1], gsl_histogram, h2);
|
606
|
+
break;
|
607
|
+
default:
|
608
|
+
if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
|
609
|
+
argc);
|
610
|
+
Data_Get_Struct(obj, gsl_histogram, h1);
|
611
|
+
CHECK_HISTOGRAM(argv[0]);
|
612
|
+
Data_Get_Struct(argv[0], gsl_histogram, h2);
|
613
|
+
break;
|
614
|
+
}
|
615
|
+
if (gsl_histogram_equal_bins_p(h1, h2)) return Qtrue;
|
616
|
+
else return Qfalse;
|
617
|
+
}
|
618
|
+
|
619
|
+
static VALUE rb_gsl_histogram_add(VALUE obj, VALUE hh2)
|
620
|
+
{
|
621
|
+
gsl_histogram *h1 = NULL, *h2 = NULL, *hnew = NULL;
|
622
|
+
Data_Get_Struct(obj, gsl_histogram, h1);
|
623
|
+
hnew = gsl_histogram_clone(h1);
|
624
|
+
if (HISTOGRAM_P(hh2)) {
|
625
|
+
Data_Get_Struct(hh2, gsl_histogram, h2);
|
626
|
+
mygsl_histogram_add(hnew, h2);
|
627
|
+
} else {
|
628
|
+
Need_Float(hh2);
|
629
|
+
gsl_histogram_shift(hnew, NUM2DBL(hh2));
|
630
|
+
}
|
631
|
+
return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
|
632
|
+
}
|
633
|
+
|
634
|
+
static VALUE rb_gsl_histogram_add2(VALUE obj, VALUE hh2)
|
635
|
+
{
|
636
|
+
gsl_histogram *h1 = NULL, *h2 = NULL;
|
637
|
+
Data_Get_Struct(obj, gsl_histogram, h1);
|
638
|
+
if (HISTOGRAM_P(hh2)) {
|
639
|
+
Data_Get_Struct(hh2, gsl_histogram, h2);
|
640
|
+
mygsl_histogram_add(h1, h2);
|
641
|
+
} else {
|
642
|
+
Need_Float(hh2);
|
643
|
+
gsl_histogram_shift(h1, NUM2DBL(hh2));
|
644
|
+
}
|
645
|
+
return obj;
|
646
|
+
}
|
647
|
+
|
648
|
+
static VALUE rb_gsl_histogram_sub(VALUE obj, VALUE hh2)
|
649
|
+
{
|
650
|
+
gsl_histogram *h1 = NULL, *h2 = NULL, *hnew = NULL;
|
651
|
+
Data_Get_Struct(obj, gsl_histogram, h1);
|
652
|
+
hnew = gsl_histogram_clone(h1);
|
653
|
+
if (HISTOGRAM_P(hh2)) {
|
654
|
+
Data_Get_Struct(hh2, gsl_histogram, h2);
|
655
|
+
mygsl_histogram_sub(hnew, h2);
|
656
|
+
} else {
|
657
|
+
Need_Float(hh2);
|
658
|
+
gsl_histogram_shift(hnew, -NUM2DBL(hh2));
|
659
|
+
}
|
660
|
+
return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
|
661
|
+
}
|
662
|
+
|
663
|
+
static VALUE rb_gsl_histogram_sub2(VALUE obj, VALUE hh2)
|
664
|
+
{
|
665
|
+
gsl_histogram *h1 = NULL, *h2 = NULL;
|
666
|
+
Data_Get_Struct(obj, gsl_histogram, h1);
|
667
|
+
if (HISTOGRAM_P(hh2)) {
|
668
|
+
Data_Get_Struct(hh2, gsl_histogram, h2);
|
669
|
+
mygsl_histogram_sub(h1, h2);
|
670
|
+
} else {
|
671
|
+
Need_Float(hh2);
|
672
|
+
gsl_histogram_shift(h1, -NUM2DBL(hh2));
|
673
|
+
}
|
674
|
+
return obj;
|
675
|
+
}
|
676
|
+
|
677
|
+
static VALUE rb_gsl_histogram_mul(VALUE obj, VALUE hh2)
|
678
|
+
{
|
679
|
+
gsl_histogram *h1 = NULL, *h2 = NULL, *hnew = NULL;
|
680
|
+
Data_Get_Struct(obj, gsl_histogram, h1);
|
681
|
+
hnew = gsl_histogram_clone(h1);
|
682
|
+
if (HISTOGRAM_P(hh2)) {
|
683
|
+
Data_Get_Struct(hh2, gsl_histogram, h2);
|
684
|
+
mygsl_histogram_mul(hnew, h2);
|
685
|
+
} else {
|
686
|
+
Need_Float(hh2);
|
687
|
+
gsl_histogram_scale(hnew, NUM2DBL(hh2));
|
688
|
+
}
|
689
|
+
return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
|
690
|
+
}
|
691
|
+
|
692
|
+
static VALUE rb_gsl_histogram_mul2(VALUE obj, VALUE hh2)
|
693
|
+
{
|
694
|
+
gsl_histogram *h1 = NULL, *h2 = NULL;
|
695
|
+
Data_Get_Struct(obj, gsl_histogram, h1);
|
696
|
+
if (HISTOGRAM_P(hh2)) {
|
697
|
+
Data_Get_Struct(hh2, gsl_histogram, h2);
|
698
|
+
mygsl_histogram_mul(h1, h2);
|
699
|
+
} else {
|
700
|
+
Need_Float(hh2);
|
701
|
+
gsl_histogram_scale(h1, NUM2DBL(hh2));
|
702
|
+
}
|
703
|
+
return obj;
|
704
|
+
}
|
705
|
+
|
706
|
+
static VALUE rb_gsl_histogram_div(VALUE obj, VALUE hh2)
|
707
|
+
{
|
708
|
+
gsl_histogram *h1 = NULL, *h2 = NULL, *hnew = NULL;
|
709
|
+
Data_Get_Struct(obj, gsl_histogram, h1);
|
710
|
+
hnew = gsl_histogram_clone(h1);
|
711
|
+
if (HISTOGRAM_P(hh2)) {
|
712
|
+
Data_Get_Struct(hh2, gsl_histogram, h2);
|
713
|
+
mygsl_histogram_div(hnew, h2);
|
714
|
+
} else {
|
715
|
+
Need_Float(hh2);
|
716
|
+
gsl_histogram_scale(hnew, 1.0/NUM2DBL(hh2));
|
717
|
+
}
|
718
|
+
return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
|
719
|
+
}
|
720
|
+
|
721
|
+
static VALUE rb_gsl_histogram_div2(VALUE obj, VALUE hh2)
|
722
|
+
{
|
723
|
+
gsl_histogram *h1 = NULL, *h2 = NULL;
|
724
|
+
Data_Get_Struct(obj, gsl_histogram, h1);
|
725
|
+
if (HISTOGRAM_P(hh2)) {
|
726
|
+
Data_Get_Struct(hh2, gsl_histogram, h2);
|
727
|
+
mygsl_histogram_div(h1, h2);
|
728
|
+
} else {
|
729
|
+
Need_Float(hh2);
|
730
|
+
gsl_histogram_scale(h1, 1.0/NUM2DBL(hh2));
|
731
|
+
}
|
732
|
+
return obj;
|
733
|
+
}
|
734
|
+
|
735
|
+
static VALUE rb_gsl_histogram_scale_bang(int argc, VALUE *argv, VALUE obj)
|
736
|
+
{
|
737
|
+
gsl_histogram *h = NULL;
|
738
|
+
double scale;
|
739
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
740
|
+
switch (argc) {
|
741
|
+
case 0:
|
742
|
+
if (CLASS_OF(obj) == cgsl_histogram_integ)
|
743
|
+
scale = 1.0/h->bin[h->n-1];
|
744
|
+
else
|
745
|
+
scale = 1.0/gsl_histogram_sum(h);
|
746
|
+
break;
|
747
|
+
case 1:
|
748
|
+
scale = NUM2DBL(argv[0]);
|
749
|
+
break;
|
750
|
+
default:
|
751
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
752
|
+
break;
|
753
|
+
}
|
754
|
+
gsl_histogram_scale(h, scale);
|
755
|
+
return obj;
|
756
|
+
}
|
757
|
+
|
758
|
+
static VALUE rb_gsl_histogram_scale(int argc, VALUE *argv, VALUE obj)
|
759
|
+
{
|
760
|
+
gsl_histogram *h = NULL, *hnew = NULL;
|
761
|
+
double scale;
|
762
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
763
|
+
switch (argc) {
|
764
|
+
case 0:
|
765
|
+
if (CLASS_OF(obj) == cgsl_histogram_integ)
|
766
|
+
scale = 1.0/h->bin[h->n-1];
|
767
|
+
else
|
768
|
+
scale = 1.0/gsl_histogram_sum(h);
|
769
|
+
break;
|
770
|
+
case 1:
|
771
|
+
scale = NUM2DBL(argv[0]);
|
772
|
+
break;
|
773
|
+
default:
|
774
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
775
|
+
break;
|
776
|
+
}
|
777
|
+
hnew = gsl_histogram_clone(h);
|
778
|
+
gsl_histogram_scale(hnew, scale);
|
779
|
+
return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
|
780
|
+
}
|
781
|
+
|
782
|
+
static VALUE rb_gsl_histogram_shift(VALUE obj, VALUE shift)
|
783
|
+
{
|
784
|
+
gsl_histogram *h = NULL;
|
785
|
+
Need_Float(shift);
|
786
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
787
|
+
gsl_histogram_shift(h, NUM2DBL(shift));
|
788
|
+
return obj;
|
789
|
+
}
|
790
|
+
|
791
|
+
static VALUE rb_gsl_histogram_shift2(VALUE obj, VALUE shift)
|
792
|
+
{
|
793
|
+
gsl_histogram *h = NULL, *hnew = NULL;
|
794
|
+
Need_Float(shift);
|
795
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
796
|
+
hnew = gsl_histogram_clone(h);
|
797
|
+
gsl_histogram_shift(hnew, NUM2DBL(shift));
|
798
|
+
return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_histogram_free, hnew);
|
799
|
+
}
|
800
|
+
|
801
|
+
static VALUE rb_gsl_histogram_fwrite(VALUE obj, VALUE io)
|
802
|
+
{
|
803
|
+
gsl_histogram *h = NULL;
|
804
|
+
FILE *f;
|
805
|
+
int status, flag = 0;
|
806
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
807
|
+
f = rb_gsl_open_writefile(io, &flag);
|
808
|
+
status = gsl_histogram_fwrite(f, h);
|
809
|
+
if (flag == 1) fclose(f);
|
810
|
+
return INT2FIX(status);
|
811
|
+
}
|
812
|
+
|
813
|
+
static VALUE rb_gsl_histogram_fread(VALUE obj, VALUE io)
|
814
|
+
{
|
815
|
+
gsl_histogram *h = NULL;
|
816
|
+
FILE *f;
|
817
|
+
int status, flag = 0;
|
818
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
819
|
+
f = rb_gsl_open_readfile(io, &flag);
|
820
|
+
status = gsl_histogram_fread(f, h);
|
821
|
+
if (flag == 1) fclose(f);
|
822
|
+
return INT2FIX(status);
|
823
|
+
}
|
824
|
+
|
825
|
+
static VALUE rb_gsl_histogram_fprintf(int argc, VALUE *argv, VALUE obj)
|
826
|
+
{
|
827
|
+
gsl_histogram *h = NULL;
|
828
|
+
FILE *fp;
|
829
|
+
int status, flag = 0;
|
830
|
+
|
831
|
+
if (argc != 1 && argc != 3) {
|
832
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 3)", argc);
|
833
|
+
}
|
834
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
835
|
+
fp = rb_gsl_open_writefile(argv[0], &flag);
|
836
|
+
if (argc == 3) {
|
837
|
+
Check_Type(argv[1], T_STRING);
|
838
|
+
Check_Type(argv[2], T_STRING);
|
839
|
+
status = gsl_histogram_fprintf(fp, h, STR2CSTR(argv[1]), STR2CSTR(argv[2]));
|
840
|
+
} else {
|
841
|
+
status = gsl_histogram_fprintf(fp, h, "%g", "%g");
|
842
|
+
}
|
843
|
+
if (flag == 1) fclose(fp);
|
844
|
+
return INT2FIX(status);
|
845
|
+
}
|
846
|
+
|
847
|
+
static VALUE rb_gsl_histogram_printf(int argc, VALUE *argv, VALUE obj)
|
848
|
+
{
|
849
|
+
gsl_histogram *h = NULL;
|
850
|
+
int status;
|
851
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
852
|
+
if (argc == 2) {
|
853
|
+
Check_Type(argv[0], T_STRING);
|
854
|
+
Check_Type(argv[1], T_STRING);
|
855
|
+
status = gsl_histogram_fprintf(stdout, h, STR2CSTR(argv[0]), STR2CSTR(argv[1]));
|
856
|
+
} else {
|
857
|
+
status = gsl_histogram_fprintf(stdout, h, "%g", "%g");
|
858
|
+
}
|
859
|
+
return INT2FIX(status);
|
860
|
+
}
|
861
|
+
|
862
|
+
static VALUE rb_gsl_histogram_fscanf(VALUE obj, VALUE io)
|
863
|
+
{
|
864
|
+
gsl_histogram *h = NULL;
|
865
|
+
FILE *fp;
|
866
|
+
int status, flag = 0;
|
867
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
868
|
+
fp = rb_gsl_open_readfile(io, &flag);
|
869
|
+
status = gsl_histogram_fscanf(fp, h);
|
870
|
+
if (flag == 1) fclose(fp);
|
871
|
+
return INT2FIX(status);
|
872
|
+
}
|
873
|
+
|
874
|
+
static VALUE rb_gsl_histogram_print(VALUE obj)
|
875
|
+
{
|
876
|
+
gsl_histogram *h = NULL;
|
877
|
+
int status;
|
878
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
879
|
+
status = gsl_histogram_fprintf(stdout, h, "%g", "%g");
|
880
|
+
return INT2FIX(status);
|
881
|
+
}
|
882
|
+
|
883
|
+
static VALUE rb_gsl_histogram_pdf_alloc(VALUE klass, VALUE nn)
|
884
|
+
{
|
885
|
+
gsl_histogram_pdf *h = NULL;
|
886
|
+
gsl_histogram *h0 = NULL;
|
887
|
+
#ifdef GSL_0_9_4_LATER
|
888
|
+
if (rb_obj_is_kind_of(nn, cgsl_histogram)) {
|
889
|
+
Data_Get_Struct(nn, gsl_histogram, h0);
|
890
|
+
h = gsl_histogram_pdf_alloc(h0->n);
|
891
|
+
gsl_histogram_pdf_init(h, h0);
|
892
|
+
} else {
|
893
|
+
CHECK_FIXNUM(nn);
|
894
|
+
h = gsl_histogram_pdf_alloc(FIX2INT(nn));
|
895
|
+
}
|
896
|
+
#else
|
897
|
+
gsl_histogram *hh = NULL;
|
898
|
+
Data_Get_Struct(nn, gsl_histogram, hh);
|
899
|
+
h = gsl_histogram_pdf_alloc(hh);
|
900
|
+
#endif
|
901
|
+
return Data_Wrap_Struct(klass, 0, gsl_histogram_pdf_free, h);
|
902
|
+
}
|
903
|
+
|
904
|
+
#ifdef GSL_0_9_4_LATER
|
905
|
+
static VALUE rb_gsl_histogram_pdf_init(VALUE obj, VALUE hh)
|
906
|
+
{
|
907
|
+
gsl_histogram_pdf *p = NULL;
|
908
|
+
gsl_histogram *h = NULL;
|
909
|
+
CHECK_HISTOGRAM(hh);
|
910
|
+
Data_Get_Struct(obj, gsl_histogram_pdf, p);
|
911
|
+
Data_Get_Struct(hh, gsl_histogram, h);
|
912
|
+
gsl_histogram_pdf_init(p, h);
|
913
|
+
return obj;
|
914
|
+
}
|
915
|
+
#endif
|
916
|
+
|
917
|
+
static VALUE rb_gsl_histogram_pdf_sample(VALUE obj, VALUE r)
|
918
|
+
{
|
919
|
+
gsl_histogram_pdf *p = NULL;
|
920
|
+
Need_Float(r);
|
921
|
+
Data_Get_Struct(obj, gsl_histogram_pdf, p);
|
922
|
+
return rb_float_new(gsl_histogram_pdf_sample(p, NUM2DBL(r)));
|
923
|
+
}
|
924
|
+
|
925
|
+
static VALUE rb_gsl_histogram_pdf_range(VALUE obj)
|
926
|
+
{
|
927
|
+
gsl_histogram_pdf *h = NULL;
|
928
|
+
gsl_vector_view *v = NULL;
|
929
|
+
Data_Get_Struct(obj, gsl_histogram_pdf, h);
|
930
|
+
v = gsl_vector_view_alloc(h->n);
|
931
|
+
v->vector.data = h->range;
|
932
|
+
v->vector.size = h->n + 1;
|
933
|
+
v->vector.stride = 1;
|
934
|
+
return Data_Wrap_Struct(cgsl_histogram_range, 0, gsl_vector_view_free, v);
|
935
|
+
}
|
936
|
+
|
937
|
+
static VALUE rb_gsl_histogram_pdf_sum(VALUE obj)
|
938
|
+
{
|
939
|
+
gsl_histogram_pdf *h = NULL;
|
940
|
+
gsl_vector_view *v = NULL;
|
941
|
+
Data_Get_Struct(obj, gsl_histogram_pdf, h);
|
942
|
+
v = gsl_vector_view_alloc(h->n);
|
943
|
+
v->vector.data = h->sum;
|
944
|
+
v->vector.size = h->n + 1;
|
945
|
+
v->vector.stride = 1;
|
946
|
+
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, gsl_vector_view_free, v);
|
947
|
+
}
|
948
|
+
|
949
|
+
static VALUE rb_gsl_histogram_graph(int argc, VALUE *argv, VALUE obj)
|
950
|
+
{
|
951
|
+
#ifdef HAVE_GNU_GRAPH
|
952
|
+
gsl_histogram *v = NULL;
|
953
|
+
FILE *fp = NULL;
|
954
|
+
size_t i;
|
955
|
+
char command[1024];
|
956
|
+
Data_Get_Struct(obj, gsl_histogram, v);
|
957
|
+
switch (argc) {
|
958
|
+
case 0:
|
959
|
+
strcpy(command, "graph -T X -g 3");
|
960
|
+
break;
|
961
|
+
case 1:
|
962
|
+
make_graphcommand(command, argv[0]);
|
963
|
+
break;
|
964
|
+
default:
|
965
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
966
|
+
break;
|
967
|
+
}
|
968
|
+
fp = popen(command, "w");
|
969
|
+
if (fp == NULL) rb_raise(rb_eIOError, "GNU graph not found.");
|
970
|
+
for (i = 0; i < v->n; i++) {
|
971
|
+
fprintf(fp, "%e %e\n%e %e\n", v->range[i], v->bin[i], v->range[i+1], v->bin[i]);
|
972
|
+
}
|
973
|
+
fflush(fp);
|
974
|
+
pclose(fp);
|
975
|
+
fp = NULL;
|
976
|
+
return Qtrue;
|
977
|
+
#else
|
978
|
+
rb_raise(rb_eNoMethodError, "not implemented");
|
979
|
+
return Qfalse;
|
980
|
+
#endif
|
981
|
+
}
|
982
|
+
|
983
|
+
static VALUE rb_gsl_histogram_plot(int argc, VALUE *argv, VALUE obj)
|
984
|
+
{
|
985
|
+
#ifdef HAVE_GNU_GRAPH
|
986
|
+
gsl_histogram *v = NULL;
|
987
|
+
FILE *fp = NULL;
|
988
|
+
size_t i;
|
989
|
+
Data_Get_Struct(obj, gsl_histogram, v);
|
990
|
+
switch (argc) {
|
991
|
+
case 0:
|
992
|
+
fp = popen("gnuplot -persist", "w");
|
993
|
+
if (fp == NULL) rb_raise(rb_eIOError, "GNU graph not found.");
|
994
|
+
fprintf(fp, "plot '-' with fsteps\n");
|
995
|
+
break;
|
996
|
+
case 1:
|
997
|
+
fp = popen("gnuplot -persist", "w");
|
998
|
+
if (fp == NULL) rb_raise(rb_eIOError, "GNU graph not found.");
|
999
|
+
if (TYPE(argv[0]) == T_STRING)
|
1000
|
+
fprintf(fp, "plot '-' %s\n", STR2CSTR(argv[0]));
|
1001
|
+
else
|
1002
|
+
fprintf(fp, "plot '-' with fsteps\n");
|
1003
|
+
break;
|
1004
|
+
default:
|
1005
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
1006
|
+
break;
|
1007
|
+
}
|
1008
|
+
for (i = 0; i < v->n; i++) {
|
1009
|
+
fprintf(fp, "%e %e\n", v->range[i], v->bin[i]);
|
1010
|
+
}
|
1011
|
+
fprintf(fp, "e\n");
|
1012
|
+
fflush(fp);
|
1013
|
+
pclose(fp);
|
1014
|
+
fp = NULL;
|
1015
|
+
return Qtrue;
|
1016
|
+
#else
|
1017
|
+
rb_raise(rb_eNoMethodError, "not implemented");
|
1018
|
+
return Qfalse;
|
1019
|
+
#endif
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
struct fit_histogram {
|
1023
|
+
gsl_histogram *h;
|
1024
|
+
size_t binstart, binend;
|
1025
|
+
};
|
1026
|
+
|
1027
|
+
static VALUE rb_gsl_histogram_fit_exponential(int argc, VALUE *argv, VALUE obj)
|
1028
|
+
{
|
1029
|
+
gsl_histogram *h;
|
1030
|
+
gsl_vector *x, *lny, *w;
|
1031
|
+
size_t binstart = 0, binend, n, p = 2, dof, i;
|
1032
|
+
double c0, c1, cov00, cov01, cov11, sumsq, xl, xh;
|
1033
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1034
|
+
binstart = 0;
|
1035
|
+
binend = h->n - 1;
|
1036
|
+
switch (argc) {
|
1037
|
+
case 2:
|
1038
|
+
CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
|
1039
|
+
binstart = FIX2INT(argv[0]);
|
1040
|
+
binend = FIX2INT(argv[1]);
|
1041
|
+
if (binend >= h->n) binend = h->n - 1;
|
1042
|
+
break;
|
1043
|
+
case 0:
|
1044
|
+
break;
|
1045
|
+
default:
|
1046
|
+
rb_raise(rb_eArgError, "too many arguments (%d for 0 or 2)", argc);
|
1047
|
+
break;
|
1048
|
+
}
|
1049
|
+
n = binend - binstart + 1;
|
1050
|
+
dof = n - p;
|
1051
|
+
|
1052
|
+
x = gsl_vector_alloc(n);
|
1053
|
+
w = gsl_vector_alloc(n);
|
1054
|
+
lny = gsl_vector_alloc(n);
|
1055
|
+
for (i = 0; i < n; i++) {
|
1056
|
+
if (gsl_histogram_get_range(h, i+binstart, &xl, &xh))
|
1057
|
+
rb_raise(rb_eIndexError, "wrong index");
|
1058
|
+
gsl_vector_set(x, i, (xl+xh)/2.0);
|
1059
|
+
gsl_vector_set(lny, i, log(h->bin[i+binstart]));
|
1060
|
+
gsl_vector_set(w, i, h->bin[i+binstart]);
|
1061
|
+
}
|
1062
|
+
gsl_fit_wlinear(x->data, 1, w->data, 1, lny->data, 1, n,
|
1063
|
+
&c0, &c1, &cov00, &cov01, &cov11, &sumsq);
|
1064
|
+
gsl_vector_free(lny);
|
1065
|
+
gsl_vector_free(w);
|
1066
|
+
gsl_vector_free(x);
|
1067
|
+
c0 = exp(c0);
|
1068
|
+
return rb_ary_new3(6, rb_float_new(c0), rb_float_new(c1),
|
1069
|
+
rb_float_new(c0*sqrt(cov00)), rb_float_new(sqrt(cov11)),
|
1070
|
+
rb_float_new(sumsq), INT2FIX(dof));
|
1071
|
+
}
|
1072
|
+
|
1073
|
+
static VALUE rb_gsl_histogram_fit_power(int argc, VALUE *argv, VALUE obj)
|
1074
|
+
{
|
1075
|
+
gsl_histogram *h;
|
1076
|
+
gsl_vector *lnx, *lny, *w;
|
1077
|
+
size_t binstart = 0, binend, n, p = 2, dof, i;
|
1078
|
+
double c0, c1, cov00, cov01, cov11, sumsq, xl, xh;
|
1079
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1080
|
+
binstart = 0;
|
1081
|
+
binend = h->n - 1;
|
1082
|
+
switch (argc) {
|
1083
|
+
case 2:
|
1084
|
+
CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
|
1085
|
+
binstart = FIX2INT(argv[0]);
|
1086
|
+
binend = FIX2INT(argv[1]);
|
1087
|
+
if (binend >= h->n) binend = h->n - 1;
|
1088
|
+
break;
|
1089
|
+
case 0:
|
1090
|
+
break;
|
1091
|
+
default:
|
1092
|
+
rb_raise(rb_eArgError, "too many arguments (%d for 0 or 2)", argc);
|
1093
|
+
break;
|
1094
|
+
}
|
1095
|
+
n = binend - binstart + 1;
|
1096
|
+
dof = n - p;
|
1097
|
+
|
1098
|
+
lnx = gsl_vector_alloc(n);
|
1099
|
+
w = gsl_vector_alloc(n);
|
1100
|
+
lny = gsl_vector_alloc(n);
|
1101
|
+
for (i = 0; i < n; i++) {
|
1102
|
+
if (gsl_histogram_get_range(h, i+binstart, &xl, &xh))
|
1103
|
+
rb_raise(rb_eIndexError, "wrong index");
|
1104
|
+
gsl_vector_set(lnx, i, (log(xl)+log(xh))/2.0);
|
1105
|
+
gsl_vector_set(lny, i, log(h->bin[i+binstart]));
|
1106
|
+
gsl_vector_set(w, i, h->bin[i+binstart]);
|
1107
|
+
}
|
1108
|
+
gsl_fit_wlinear(lnx->data, 1, w->data, 1, lny->data, 1, n,
|
1109
|
+
&c0, &c1, &cov00, &cov01, &cov11, &sumsq);
|
1110
|
+
gsl_vector_free(lny);
|
1111
|
+
gsl_vector_free(w);
|
1112
|
+
gsl_vector_free(lnx);
|
1113
|
+
c0 = exp(c0);
|
1114
|
+
return rb_ary_new3(6, rb_float_new(c0), rb_float_new(c1),
|
1115
|
+
rb_float_new(c0*sqrt(cov00)), rb_float_new(sqrt(cov11)),
|
1116
|
+
rb_float_new(sumsq), INT2FIX(dof));
|
1117
|
+
}
|
1118
|
+
|
1119
|
+
static int Gaussian_f(const gsl_vector *v, void *params, gsl_vector *f);
|
1120
|
+
static int Gaussian_df(const gsl_vector *v, void *params, gsl_matrix * J);
|
1121
|
+
static int Gaussian_f(const gsl_vector *v, void *params, gsl_vector *f)
|
1122
|
+
{
|
1123
|
+
struct fit_histogram *hh;
|
1124
|
+
gsl_histogram *h = NULL;
|
1125
|
+
double amp, mu, var, xl, xh, xi, yi, sqw;
|
1126
|
+
size_t i, binstart, binend;
|
1127
|
+
hh = (struct fit_histogram *) params;
|
1128
|
+
h = hh->h;
|
1129
|
+
binstart = hh->binstart;
|
1130
|
+
binend = hh->binend;
|
1131
|
+
var = gsl_vector_get(v, 0);
|
1132
|
+
mu = gsl_vector_get(v, 1);
|
1133
|
+
amp = gsl_vector_get(v, 2);
|
1134
|
+
for (i = binstart; i <= binend; i++) {
|
1135
|
+
if (gsl_histogram_get_range(h, i, &xl, &xh))
|
1136
|
+
rb_raise(rb_eIndexError, "wrong index");
|
1137
|
+
xi = (xl + xh)/2.0;
|
1138
|
+
yi = h->bin[i];
|
1139
|
+
// sqw = sqrt(yi);
|
1140
|
+
if (yi >= 1.0) sqw = 1.0/sqrt(yi);
|
1141
|
+
else sqw = 1.0;
|
1142
|
+
gsl_vector_set(f, i-binstart, (amp*exp(-(xi - mu)*(xi - mu)/var/2.0) - yi)*sqw);
|
1143
|
+
}
|
1144
|
+
return GSL_SUCCESS;
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
static int Gaussian_df(const gsl_vector *v, void *params, gsl_matrix *J)
|
1148
|
+
{
|
1149
|
+
struct fit_histogram *hh;
|
1150
|
+
gsl_histogram *h = NULL;
|
1151
|
+
double amp, mu, var, xl, xh, xi, yi, y, sqw;
|
1152
|
+
size_t i, binstart, binend;
|
1153
|
+
hh = (struct fit_histogram *) params;
|
1154
|
+
h = hh->h;
|
1155
|
+
binstart = hh->binstart;
|
1156
|
+
binend = hh->binend;
|
1157
|
+
var = gsl_vector_get(v, 0);
|
1158
|
+
mu = gsl_vector_get(v, 1);
|
1159
|
+
amp = gsl_vector_get(v, 2);
|
1160
|
+
for (i = binstart; i <= binend; i++) {
|
1161
|
+
if (gsl_histogram_get_range(h, i, &xl, &xh))
|
1162
|
+
rb_raise(rb_eIndexError, "wrong index");
|
1163
|
+
xi = (xl + xh)/2.0;
|
1164
|
+
yi = h->bin[i];
|
1165
|
+
// sqw = sqrt(yi);
|
1166
|
+
if (yi >= 1.0) sqw = 1.0/sqrt(yi);
|
1167
|
+
else sqw = 1.0;
|
1168
|
+
y = exp(-(xi - mu)*(xi - mu)/var/2.0);
|
1169
|
+
gsl_matrix_set(J, i-binstart, 0, amp*y*(xi - mu)*(xi - mu)/2/var/var*sqw);
|
1170
|
+
gsl_matrix_set(J, i-binstart, 1, amp*y*(xi - mu)/var*sqw);
|
1171
|
+
gsl_matrix_set(J, i-binstart, 2, y*sqw);
|
1172
|
+
}
|
1173
|
+
return GSL_SUCCESS;
|
1174
|
+
}
|
1175
|
+
|
1176
|
+
static int Gaussian_fdf(const gsl_vector *v, void *params, gsl_vector *f,
|
1177
|
+
gsl_matrix *J)
|
1178
|
+
{
|
1179
|
+
Gaussian_f(v, params, f);
|
1180
|
+
Gaussian_df(v, params, J);
|
1181
|
+
return GSL_SUCCESS;
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
static VALUE rb_gsl_histogram_fit_gaussian(int argc, VALUE *argv, VALUE obj)
|
1185
|
+
{
|
1186
|
+
gsl_histogram *h = NULL;
|
1187
|
+
struct fit_histogram hh;
|
1188
|
+
const gsl_multifit_fdfsolver_type *T;
|
1189
|
+
gsl_multifit_fdfsolver *s;
|
1190
|
+
int status;
|
1191
|
+
size_t iter = 0, binstart, binend;
|
1192
|
+
size_t n, dof; /* # of data points */
|
1193
|
+
size_t p = 3; /* # of fitting parameters */
|
1194
|
+
gsl_multifit_function_fdf f;
|
1195
|
+
gsl_matrix *covar = NULL;
|
1196
|
+
gsl_vector *x = NULL;
|
1197
|
+
double sigma, mean, height, errs, errm, errh, chi2;
|
1198
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1199
|
+
binstart = 0;
|
1200
|
+
binend = h->n - 1;
|
1201
|
+
switch (argc) {
|
1202
|
+
case 2:
|
1203
|
+
CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
|
1204
|
+
binstart = FIX2INT(argv[0]);
|
1205
|
+
binend = FIX2INT(argv[1]);
|
1206
|
+
if (binend >= h->n) binend = h->n - 1;
|
1207
|
+
break;
|
1208
|
+
case 0:
|
1209
|
+
break;
|
1210
|
+
default:
|
1211
|
+
rb_raise(rb_eArgError, "too many arguments (%d for 0 or 2)", argc);
|
1212
|
+
break;
|
1213
|
+
}
|
1214
|
+
x = gsl_vector_alloc(p);
|
1215
|
+
gsl_vector_set(x, 0, gsl_pow_2(gsl_histogram_sigma(h))); /* initial values, var = 1 */
|
1216
|
+
gsl_vector_set(x, 1, gsl_histogram_mean(h)); /* mu = 0 */
|
1217
|
+
gsl_vector_set(x, 2, gsl_histogram_max_val(h)); /* amp = 1 */
|
1218
|
+
hh.h = h;
|
1219
|
+
hh.binstart = binstart;
|
1220
|
+
hh.binend = binend;
|
1221
|
+
n = binend - binstart + 1;
|
1222
|
+
|
1223
|
+
covar = gsl_matrix_alloc(p, p);
|
1224
|
+
|
1225
|
+
f.f = Gaussian_f;
|
1226
|
+
f.df = Gaussian_df;
|
1227
|
+
f.fdf = Gaussian_fdf;
|
1228
|
+
f.n = n;
|
1229
|
+
f.p = p;
|
1230
|
+
f.params = &hh;
|
1231
|
+
|
1232
|
+
T = gsl_multifit_fdfsolver_lmsder;
|
1233
|
+
s = gsl_multifit_fdfsolver_alloc(T, n, p);
|
1234
|
+
gsl_multifit_fdfsolver_set(s, &f, x);
|
1235
|
+
|
1236
|
+
do {
|
1237
|
+
iter++;
|
1238
|
+
status = gsl_multifit_fdfsolver_iterate(s);
|
1239
|
+
if (status) break;
|
1240
|
+
status = gsl_multifit_test_delta(s->dx, s->x, 1e-4, 1e-4);
|
1241
|
+
} while (status == GSL_CONTINUE);
|
1242
|
+
sigma = sqrt(gsl_vector_get(s->x, 0));
|
1243
|
+
mean = gsl_vector_get(s->x, 1);
|
1244
|
+
height = gsl_vector_get(s->x, 2)*sigma*sqrt(2*M_PI);
|
1245
|
+
gsl_multifit_covar(s->J, 0.0, covar);
|
1246
|
+
chi2 = gsl_pow_2(gsl_blas_dnrm2(s->f)); /* not reduced chi-square */
|
1247
|
+
dof = n - p;
|
1248
|
+
errs = sqrt(chi2/dof*gsl_matrix_get(covar, 0, 0))/sigma/2;
|
1249
|
+
errm = sqrt(chi2/dof*gsl_matrix_get(covar, 1, 1));
|
1250
|
+
errh = sqrt(chi2/dof*gsl_matrix_get(covar, 2, 2));
|
1251
|
+
|
1252
|
+
gsl_multifit_fdfsolver_free(s);
|
1253
|
+
gsl_vector_free(x);
|
1254
|
+
gsl_matrix_free(covar);
|
1255
|
+
return rb_ary_new3(8, rb_float_new(sigma), rb_float_new(mean),
|
1256
|
+
rb_float_new(height), rb_float_new(errs),
|
1257
|
+
rb_float_new(errm), rb_float_new(errh),
|
1258
|
+
rb_float_new(chi2), INT2FIX(dof));
|
1259
|
+
}
|
1260
|
+
|
1261
|
+
static int Rayleigh_f(const gsl_vector *v, void *params, gsl_vector *f);
|
1262
|
+
static int Rayleigh_df(const gsl_vector *v, void *params, gsl_matrix * J);
|
1263
|
+
static int Rayleigh_f(const gsl_vector *v, void *params, gsl_vector *f)
|
1264
|
+
{
|
1265
|
+
struct fit_histogram *hh;
|
1266
|
+
gsl_histogram *h = NULL;
|
1267
|
+
double amp, var, xl, xh, xi, yi, sqw;
|
1268
|
+
size_t i, binstart, binend;
|
1269
|
+
hh = (struct fit_histogram *) params;
|
1270
|
+
h = hh->h;
|
1271
|
+
binstart = hh->binstart;
|
1272
|
+
binend = hh->binend;
|
1273
|
+
var = gsl_vector_get(v, 0);
|
1274
|
+
amp = gsl_vector_get(v, 1);
|
1275
|
+
for (i = binstart; i <= binend; i++) {
|
1276
|
+
if (gsl_histogram_get_range(h, i, &xl, &xh))
|
1277
|
+
rb_raise(rb_eIndexError, "wrong index");
|
1278
|
+
xi = (xl + xh)/2.0;
|
1279
|
+
yi = h->bin[i];
|
1280
|
+
sqw = sqrt(yi);
|
1281
|
+
gsl_vector_set(f, i-binstart, (amp*xi*exp(-xi*xi/var/2.0) - yi)*sqw);
|
1282
|
+
}
|
1283
|
+
return GSL_SUCCESS;
|
1284
|
+
}
|
1285
|
+
|
1286
|
+
static int Rayleigh_df(const gsl_vector *v, void *params, gsl_matrix *J)
|
1287
|
+
{
|
1288
|
+
struct fit_histogram *hh;
|
1289
|
+
gsl_histogram *h = NULL;
|
1290
|
+
double amp, var, xl, xh, xi, yi, y, sqw;
|
1291
|
+
size_t i, binstart, binend;
|
1292
|
+
hh = (struct fit_histogram *) params;
|
1293
|
+
h = hh->h;
|
1294
|
+
binstart = hh->binstart;
|
1295
|
+
binend = hh->binend;
|
1296
|
+
var = gsl_vector_get(v, 0);
|
1297
|
+
amp = gsl_vector_get(v, 1);
|
1298
|
+
for (i = binstart; i <= binend; i++) {
|
1299
|
+
if (gsl_histogram_get_range(h, i, &xl, &xh))
|
1300
|
+
rb_raise(rb_eIndexError, "wrong index");
|
1301
|
+
xi = (xl + xh)/2.0;
|
1302
|
+
yi = h->bin[i];
|
1303
|
+
sqw = sqrt(yi);
|
1304
|
+
y = xi*exp(-xi*xi/var/2.0);
|
1305
|
+
gsl_matrix_set(J, i-binstart, 0, amp*y*xi*xi/2/var/var*sqw);
|
1306
|
+
gsl_matrix_set(J, i-binstart, 1, y*sqw);
|
1307
|
+
}
|
1308
|
+
return GSL_SUCCESS;
|
1309
|
+
}
|
1310
|
+
|
1311
|
+
static int Rayleigh_fdf(const gsl_vector *v, void *params, gsl_vector *f,
|
1312
|
+
gsl_matrix *J)
|
1313
|
+
{
|
1314
|
+
Rayleigh_f(v, params, f);
|
1315
|
+
Rayleigh_df(v, params, J);
|
1316
|
+
return GSL_SUCCESS;
|
1317
|
+
}
|
1318
|
+
|
1319
|
+
|
1320
|
+
static VALUE rb_gsl_histogram_fit_rayleigh(int argc, VALUE *argv, VALUE obj)
|
1321
|
+
{
|
1322
|
+
gsl_histogram *h = NULL;
|
1323
|
+
struct fit_histogram hh;
|
1324
|
+
const gsl_multifit_fdfsolver_type *T;
|
1325
|
+
gsl_multifit_fdfsolver *s;
|
1326
|
+
int status;
|
1327
|
+
size_t iter = 0, binstart, binend;
|
1328
|
+
size_t n, dof; /* # of data points */
|
1329
|
+
size_t p = 2; /* # of fitting parameters */
|
1330
|
+
gsl_multifit_function_fdf f;
|
1331
|
+
gsl_matrix *covar = NULL;
|
1332
|
+
gsl_vector *x = NULL;
|
1333
|
+
double sigma, height, errs, errh, chi2;
|
1334
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1335
|
+
binstart = 0;
|
1336
|
+
binend = h->n - 1;
|
1337
|
+
switch (argc) {
|
1338
|
+
case 2:
|
1339
|
+
CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
|
1340
|
+
binstart = FIX2INT(argv[0]);
|
1341
|
+
binend = FIX2INT(argv[1]);
|
1342
|
+
if (binend >= h->n) binend = h->n - 1;
|
1343
|
+
break;
|
1344
|
+
case 0:
|
1345
|
+
break;
|
1346
|
+
default:
|
1347
|
+
rb_raise(rb_eArgError, "too many arguments (%d for 0 or 2)", argc);
|
1348
|
+
break;
|
1349
|
+
}
|
1350
|
+
x = gsl_vector_alloc(p);
|
1351
|
+
gsl_vector_set(x, 0, gsl_pow_2(gsl_histogram_sigma(h))); /* initial values, var = 1 */
|
1352
|
+
gsl_vector_set(x, 1, gsl_histogram_max_val(h));
|
1353
|
+
hh.h = h;
|
1354
|
+
hh.binstart = binstart;
|
1355
|
+
hh.binend = binend;
|
1356
|
+
n = binend - binstart + 1;
|
1357
|
+
|
1358
|
+
covar = gsl_matrix_alloc(p, p);
|
1359
|
+
|
1360
|
+
f.f = Rayleigh_f;
|
1361
|
+
f.df = Rayleigh_df;
|
1362
|
+
f.fdf = Rayleigh_fdf;
|
1363
|
+
f.n = n;
|
1364
|
+
f.p = p;
|
1365
|
+
f.params = &hh;
|
1366
|
+
|
1367
|
+
T = gsl_multifit_fdfsolver_lmsder;
|
1368
|
+
s = gsl_multifit_fdfsolver_alloc(T, n, p);
|
1369
|
+
gsl_multifit_fdfsolver_set(s, &f, x);
|
1370
|
+
|
1371
|
+
do {
|
1372
|
+
iter++;
|
1373
|
+
status = gsl_multifit_fdfsolver_iterate(s);
|
1374
|
+
if (status) break;
|
1375
|
+
status = gsl_multifit_test_delta(s->dx, s->x, 1e-4, 1e-4);
|
1376
|
+
} while (status == GSL_CONTINUE);
|
1377
|
+
sigma = sqrt(gsl_vector_get(s->x, 0));
|
1378
|
+
height = gsl_vector_get(s->x, 1)*sigma*sigma;
|
1379
|
+
gsl_multifit_covar(s->J, 0.0, covar);
|
1380
|
+
chi2 = gsl_pow_2(gsl_blas_dnrm2(s->f)); /* not reduced chi-square */
|
1381
|
+
dof = n - p;
|
1382
|
+
errs = sqrt(chi2/dof*gsl_matrix_get(covar, 0, 0))/sigma/2;
|
1383
|
+
errh = sqrt(chi2/dof*gsl_matrix_get(covar, 1, 1));
|
1384
|
+
|
1385
|
+
gsl_multifit_fdfsolver_free(s);
|
1386
|
+
gsl_vector_free(x);
|
1387
|
+
gsl_matrix_free(covar);
|
1388
|
+
return rb_ary_new3(6, rb_float_new(sigma),
|
1389
|
+
rb_float_new(height), rb_float_new(errs),
|
1390
|
+
rb_float_new(errh),
|
1391
|
+
rb_float_new(chi2), INT2FIX(dof));
|
1392
|
+
}
|
1393
|
+
|
1394
|
+
/*
|
1395
|
+
* y(x) = Amp*exp(-a*x)
|
1396
|
+
*/
|
1397
|
+
static int xExponential_f(const gsl_vector *v, void *params, gsl_vector *f);
|
1398
|
+
static int xExponential_df(const gsl_vector *v, void *params, gsl_matrix * J);
|
1399
|
+
static int xExponential_f(const gsl_vector *v, void *params, gsl_vector *f)
|
1400
|
+
{
|
1401
|
+
struct fit_histogram *hh;
|
1402
|
+
gsl_histogram *h = NULL;
|
1403
|
+
double amp, b, xl, xh, xi, yi, sqw;
|
1404
|
+
size_t i, binstart, binend;
|
1405
|
+
hh = (struct fit_histogram *) params;
|
1406
|
+
h = hh->h;
|
1407
|
+
binstart = hh->binstart;
|
1408
|
+
binend = hh->binend;
|
1409
|
+
b = gsl_vector_get(v, 0);
|
1410
|
+
amp = gsl_vector_get(v, 1);
|
1411
|
+
for (i = binstart; i <= binend; i++) {
|
1412
|
+
if (gsl_histogram_get_range(h, i, &xl, &xh))
|
1413
|
+
rb_raise(rb_eIndexError, "wrong index");
|
1414
|
+
xi = (xl + xh)/2.0;
|
1415
|
+
yi = h->bin[i];
|
1416
|
+
sqw = sqrt(yi);
|
1417
|
+
gsl_vector_set(f, i-binstart, (amp*xi*exp(-b*xi) - yi)*sqw);
|
1418
|
+
}
|
1419
|
+
return GSL_SUCCESS;
|
1420
|
+
}
|
1421
|
+
|
1422
|
+
static int xExponential_df(const gsl_vector *v, void *params, gsl_matrix *J)
|
1423
|
+
{
|
1424
|
+
struct fit_histogram *hh;
|
1425
|
+
gsl_histogram *h = NULL;
|
1426
|
+
double amp, b, xl, xh, xi, yi, y, sqw;
|
1427
|
+
size_t i, binstart, binend;
|
1428
|
+
hh = (struct fit_histogram *) params;
|
1429
|
+
h = hh->h;
|
1430
|
+
binstart = hh->binstart;
|
1431
|
+
binend = hh->binend;
|
1432
|
+
b = gsl_vector_get(v, 0);
|
1433
|
+
amp = gsl_vector_get(v, 1);
|
1434
|
+
for (i = binstart; i <= binend; i++) {
|
1435
|
+
if (gsl_histogram_get_range(h, i, &xl, &xh))
|
1436
|
+
rb_raise(rb_eIndexError, "wrong index");
|
1437
|
+
xi = (xl + xh)/2.0;
|
1438
|
+
yi = h->bin[i];
|
1439
|
+
sqw = sqrt(yi);
|
1440
|
+
y = xi*exp(-b*xi);
|
1441
|
+
gsl_matrix_set(J, i-binstart, 0, -amp*y*xi*sqw);
|
1442
|
+
gsl_matrix_set(J, i-binstart, 1, y*sqw);
|
1443
|
+
}
|
1444
|
+
return GSL_SUCCESS;
|
1445
|
+
}
|
1446
|
+
|
1447
|
+
static int xExponential_fdf(const gsl_vector *v, void *params, gsl_vector *f,
|
1448
|
+
gsl_matrix *J)
|
1449
|
+
{
|
1450
|
+
xExponential_f(v, params, f);
|
1451
|
+
xExponential_df(v, params, J);
|
1452
|
+
return GSL_SUCCESS;
|
1453
|
+
}
|
1454
|
+
|
1455
|
+
|
1456
|
+
static VALUE rb_gsl_histogram_fit_xexponential(int argc, VALUE *argv, VALUE obj)
|
1457
|
+
{
|
1458
|
+
gsl_histogram *h = NULL;
|
1459
|
+
struct fit_histogram hh;
|
1460
|
+
const gsl_multifit_fdfsolver_type *T;
|
1461
|
+
gsl_multifit_fdfsolver *s;
|
1462
|
+
int status;
|
1463
|
+
size_t iter = 0, binstart, binend;
|
1464
|
+
size_t n, dof; /* # of data points */
|
1465
|
+
size_t p = 2; /* # of fitting parameters */
|
1466
|
+
gsl_multifit_function_fdf f;
|
1467
|
+
gsl_matrix *covar = NULL;
|
1468
|
+
gsl_vector *x = NULL;
|
1469
|
+
double b, height, errs, errh, chi2;
|
1470
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1471
|
+
binstart = 0;
|
1472
|
+
binend = h->n - 1;
|
1473
|
+
switch (argc) {
|
1474
|
+
case 2:
|
1475
|
+
CHECK_FIXNUM(argv[0]); CHECK_FIXNUM(argv[1]);
|
1476
|
+
binstart = FIX2INT(argv[0]);
|
1477
|
+
binend = FIX2INT(argv[1]);
|
1478
|
+
if (binend >= h->n) binend = h->n - 1;
|
1479
|
+
break;
|
1480
|
+
case 0:
|
1481
|
+
break;
|
1482
|
+
default:
|
1483
|
+
rb_raise(rb_eArgError, "too many arguments (%d for 0 or 2)", argc);
|
1484
|
+
break;
|
1485
|
+
}
|
1486
|
+
x = gsl_vector_alloc(p);
|
1487
|
+
gsl_vector_set(x, 0, gsl_histogram_sigma(h)); /* initial values, var = 1 */
|
1488
|
+
gsl_vector_set(x, 1, gsl_histogram_max_val(h));
|
1489
|
+
hh.h = h;
|
1490
|
+
hh.binstart = binstart;
|
1491
|
+
hh.binend = binend;
|
1492
|
+
n = binend - binstart + 1;
|
1493
|
+
|
1494
|
+
covar = gsl_matrix_alloc(p, p);
|
1495
|
+
|
1496
|
+
f.f = xExponential_f;
|
1497
|
+
f.df = xExponential_df;
|
1498
|
+
f.fdf = xExponential_fdf;
|
1499
|
+
f.n = n;
|
1500
|
+
f.p = p;
|
1501
|
+
f.params = &hh;
|
1502
|
+
|
1503
|
+
T = gsl_multifit_fdfsolver_lmsder;
|
1504
|
+
s = gsl_multifit_fdfsolver_alloc(T, n, p);
|
1505
|
+
gsl_multifit_fdfsolver_set(s, &f, x);
|
1506
|
+
|
1507
|
+
do {
|
1508
|
+
iter++;
|
1509
|
+
status = gsl_multifit_fdfsolver_iterate(s);
|
1510
|
+
if (status) break;
|
1511
|
+
status = gsl_multifit_test_delta(s->dx, s->x, 1e-4, 1e-4);
|
1512
|
+
} while (status == GSL_CONTINUE);
|
1513
|
+
b = gsl_vector_get(s->x, 0);
|
1514
|
+
height = gsl_vector_get(s->x, 1);
|
1515
|
+
gsl_multifit_covar(s->J, 0.0, covar);
|
1516
|
+
chi2 = gsl_pow_2(gsl_blas_dnrm2(s->f)); /* not reduced chi-square */
|
1517
|
+
dof = n - p;
|
1518
|
+
errs = sqrt(chi2/dof*gsl_matrix_get(covar, 0, 0));
|
1519
|
+
errh = sqrt(chi2/dof*gsl_matrix_get(covar, 1, 1));
|
1520
|
+
|
1521
|
+
gsl_multifit_fdfsolver_free(s);
|
1522
|
+
gsl_vector_free(x);
|
1523
|
+
gsl_matrix_free(covar);
|
1524
|
+
return rb_ary_new3(6, rb_float_new(b),
|
1525
|
+
rb_float_new(height), rb_float_new(errs),
|
1526
|
+
rb_float_new(errh),
|
1527
|
+
rb_float_new(chi2), INT2FIX(dof));
|
1528
|
+
}
|
1529
|
+
|
1530
|
+
static VALUE rb_gsl_histogram_fit(int argc, VALUE *argv, VALUE obj)
|
1531
|
+
{
|
1532
|
+
char fittype[32];
|
1533
|
+
if (argc < 1) rb_raise(rb_eArgError, "too few arguments");
|
1534
|
+
Check_Type(argv[0], T_STRING);
|
1535
|
+
strcpy(fittype, STR2CSTR(argv[0]));
|
1536
|
+
if (str_head_grep(fittype, "exp") == 0) {
|
1537
|
+
return rb_gsl_histogram_fit_exponential(argc-1, argv+1, obj);
|
1538
|
+
} else if (str_head_grep(fittype, "power") == 0) {
|
1539
|
+
return rb_gsl_histogram_fit_power(argc-1, argv+1, obj);
|
1540
|
+
} else if (str_head_grep(fittype, "gaus") == 0) {
|
1541
|
+
return rb_gsl_histogram_fit_gaussian(argc-1, argv+1, obj);
|
1542
|
+
} else if (str_head_grep(fittype, "rayleigh") == 0) {
|
1543
|
+
return rb_gsl_histogram_fit_rayleigh(argc-1, argv+1, obj);
|
1544
|
+
} else if (str_head_grep(fittype, "xexp") == 0) {
|
1545
|
+
return rb_gsl_histogram_fit_xexponential(argc-1, argv+1, obj);
|
1546
|
+
} else {
|
1547
|
+
rb_raise(rb_eRuntimeError,
|
1548
|
+
"unknown fitting type %s (exp, power, gaus expected)", fittype);
|
1549
|
+
}
|
1550
|
+
return Qnil;
|
1551
|
+
}
|
1552
|
+
|
1553
|
+
/* Integrate histogram: the two histograms must have the same range and bins. */
|
1554
|
+
void mygsl_histogram_integrate(const gsl_histogram *h, gsl_histogram *hi,
|
1555
|
+
size_t istart, size_t iend)
|
1556
|
+
{
|
1557
|
+
size_t i;
|
1558
|
+
if (iend >= istart) {
|
1559
|
+
if (istart < 0) istart = 0;
|
1560
|
+
if (iend >= h->n) iend = h->n-1;
|
1561
|
+
hi->bin[istart] = h->bin[istart];
|
1562
|
+
for (i = istart+1; i <= iend; i++) hi->bin[i] = hi->bin[i-1] + h->bin[i];
|
1563
|
+
} else {
|
1564
|
+
if (istart >= h->n) istart = h->n-1;
|
1565
|
+
if (iend < 0) iend = 0;
|
1566
|
+
hi->bin[istart] = h->bin[istart];
|
1567
|
+
for (i = istart-1; i >= iend; i--) {
|
1568
|
+
hi->bin[i] = hi->bin[i+1] + h->bin[i];
|
1569
|
+
if (i == 0) break;
|
1570
|
+
}
|
1571
|
+
}
|
1572
|
+
}
|
1573
|
+
|
1574
|
+
void mygsl_histogram_differentiate(const gsl_histogram *hi, gsl_histogram *h)
|
1575
|
+
{
|
1576
|
+
size_t i;
|
1577
|
+
h->bin[0] = hi->bin[0];
|
1578
|
+
for (i = 1; i < hi->n; i++) h->bin[i] = hi->bin[i] - hi->bin[i-1];
|
1579
|
+
}
|
1580
|
+
|
1581
|
+
/* Create a histogram integrating the given histogram h */
|
1582
|
+
gsl_histogram* mygsl_histogram_calloc_integrate(const gsl_histogram *h,
|
1583
|
+
size_t istart, size_t iend)
|
1584
|
+
{
|
1585
|
+
gsl_histogram *hi = NULL;
|
1586
|
+
hi = gsl_histogram_calloc_range(h->n, h->range);
|
1587
|
+
mygsl_histogram_integrate(h, hi, istart, iend);
|
1588
|
+
return hi;
|
1589
|
+
}
|
1590
|
+
|
1591
|
+
gsl_histogram* mygsl_histogram_calloc_differentiate(const gsl_histogram *hi)
|
1592
|
+
{
|
1593
|
+
gsl_histogram *h = NULL;
|
1594
|
+
h = gsl_histogram_calloc_range(hi->n, hi->range);
|
1595
|
+
mygsl_histogram_differentiate(hi, h);
|
1596
|
+
return h;
|
1597
|
+
}
|
1598
|
+
|
1599
|
+
static VALUE rb_gsl_histogram_integrate(int argc, VALUE *argv, VALUE obj)
|
1600
|
+
{
|
1601
|
+
gsl_histogram *h, *hi;
|
1602
|
+
size_t istart, iend;
|
1603
|
+
int itmp;
|
1604
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1605
|
+
switch (argc) {
|
1606
|
+
case 2:
|
1607
|
+
istart = FIX2INT(argv[0]);
|
1608
|
+
iend = FIX2INT(argv[1]);
|
1609
|
+
break;
|
1610
|
+
case 1:
|
1611
|
+
switch (TYPE(argv[0])) {
|
1612
|
+
case T_ARRAY:
|
1613
|
+
istart = FIX2INT(rb_ary_entry(argv[0], 0));
|
1614
|
+
iend = FIX2INT(rb_ary_entry(argv[0], 1));
|
1615
|
+
break;
|
1616
|
+
case T_FIXNUM:
|
1617
|
+
itmp = FIX2INT(argv[0]);
|
1618
|
+
if (itmp == -1) {
|
1619
|
+
istart = h->n - 1;
|
1620
|
+
iend = 0;
|
1621
|
+
} else {
|
1622
|
+
istart = 0;
|
1623
|
+
iend = h->n - 1;
|
1624
|
+
}
|
1625
|
+
break;
|
1626
|
+
default:
|
1627
|
+
rb_raise(rb_eArgError, "wrong argument type %s (Arran or Fixnum expected)",
|
1628
|
+
rb_class2name(CLASS_OF(argv[0])));
|
1629
|
+
break;
|
1630
|
+
}
|
1631
|
+
break;
|
1632
|
+
case 0:
|
1633
|
+
istart = 0;
|
1634
|
+
iend = h->n - 1;
|
1635
|
+
break;
|
1636
|
+
default:
|
1637
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0-2)", argc);
|
1638
|
+
break;
|
1639
|
+
}
|
1640
|
+
hi = mygsl_histogram_calloc_integrate(h, istart, iend);
|
1641
|
+
return Data_Wrap_Struct(cgsl_histogram_integ, 0, gsl_histogram_free, hi);
|
1642
|
+
}
|
1643
|
+
|
1644
|
+
static VALUE rb_gsl_histogram_differentiate(VALUE obj)
|
1645
|
+
{
|
1646
|
+
gsl_histogram *h, *hi;
|
1647
|
+
Data_Get_Struct(obj, gsl_histogram, hi);
|
1648
|
+
h = mygsl_histogram_calloc_differentiate(hi);
|
1649
|
+
return Data_Wrap_Struct(cgsl_histogram, 0, gsl_histogram_free, h);
|
1650
|
+
}
|
1651
|
+
|
1652
|
+
static gsl_histogram* mygsl_histogram_rebin(const gsl_histogram *h, size_t m)
|
1653
|
+
{
|
1654
|
+
gsl_histogram *hnew;
|
1655
|
+
double w;
|
1656
|
+
size_t n, i, j, k;
|
1657
|
+
if (m > h->n) m = h->n;
|
1658
|
+
n = (size_t) h->n/m;
|
1659
|
+
if (n*m != h->n) n += 1;
|
1660
|
+
w = (h->range[h->n] - h->range[0])/h->n;
|
1661
|
+
hnew = gsl_histogram_alloc(n);
|
1662
|
+
for (i = 0, j = 0; i <= n; i++) {
|
1663
|
+
if (i*m <= h->n) hnew->range[i] = h->range[i*m];
|
1664
|
+
else hnew->range[i] = w*m*i;
|
1665
|
+
}
|
1666
|
+
for (i = 0, j = 0; i < n; i++) {
|
1667
|
+
hnew->bin[i] = 0;
|
1668
|
+
for (k = 0; k < m && j < h->n; k++) hnew->bin[i] += h->bin[j++];
|
1669
|
+
}
|
1670
|
+
return hnew;
|
1671
|
+
}
|
1672
|
+
|
1673
|
+
static VALUE rb_gsl_histogram_rebin(int argc, VALUE *argv, VALUE obj)
|
1674
|
+
{
|
1675
|
+
gsl_histogram *h, *hnew;
|
1676
|
+
size_t m = 2;
|
1677
|
+
switch (argc) {
|
1678
|
+
case 1:
|
1679
|
+
CHECK_FIXNUM(argv[0]);
|
1680
|
+
m = (size_t) FIX2INT(argv[0]);
|
1681
|
+
break;
|
1682
|
+
case 0:
|
1683
|
+
m = 2;
|
1684
|
+
break;
|
1685
|
+
default:
|
1686
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
1687
|
+
break;
|
1688
|
+
}
|
1689
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1690
|
+
hnew = mygsl_histogram_rebin(h, m);
|
1691
|
+
return Data_Wrap_Struct(cgsl_histogram, 0, gsl_histogram_free, hnew);
|
1692
|
+
}
|
1693
|
+
|
1694
|
+
static int mygsl_histogram_fread2(FILE * stream, gsl_histogram * h)
|
1695
|
+
{
|
1696
|
+
double min, max;
|
1697
|
+
int status;
|
1698
|
+
status = gsl_block_raw_fread(stream, &min, 1, 1);
|
1699
|
+
if (status) return status;
|
1700
|
+
status = gsl_block_raw_fread(stream, &max, 1, 1);
|
1701
|
+
if (status) return status;
|
1702
|
+
gsl_histogram_set_ranges_uniform(h, min, max);
|
1703
|
+
status = gsl_block_raw_fread (stream, h->bin, h->n, 1);
|
1704
|
+
if (status) return status;
|
1705
|
+
return status;
|
1706
|
+
}
|
1707
|
+
|
1708
|
+
static int mygsl_histogram_fwrite2(FILE * stream, const gsl_histogram * h)
|
1709
|
+
{
|
1710
|
+
int status;
|
1711
|
+
status = gsl_block_raw_fwrite (stream, h->range, 1, 1);
|
1712
|
+
if (status) return status;
|
1713
|
+
status = gsl_block_raw_fwrite (stream, h->range+h->n, 1, 1);
|
1714
|
+
if (status) return status;
|
1715
|
+
status = gsl_block_raw_fwrite (stream, h->bin, h->n, 1);
|
1716
|
+
return status;
|
1717
|
+
}
|
1718
|
+
|
1719
|
+
static VALUE rb_gsl_histogram_fwrite2(VALUE obj, VALUE io)
|
1720
|
+
{
|
1721
|
+
gsl_histogram *h = NULL;
|
1722
|
+
FILE *f;
|
1723
|
+
int status, flag = 0;
|
1724
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1725
|
+
f = rb_gsl_open_writefile(io, &flag);
|
1726
|
+
status = mygsl_histogram_fwrite2(f, h);
|
1727
|
+
if (flag == 1) fclose(f);
|
1728
|
+
return INT2FIX(status);
|
1729
|
+
}
|
1730
|
+
|
1731
|
+
static VALUE rb_gsl_histogram_fread2(VALUE obj, VALUE io)
|
1732
|
+
{
|
1733
|
+
gsl_histogram *h = NULL;
|
1734
|
+
FILE *f;
|
1735
|
+
int status, flag = 0;
|
1736
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1737
|
+
f = rb_gsl_open_readfile(io, &flag);
|
1738
|
+
status = mygsl_histogram_fread2(f, h);
|
1739
|
+
if (flag == 1) fclose(f);
|
1740
|
+
return INT2FIX(status);
|
1741
|
+
}
|
1742
|
+
|
1743
|
+
static gsl_histogram* mygsl_histogram_calloc_reverse(const gsl_histogram *h)
|
1744
|
+
{
|
1745
|
+
gsl_histogram *hnew;
|
1746
|
+
size_t i, n;
|
1747
|
+
hnew = gsl_histogram_alloc(h->n);
|
1748
|
+
n = h->n;
|
1749
|
+
for (i = 0; i <= n; i++) hnew->range[i] = h->range[n-i];
|
1750
|
+
for (i = 0; i < n; i++) hnew->bin[i] = h->bin[n-1-i];
|
1751
|
+
return hnew;
|
1752
|
+
}
|
1753
|
+
|
1754
|
+
static VALUE rb_gsl_histogram_reverse(VALUE obj)
|
1755
|
+
{
|
1756
|
+
gsl_histogram *h, *hnew;
|
1757
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1758
|
+
hnew = mygsl_histogram_calloc_reverse(h);
|
1759
|
+
return Data_Wrap_Struct(cgsl_histogram, 0, gsl_histogram_free, hnew);
|
1760
|
+
}
|
1761
|
+
|
1762
|
+
/* The functions below are not included in GSL */
|
1763
|
+
/*
|
1764
|
+
* Returns an x value at which the histogram integration
|
1765
|
+
* reaches the given percentile. The x value is calculated
|
1766
|
+
* by an interpolation between the ranges in which the percentile
|
1767
|
+
* is found.
|
1768
|
+
*/
|
1769
|
+
static double histogram_percentile(const gsl_histogram *h, double f)
|
1770
|
+
{
|
1771
|
+
double sum = gsl_histogram_sum(h), sf;
|
1772
|
+
double val, s = 0, x;
|
1773
|
+
double ri, ri1;
|
1774
|
+
size_t i;
|
1775
|
+
sf = sum * f;
|
1776
|
+
for (i = 0; i < h->n; i++) {
|
1777
|
+
val = gsl_histogram_get(h, i);
|
1778
|
+
if ((s+val) > sf) break;
|
1779
|
+
s += val;
|
1780
|
+
}
|
1781
|
+
ri = h->range[i];
|
1782
|
+
ri1 = h->range[i+1];
|
1783
|
+
x = (sf - s)*(ri1 - ri)/val + ri;
|
1784
|
+
return x;
|
1785
|
+
}
|
1786
|
+
|
1787
|
+
static double histogram_median(const gsl_histogram *h)
|
1788
|
+
{
|
1789
|
+
return histogram_percentile(h, 0.5);
|
1790
|
+
}
|
1791
|
+
|
1792
|
+
static VALUE rb_gsl_histogram_percentile(VALUE obj, VALUE f)
|
1793
|
+
{
|
1794
|
+
gsl_histogram *h;
|
1795
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1796
|
+
return rb_float_new(histogram_percentile(h, NUM2DBL(f)));
|
1797
|
+
}
|
1798
|
+
|
1799
|
+
static VALUE rb_gsl_histogram_median(VALUE obj)
|
1800
|
+
{
|
1801
|
+
gsl_histogram *h;
|
1802
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1803
|
+
return rb_float_new(histogram_median(h));
|
1804
|
+
}
|
1805
|
+
|
1806
|
+
static double histogram_percentile_inv(const gsl_histogram *h, double x)
|
1807
|
+
{
|
1808
|
+
double sum = gsl_histogram_sum(h);
|
1809
|
+
double val, s = 0;
|
1810
|
+
double ri, ri1, q;
|
1811
|
+
size_t i;
|
1812
|
+
|
1813
|
+
for (i = 0; i < h->n; i++) {
|
1814
|
+
val = gsl_histogram_get(h, i);
|
1815
|
+
if (h->range[i+1] > x) break;
|
1816
|
+
s += val;
|
1817
|
+
}
|
1818
|
+
ri = h->range[i];
|
1819
|
+
ri1 = h->range[i+1];
|
1820
|
+
q = s + val/(ri1 - ri)*(x - ri);
|
1821
|
+
return q/sum;
|
1822
|
+
}
|
1823
|
+
|
1824
|
+
static VALUE rb_gsl_histogram_percentile_inv(VALUE obj, VALUE x)
|
1825
|
+
{
|
1826
|
+
gsl_histogram *h;
|
1827
|
+
Data_Get_Struct(obj, gsl_histogram, h);
|
1828
|
+
return rb_float_new(histogram_percentile_inv(h, NUM2DBL(x)));
|
1829
|
+
}
|
1830
|
+
|
1831
|
+
void Init_gsl_histogram(VALUE module)
|
1832
|
+
{
|
1833
|
+
VALUE cgsl_histogram_pdf;
|
1834
|
+
|
1835
|
+
cgsl_histogram = rb_define_class_under(module, "Histogram", cGSL_Object);
|
1836
|
+
cgsl_histogram_range = rb_define_class_under(cgsl_histogram, "Range",
|
1837
|
+
cgsl_vector_view_ro);
|
1838
|
+
cgsl_histogram_bin = rb_define_class_under(cgsl_histogram, "Bin",
|
1839
|
+
cgsl_vector_view);
|
1840
|
+
cgsl_histogram_integ = rb_define_class_under(cgsl_histogram, "Integral",
|
1841
|
+
cgsl_histogram);
|
1842
|
+
|
1843
|
+
#ifdef GSL_0_9_4_LATER
|
1844
|
+
rb_define_singleton_method(cgsl_histogram, "alloc", rb_gsl_histogram_alloc, -1);
|
1845
|
+
/* rb_define_singleton_method(cgsl_histogram, "new", rb_gsl_histogram_alloc, -1);*/
|
1846
|
+
rb_define_singleton_method(cgsl_histogram, "[]", rb_gsl_histogram_alloc, -1);
|
1847
|
+
|
1848
|
+
rb_define_singleton_method(cgsl_histogram, "alloc_uniform",
|
1849
|
+
rb_gsl_histogram_alloc_uniform, -1);
|
1850
|
+
rb_define_singleton_method(cgsl_histogram, "new_uniform",
|
1851
|
+
rb_gsl_histogram_alloc_uniform, -1);
|
1852
|
+
|
1853
|
+
rb_define_singleton_method(cgsl_histogram, "alloc_with_min_max_step",
|
1854
|
+
rb_gsl_histogram_alloc_with_min_max_step, 3);
|
1855
|
+
rb_define_singleton_method(cgsl_histogram, "new_with_min_max_step",
|
1856
|
+
rb_gsl_histogram_alloc_with_min_max_step, 3);
|
1857
|
+
#endif
|
1858
|
+
|
1859
|
+
rb_define_singleton_method(cgsl_histogram, "calloc",
|
1860
|
+
rb_gsl_histogram_calloc, 1);
|
1861
|
+
rb_define_singleton_method(cgsl_histogram, "calloc_range",
|
1862
|
+
rb_gsl_histogram_calloc_range, -1);
|
1863
|
+
|
1864
|
+
rb_define_method(cgsl_histogram, "bins", rb_gsl_histogram_bins, 0);
|
1865
|
+
rb_define_alias(cgsl_histogram, "n", "bins");
|
1866
|
+
rb_define_alias(cgsl_histogram, "size", "bins");
|
1867
|
+
rb_define_method(cgsl_histogram, "set_ranges", rb_gsl_histogram_set_ranges, -1);
|
1868
|
+
rb_define_method(cgsl_histogram, "range", rb_gsl_histogram_range, 0);
|
1869
|
+
rb_define_method(cgsl_histogram, "bin", rb_gsl_histogram_bin, 0);
|
1870
|
+
rb_define_method(cgsl_histogram, "set_ranges_uniform",
|
1871
|
+
rb_gsl_histogram_set_ranges_uniform, -1);
|
1872
|
+
rb_define_singleton_method(cgsl_histogram, "memcpy", rb_gsl_histogram_memcpy, 2);
|
1873
|
+
rb_define_method(cgsl_histogram, "clone", rb_gsl_histogram_clone, 0);
|
1874
|
+
rb_define_alias(cgsl_histogram, "duplicate", "clone");
|
1875
|
+
rb_define_method(cgsl_histogram, "increment", rb_gsl_histogram_accumulate, -1);
|
1876
|
+
rb_define_alias(cgsl_histogram, "fill", "increment");
|
1877
|
+
rb_define_alias(cgsl_histogram, "accumulate", "increment");
|
1878
|
+
rb_define_method(cgsl_histogram, "increment2", rb_gsl_histogram_accumulate2, -1);
|
1879
|
+
rb_define_alias(cgsl_histogram, "accumulate2", "increment2");
|
1880
|
+
rb_define_alias(cgsl_histogram, "fill2", "increment2");
|
1881
|
+
|
1882
|
+
rb_define_method(cgsl_histogram, "get", rb_gsl_histogram_get, 1);
|
1883
|
+
rb_define_alias(cgsl_histogram, "[]", "get");
|
1884
|
+
rb_define_method(cgsl_histogram, "get_range", rb_gsl_histogram_get_range, 1);
|
1885
|
+
rb_define_method(cgsl_histogram, "max", rb_gsl_histogram_max, 0);
|
1886
|
+
rb_define_method(cgsl_histogram, "min", rb_gsl_histogram_min, 0);
|
1887
|
+
rb_define_method(cgsl_histogram, "reset", rb_gsl_histogram_reset, 0);
|
1888
|
+
rb_define_method(cgsl_histogram, "find", rb_gsl_histogram_find, 1);
|
1889
|
+
rb_define_method(cgsl_histogram, "max_val", rb_gsl_histogram_max_val, 0);
|
1890
|
+
rb_define_method(cgsl_histogram, "max_bin", rb_gsl_histogram_max_bin, 0);
|
1891
|
+
rb_define_method(cgsl_histogram, "min_val", rb_gsl_histogram_min_val, 0);
|
1892
|
+
rb_define_method(cgsl_histogram, "min_bin", rb_gsl_histogram_min_bin, 0);
|
1893
|
+
rb_define_method(cgsl_histogram, "mean", rb_gsl_histogram_mean, 0);
|
1894
|
+
rb_define_method(cgsl_histogram, "sigma", rb_gsl_histogram_sigma, 0);
|
1895
|
+
|
1896
|
+
rb_define_method(cgsl_histogram, "sum", rb_gsl_histogram_integral, -1);
|
1897
|
+
rb_define_alias(cgsl_histogram, "integral", "sum");
|
1898
|
+
|
1899
|
+
rb_define_method(cgsl_histogram, "equal_bins_p",
|
1900
|
+
rb_gsl_histogram_equal_bins_p, -1);
|
1901
|
+
rb_define_alias(cgsl_histogram, "equal_bins", "equal_bins_p");
|
1902
|
+
rb_define_singleton_method(cgsl_histogram, "equal_bins_p",
|
1903
|
+
rb_gsl_histogram_equal_bins_p, -1);
|
1904
|
+
rb_define_singleton_method(cgsl_histogram, "equal_bins",
|
1905
|
+
rb_gsl_histogram_equal_bins_p, -1);
|
1906
|
+
rb_define_method(cgsl_histogram, "equal_bins_p?",
|
1907
|
+
rb_gsl_histogram_equal_bins_p2, -1);
|
1908
|
+
rb_define_alias(cgsl_histogram, "equal_bins?", "equal_bins_p?");
|
1909
|
+
rb_define_singleton_method(cgsl_histogram, "equal_bins_p?",
|
1910
|
+
rb_gsl_histogram_equal_bins_p2, -1);
|
1911
|
+
rb_define_singleton_method(cgsl_histogram, "equal_bins?",
|
1912
|
+
rb_gsl_histogram_equal_bins_p2, -1);
|
1913
|
+
|
1914
|
+
rb_define_method(cgsl_histogram, "add", rb_gsl_histogram_add, 1);
|
1915
|
+
rb_define_alias(cgsl_histogram, "+", "add");
|
1916
|
+
rb_define_method(cgsl_histogram, "sub", rb_gsl_histogram_sub, 1);
|
1917
|
+
rb_define_alias(cgsl_histogram, "-", "sub");
|
1918
|
+
rb_define_method(cgsl_histogram, "mul", rb_gsl_histogram_mul, 1);
|
1919
|
+
rb_define_alias(cgsl_histogram, "*", "mul");
|
1920
|
+
rb_define_method(cgsl_histogram, "div", rb_gsl_histogram_div, 1);
|
1921
|
+
rb_define_alias(cgsl_histogram, "/", "div");
|
1922
|
+
|
1923
|
+
rb_define_method(cgsl_histogram, "add!", rb_gsl_histogram_add2, 1);
|
1924
|
+
rb_define_method(cgsl_histogram, "sub!", rb_gsl_histogram_sub2, 1);
|
1925
|
+
rb_define_method(cgsl_histogram, "mul!", rb_gsl_histogram_mul2, 1);
|
1926
|
+
rb_define_method(cgsl_histogram, "div!", rb_gsl_histogram_div2, 1);
|
1927
|
+
|
1928
|
+
rb_define_method(cgsl_histogram, "scale!", rb_gsl_histogram_scale_bang, -1);
|
1929
|
+
rb_define_method(cgsl_histogram, "scale", rb_gsl_histogram_scale, -1);
|
1930
|
+
rb_define_method(cgsl_histogram, "shift!", rb_gsl_histogram_shift, 1);
|
1931
|
+
rb_define_method(cgsl_histogram, "shift", rb_gsl_histogram_shift2, 1);
|
1932
|
+
|
1933
|
+
rb_define_method(cgsl_histogram, "fwrite", rb_gsl_histogram_fwrite, 1);
|
1934
|
+
rb_define_method(cgsl_histogram, "fread", rb_gsl_histogram_fread, 1);
|
1935
|
+
rb_define_method(cgsl_histogram, "fwrite2", rb_gsl_histogram_fwrite2, 1);
|
1936
|
+
rb_define_method(cgsl_histogram, "fread2", rb_gsl_histogram_fread2, 1);
|
1937
|
+
rb_define_method(cgsl_histogram, "fprintf", rb_gsl_histogram_fprintf, -1);
|
1938
|
+
rb_define_method(cgsl_histogram, "printf", rb_gsl_histogram_printf, -1);
|
1939
|
+
rb_define_method(cgsl_histogram, "fscanf", rb_gsl_histogram_fscanf, 1);
|
1940
|
+
rb_define_method(cgsl_histogram, "print", rb_gsl_histogram_print, 0);
|
1941
|
+
|
1942
|
+
cgsl_histogram_pdf = rb_define_class_under(cgsl_histogram, "Pdf", cGSL_Object);
|
1943
|
+
rb_define_singleton_method(cgsl_histogram_pdf, "alloc",
|
1944
|
+
rb_gsl_histogram_pdf_alloc, 1);
|
1945
|
+
/* rb_define_singleton_method(cgsl_histogram_pdf, "new",
|
1946
|
+
rb_gsl_histogram_pdf_alloc, 1);*/
|
1947
|
+
#ifdef GSL_0_9_4_LATER
|
1948
|
+
rb_define_method(cgsl_histogram_pdf, "init", rb_gsl_histogram_pdf_init, 1);
|
1949
|
+
#endif
|
1950
|
+
rb_define_method(cgsl_histogram_pdf, "sample", rb_gsl_histogram_pdf_sample, 1);
|
1951
|
+
|
1952
|
+
rb_define_method(cgsl_histogram_pdf, "range", rb_gsl_histogram_pdf_range, 0);
|
1953
|
+
rb_define_method(cgsl_histogram_pdf, "sum", rb_gsl_histogram_pdf_sum, 0);
|
1954
|
+
|
1955
|
+
/*****/
|
1956
|
+
rb_define_method(cgsl_histogram, "graph", rb_gsl_histogram_graph, -1);
|
1957
|
+
rb_define_alias(cgsl_histogram, "draw", "graph");
|
1958
|
+
|
1959
|
+
rb_define_method(cgsl_histogram, "plot", rb_gsl_histogram_plot, -1);
|
1960
|
+
|
1961
|
+
rb_define_method(cgsl_histogram, "fit_gaussian",
|
1962
|
+
rb_gsl_histogram_fit_gaussian, -1);
|
1963
|
+
rb_define_method(cgsl_histogram, "fit_exponential",
|
1964
|
+
rb_gsl_histogram_fit_exponential, -1);
|
1965
|
+
rb_define_method(cgsl_histogram, "fit_xexponential",
|
1966
|
+
rb_gsl_histogram_fit_xexponential, -1);
|
1967
|
+
rb_define_method(cgsl_histogram, "fit_power",
|
1968
|
+
rb_gsl_histogram_fit_power, -1);
|
1969
|
+
rb_define_method(cgsl_histogram, "fit_rayleigh",
|
1970
|
+
rb_gsl_histogram_fit_rayleigh, -1);
|
1971
|
+
rb_define_method(cgsl_histogram, "fit",
|
1972
|
+
rb_gsl_histogram_fit, -1);
|
1973
|
+
|
1974
|
+
rb_define_method(cgsl_histogram, "integrate", rb_gsl_histogram_integrate, -1);
|
1975
|
+
rb_undef_method(cgsl_histogram_integ, "integrate");
|
1976
|
+
rb_define_method(cgsl_histogram_integ, "differentiate",
|
1977
|
+
rb_gsl_histogram_differentiate, 0);
|
1978
|
+
rb_define_alias(cgsl_histogram_integ, "diff", "differentiate");
|
1979
|
+
|
1980
|
+
rb_define_method(cgsl_histogram, "normalize", rb_gsl_histogram_normalize, 0);
|
1981
|
+
rb_define_method(cgsl_histogram, "normalize!", rb_gsl_histogram_normalize_bang, 0);
|
1982
|
+
|
1983
|
+
rb_define_method(cgsl_histogram, "rebin", rb_gsl_histogram_rebin, -1);
|
1984
|
+
rb_define_alias(cgsl_histogram, "mergebin", "rebin");
|
1985
|
+
|
1986
|
+
rb_define_method(cgsl_histogram, "reverse", rb_gsl_histogram_reverse, 0);
|
1987
|
+
|
1988
|
+
rb_define_method(cgsl_histogram, "percentile", rb_gsl_histogram_percentile, 1);
|
1989
|
+
rb_define_method(cgsl_histogram, "median", rb_gsl_histogram_median, 0);
|
1990
|
+
rb_define_method(cgsl_histogram, "percentile_inv", rb_gsl_histogram_percentile_inv, 1);
|
1991
|
+
}
|