Sha256: f0e996b764fe350dbefcc9db1d2df1df807fb150cfce5395eff2d2f88f351317

Contents?: true

Size: 717 Bytes

Versions: 22

Compression:

Stored size: 717 Bytes

Contents

#!/usr/bin/env ruby
require("gsl")
N = 10000
BINS = 100

rng = GSL::Rng.alloc("mt19937", 123456)

h2 = GSL::Histogram2d.alloc(BINS, [-8, 8], BINS, [-8, 8])

sig1 = 0.8
sig2 = 2.0

for i in 0...N do
  r1 = rng.gaussian(sig1) + 2.5
  r2 = rng.gaussian(sig2) - 1
  h2.increment(r1, r2)
end

hx = h2.xproject
hy = h2.yproject
printf("%f %f %f %f\n", h2.xmean, h2.ymean, hx.mean, hy.mean)
printf("%f %f %f %f\n", h2.xsigma, h2.ysigma, hx.sigma, hy.sigma)

x = GSL::Vector.linspace(-8, 8, 100)
result = hx.fit_gaussian
y1 = result[2]*GSL::Ran::gaussian_pdf(x-result[1], result[0])
result = hy.fit_gaussian
y2 = result[2]*GSL::Ran::gaussian_pdf(x-result[1], result[0])
GSL::graph(hx, hy, [x, y1], [x, y2], "-T X -C -g 3")


Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
gsl-2.1.0.3 examples/histogram/histo2d.rb
gsl-2.1.0.2 examples/histogram/histo2d.rb
gsl-2.1.0.1 examples/histogram/histo2d.rb
gsl-2.1.0 examples/histogram/histo2d.rb
gsl-1.16.0.6 examples/histogram/histo2d.rb
rb-gsl-1.16.0.5 examples/histogram/histo2d.rb
rb-gsl-1.16.0.4 examples/histogram/histo2d.rb
rb-gsl-1.16.0.3 examples/histogram/histo2d.rb
rb-gsl-1.16.0.3.rc1 examples/histogram/histo2d.rb
gsl-nmatrix-1.15.3.2 examples/histogram/histo2d.rb
gsl-nmatrix-1.15.3.1 examples/histogram/histo2d.rb
rb-gsl-1.16.0.2 examples/histogram/histo2d.rb
rb-gsl-1.16.0.1 examples/histogram/histo2d.rb
rb-gsl-1.16.0 examples/histogram/histo2d.rb
rb-gsl-1.15.3.2 examples/histogram/histo2d.rb
rb-gsl-1.15.3.1 examples/histogram/histo2d.rb
blackwinter-gsl-1.15.3.2 examples/histogram/histo2d.rb
gsl-nmatrix-1.15.3.0 examples/histogram/histo2d.rb
gsl-1.15.3 examples/histogram/histo2d.rb
gsl-1.14.7 examples/histogram/histo2d.rb