GSL::Histogram2d.new(nx, ny)GSL::Histogram2d.new(xrange, yrange)GSL::Histogram2d.new(nx, xmin, xmax, ny, ymin, ymax)GSL::Histogram2d.new(nx, [xmin, xmax], ny, [ymin, ymax])With sizes
irb(main):002:0> h2 = GSL::Histogram2d.alloc(2, 3) # size 6 irb(main):003:0> h2.xrange => GSL::Histogram::Range: [ 0.000e+00 1.000e+00 2.000e+00 ] irb(main):004:0> h2.yrange => GSL::Histogram::Range: [ 0.000e+00 1.000e+00 2.000e+00 3.000e+00 ] irb(main):005:0> h2.bin => GSL::Histogram::Bin: [ 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 ] irb(main):006:0> h2.xrange.class.superclass => GSL::Vector::View::ReadOnly irb(main):007:0> h2.bin.class.superclass => GSL::Vector::View::ReadOnly
With ranges
irb(main):006:0> h2 = Histogram2d.new([3, 6, 7], [2, 3, 8]) irb(main):007:0> h2.xrange => GSL::Histogram::Range: [ 3.000e+00 6.000e+00 7.000e+00 ] irb(main):008:0> h2.yrange => GSL::Histogram::Range: [ 2.000e+00 3.000e+00 8.000e+00 ] irb(main):009:0> h2.bin => GSL::Histogram::Bin: [ 0.000e+00 0.000e+00 0.000e+00 0.000e+00 ]
With sizes and ranges
irb(main):010:0> h2 = Histogram2d.new(4, [0, 4], 3, [1, 5]) irb(main):011:0> h2.xrange => GSL::Histogram::Range: [ 0.000e+00 1.000e+00 2.000e+00 3.000e+00 4.000e+00 ] irb(main):012:0> h2.yrange => GSL::Histogram::Range: [ 1.000e+00 2.333e+00 3.667e+00 5.000e+00 ]
GSL::Histogram2d.new_uniform(nx, xmin, xmax, ny, ymin, ymax)GSL::Histogram2d.alloc_uniform(nx, xmin, xmax, ny, ymin, ymax)GSL::Histogram2d.equal_bins_p(h1, h2)GSL::Histogram2d#set_ranges(vx, vy)GSL::Histogram2d#set_ranges_uniform(xmin, xmax, ymin, ymax)GSL::Histogram2d#cloneGSL::Histogram2d#duplicateGSL::Histogram2d#increment(x, y, weight = 1)GSL::Histogram2d#accumulate(x, y, weight = 1)GSL::Histogram2d#fill(x, y, weight = 1)GSL::Histogram2d#increment2(x, y, weight = 1)GSL::Histogram2d#accumulate2(x, y, weight = 1)GSL::Histogram2d#fill2(x, y, weight = 1)GSL::Histogram#increment/accumulate/fill,
but when (x,y) lies outside the limits of the histogram then the edge
bin is incremented.GSL::Histogram2d#get(i[, j])GSL::Histogram2d#[i, j]GSL::Histogram2d#get_xrange(i)GSL::Histogram2d#get_yrange(j)These methods find the upper and lower range limits of the i-th and j-th bins in the x and y directions of the histogram self.
Ex:
irb(main):030:0> h2 = Histogram2d.new(2, [0, 2], 3, [1, 4]) irb(main):031:0> h2.get_xrange(1) => [1.0, 2.0] irb(main):032:0> h2.get_yrange(1) => [2.0, 3.0]
GSL::Histogram2d#xrangeGSL::Histogram2d#yrangeVector::View objects.GSL::Histogram2d#xmaxGSL::Histogram2d#xminGSL::Histogram2d#ymaxGSL::Histogram2d#yminGSL::Histogram2d#nxGSL::Histogram2d#nyGSL::Histogram2d#resetGSL::Histogram2d#find(x, y)GSL::Histogram2d#max_valGSL::Histogram2d#max_binGSL::Histogram2d#min_valGSL::Histogram2d#min_binGSL::Histogram2d#xmeanGSL::Histogram2d#xsigmaGSL::Histogram2d#ymeanGSL::Histogram2d#ysigmaGSL::Histogram2d#covGSL::Histogram2d#sumGSL::Histogram2d#integralGSL::Histogram2d#addGSL::Histogram2d#subGSL::Histogram2d#mulGSL::Histogram2d#divGSL::Histogram2d#scale(val)GSL::Histogram2d#shift(val)GSL::Histogram2d#fwrite(io)GSL::Histogram2d#fwrite(filename)GSL::Histogram2d#fread(io)GSL::Histogram2d#fread(filename)GSL::Histogram2d#fprintf(io, range_format, bin_format)GSL::Histogram2d#fprintf(filename, range_format, bin_format)GSL::Histogram2d#fscanf(io)GSL::Histogram2d#fscanf(filename)GSL::Histogram2d#xproject(jstart = 0, jend = ny-1)GSL::Histogram object by projecting the 2D histogram
self onto the x-axis over the y-range from jstart to jend.GSL::Histogram2d#yproject(istart = 0, iend = nx-1)GSL::Histogram object by projecting the 2D histogram
self onto the y-axis over the x-range from istart to iend.GSL::Histogram2d::Pdf.new(nx, ny)GSL::Histogram2d::Pdf.alloc(nx, ny)GSL::Histogram2d::Pdf#init(h)GSL::Histogram2d::Pdf#sample(r1, r2)#!/usr/bin/env ruby
require("gsl")
N = 10000
BINS = 100
rng = Rng.new(2)
h2 = Histogram2d.new(BINS, [-5, 5], BINS, [-8, 8])
sig1 = 1.0
sig2 = 2.0
for i in 0...N do
r1 = rng.gaussian(sig1)
r2 = rng.gaussian(sig2)
h2.increment(r1, r2)
end
hx = h2.xproject
hy = h2.yproject
printf("%f %f %f %f\n", h2.xsigma, h2.ysigma, hx.sigma, hy.sigma)
GSL::graph(hx, hy, "-T X -C -g 3")