GSL::Histogram.new(n)
GSL::Histogram.new(n, [xmin, xmax])
GSL::Histogram.new(n, xmin, xmax)
GSL::Histogram.alloc(n)
GSL::Histogram.alloc(array)
GSL::Histogram.alloc(vector)
Constructor for a histogram object with n bins.
Examples:
With an integer:
h = Histogram.alloc(4) <--- Histogram of 4 bins. The range is not defined yet. [ bin[0] )[ bin[1] )[ bin[2] )[ bin[3] ) |---------|---------|---------|---------| range[0] range[1] range[2] range[3] range[4]
With an array or a vector:
h = Histogram.new([1, 3, 7, 9, 20]) <--- Histogram of 4 bins. The range is initialized as range[0] = 1, range[1] = 3, ..., range[4] = 20.
With size and the range [min, max]:
irb(main):004:0> h = Histogram.alloc(5, [0, 5]) irb(main):005:0> h.range => GSL::Histogram::Range: [ 0.000e+00 1.000e+00 2.000e+00 3.000e+00 4.000e+00 5.000e+00 ] irb(main):006:0> h.bin => GSL::Histogram::Bin: [ 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 ] irb(main):007:0> h.increment(2.5) irb(main):008:0> h.bin => GSL::Histogram::Bin: [ 0.000e+00 0.000e+00 1.000e+00 0.000e+00 0.000e+00 ]
GSL::Histogram.alloc_uniform(n, min, max)
GSL::Histogram.alloc_uniform(n, [min, max])
GSL::Histogram.equal_bins_p(h1, h2)
GSL::Histogram.equal_bins(h1, h2)
GSL::Histogram.equal_bins_p?(h1, h2)
GSL::Histogram.equal_bins?(h1, h2)
GSL::Histogram#set_ranges(v)
GSL::Histogram#set_ranges_uniform(xmin, xmax)
GSL::Histogram#set_ranges_uniform([xmin, xmax])
This method sets the ranges of the existing histogram self to cover the range xmin to xmax uniformly. The values of the histogram bins are reset to zero. The bin ranges are shown as below,
bin[0] corresponds to xmin <= x < xmin + d bin[1] corresponds to xmin + d <= x < xmin + 2 d ...... bin[n-1] corresponds to xmin + (n-1)d <= x < xmax
where d is the bin spacing, d = (xmax-xmin)/n.
GSL::Histogram#increment(x, weight = 1)
GSL::Histogram#fill(x, weight = 1)
GSL::Histogram#accumulate(x, weight = 1)
GSL::Vector
or Array
, all the elements are filled into the histogram. If x is less than (greater than) the lower limit (upper limit) of the histogram then none of bins are modified.GSL::Histogram#increment2(x, weight = 1)
GSL::Histogram#fill2(x, weight = 1)
GSL::Histogram#accumulate2(x, weight = 1)
GSL::Histogram#get(i)
GSL::Histogram#[i]
GSL::Hiatogram#get_range(i)
GSL::Histogram#range
Vector::View
object as a reference to the pointer double *range
in the gsl_histogram
struct.GSL::Histogram#bin
Vector::View
object to access the pointer double *bin
in the gsl_histogram
struct.GSL::Histogram#max
GSL::Histogram#min
GSL::Histogram#bins
GSL::Histogram#reset
GSL::Histogram#find(x)
GSL::Histogram#max_val
GSL::Histogram#max_bin
GSL::Histogram#min_val
GSL::Histogram#min_bin
GSL::Histogram#mean
GSL::Histogram#sigma
GSL::Histogram#sum(istart = 0, iend = n-1)
GSL::Histogram#normalize
GSL::Histogram#rebin(m = 2)
This method creates a new histogram merging m bins in one in the histogram self. This method cannot be used for histograms of non-uniform bin size. If m is not an exact divider of the number of bins of self, the range of the rebinned histogram is extended not to lose the entries in the last m-1 (at most) bins.
Example: a histogram h of size 5 with the range [0, 5), binned as
GSL::Histogram::Range: [ 0.000e+00 1.000e+00 2.000e+00 3.000e+00 4.000e+00 5.000e+00 ] GSL::Histogram::Bin: [ 0.000e+00 3.000e+00 1.000e+00 1.000e+00 3.000e+00 ]
When a new histogram is created merging two bins into one as h2 = h.rebin
, then h2
looks like
GSL::Histogram::Range: [ 0.000e+00 2.000e+00 4.000e+00 6.000e+00 ] GSL::Histogram::Bin: [ 3.000e+00 2.000e+00 3.000e+00 ]
GSL::Histogram#reverse
GSL::Histogram#integrate(istart = 0, iend = n-1)
GSL::Histogram#integrate([istart, iend])
GSL::Histogram#integrate(direction = 1 or -1)
GSL::Histogram::Integral
object. If istart <= iend (or direction == 1), the i-th bin value of a GSL::Histogram::Integral
object hi created from a GSL::Histogram
h is given by hi[i] = hi[i-1] + h[i]
. If istart > iend (or direction == -1), hi[i] = hi[i+1] = h[i]
.GSL::Histogram::Integral#differentiate
GSL::Histogram::Integral#diff
GSL::Histogram#add(h2)
GSL::Histogram#sub(h2)
GSL::Histogram#mul(h2)
GSL::Histogram#div(h2)
GSL::Histogram#scale(val)
GSL::Histogram#shift(val)
GSL::Histogram#fwrite(io)
GSL::Histogram#fwrite(filename)
GSL::Histogram#fread(io)
GSL::Histogram#fread(filename)
GSL::Histogram#fprintf(io, range_format = "%e", bin_format = "%e")
GSL::Histogram#fprintf(filename, range_format = "%e", bin_format = "%e")
GSL::Histogram#fscanf(io)
GSL::Histogram#fscanf(filename)
GSL::Histogram#graph(options)
graph
to draw the histogram self. The options as "-T X -C -l x" etc are given by a String.GSL::Histogram#fit_exponential(binstart = 0, binend = n-1)
h[n] = a exp(b x[n])
using the bins of indices from binstart to binend. The result is returned as an Array of 6 elements, [a, b, erra, errb, sumsq, dof], where
GSL::Histogram#fit_power(binstart = 0, binend = n-1)
h[n] = a x[n]^b
using the bins of indices from binstart to binend. The result is returned as an Array of 6 elements, [a, b, erra, errb, sumsq, dof].GSL::Histogram#fit_gaussian(binstart = 0, binend = n-1)
This method fits the histogram self to Gaussian distribution using the bins of indices from binstart to binend, and returns an Array of 8 elements, [sigma, mean, height, errsig, errmean, errhei, sumsq, dof].
Example:
#!/usr/bin/env ruby require("gsl") N = 10000 MAX = 8 rng = Rng.alloc data = Ran.gaussian(rng, 1.5, N) + 2 h = Histogram.alloc(100, [-MAX, MAX]) h.increment(data) sigma, mean, height, = h.fit_gaussian x = Vector.linspace(-MAX, MAX, 100) y = height*Ran::gaussian_pdf(x-mean, sigma) GSL::graph(h, [x, y], "-T X -C -g 3")
The probability distribution function for a histogram consists of a set of bins which measure the probability of an event falling into a given range of a continuous variable x. A probability distribution function is defined by the following class, which actually stores the cumulative probability distribution function. This is the natural quantity for generating samples via the inverse transform method, because there is a one-to-one mapping between the cumulative probability distribution and the range [0,1]. It can be shown that by taking a uniform random number in this range and finding its corresponding coordinate in the cumulative probability distribution we obtain samples with the desired probability distribution.
GSL::Histogram::Pdf.new(n)
GSL::Histogram::Pdf.alloc(n)
GSL::Histogram::Pdf#init(h)
GSL::Histogram::Pdf#sample(r)
This method uses r, a uniform random number between zero and one, to compute a single random sample from the probability distribution self. The algorithm used to compute the sample s is given by the following formula,
s = range[i] + delta * (range[i+1] - range[i])
where i is the index which satisfies sum[i] <= r < sum[i+1]
and delta
is (r - sum[i])/(sum[i+1] - sum[i])
.
GSL::Histogram::Pdf#n
GSL::Histogram:Pdf#range
Vector::View
object as a reference to the pointer double *range
in the gsl_histogram_pdf
struct.GSL::Histogram:Pdf#sum
Vector::View
object as a reference to the pointer double *sum
in the gsl_histogram_pdf
struct.