Sha256: 25e466203ca704e49c919e9aaefaea45308bab8aad29fb4ad8c7188b68bf7df4

Contents?: true

Size: 507 Bytes

Versions: 6

Compression:

Stored size: 507 Bytes

Contents

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

NDATA = 1000
NBINS = 100
MAX = 8

rng = GSL::Rng.alloc()
data = GSL::Ran.gaussian(rng, 1.0, NDATA) + 2
h = GSL::Histogram.alloc(NBINS, [-MAX, MAX])
h.fill(data)

hpdf = GSL::Histogram::Pdf.alloc(h)

rng2 = GSL::Rng.alloc()
h2 = GSL::Histogram.alloc(NBINS, [-MAX, MAX])
NDATA2 = 10000
for i in 0...NDATA2 do
  val = hpdf.sample(rng2.uniform())
  h2.fill(val)
end

GSL::graph(h, h2)

sum = h.sum()      # NDATA
sum2 = h2.sum()    # NDATA2
GSL::graph(h, h2.scale(sum/sum2))

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
gsl-2.1.0.3 examples/histogram/histogram-pdf.rb
gsl-2.1.0.2 examples/histogram/histogram-pdf.rb
gsl-2.1.0.1 examples/histogram/histogram-pdf.rb
gsl-2.1.0 examples/histogram/histogram-pdf.rb
gsl-1.16.0.6 examples/histogram/histogram-pdf.rb
rb-gsl-1.16.0.5 examples/histogram/histogram-pdf.rb