Sha256: 248181252b95e13a2b37c44f0dc5c6531617e093257b335246f2dc6dd954aaf5

Contents?: true

Size: 830 Bytes

Versions: 16

Compression:

Stored size: 830 Bytes

Contents

#!/usr/bin/env ruby
require("gsl")

N = 5000
BINS = 50
rng = GSL::Rng.alloc(1)

h = GSL::Histogram3d.alloc(BINS, [-5, 5], BINS, [-4, 8], BINS, [-8, 3]) 
sig1 = 1
sig2 = 2
sig3 = 1.3

for i in 0...N do
  r1 = rng.gaussian(sig1) + 1
  r2 = rng.gaussian(sig2) + 1.5
  r3 = rng.gaussian(sig3) - 2
  h.increment(r1, r2, r3)
end

hxy = h.xyproject
h1 = hxy.xproject
h2 = hxy.yproject
hxz = h.xzproject
h3 = hxz.yproject

x = GSL::Vector.linspace(-7, 7, 100)
a = h1.fit_gaussian   # a[0]: sigma, a[1]: mean, a[2]: height
y1 = a[2]*GSL::Ran::gaussian_pdf(x-a[1], a[0])
a = h2.fit_gaussian   # a[0]: sigma, a[1]: mean, a[2]: height
y2 = a[2]*GSL::Ran::gaussian_pdf(x-a[1], a[0])
a = h3.fit_gaussian   # a[0]: sigma, a[1]: mean, a[2]: height
y3 = a[2]*GSL::Ran::gaussian_pdf(x-a[1], a[0])

GSL::graph(h1, h2, h3, [x, y1], [x, y2], [x, y3])

Version data entries

16 entries across 16 versions & 4 rubygems

Version Path
rb-gsl-1.16.0.4 examples/histogram/histo3d.rb
rb-gsl-1.16.0.3 examples/histogram/histo3d.rb
rb-gsl-1.16.0.3.rc1 examples/histogram/histo3d.rb
gsl-nmatrix-1.15.3.2 examples/histogram/histo3d.rb
gsl-nmatrix-1.15.3.1 examples/histogram/histo3d.rb
rb-gsl-1.16.0.2 examples/histogram/histo3d.rb
rb-gsl-1.16.0.1 examples/histogram/histo3d.rb
rb-gsl-1.16.0 examples/histogram/histo3d.rb
rb-gsl-1.15.3.2 examples/histogram/histo3d.rb
rb-gsl-1.15.3.1 examples/histogram/histo3d.rb
blackwinter-gsl-1.15.3.2 examples/histogram/histo3d.rb
gsl-nmatrix-1.15.3.0 examples/histogram/histo3d.rb
gsl-1.15.3 examples/histogram/histo3d.rb
gsl-1.14.7 examples/histogram/histo3d.rb
gsl-1.14.6 examples/histogram/histo3d.rb
gsl-1.14.5 examples/histogram/histo3d.rb