Title: Histograms

1 Singleton Methods

GSL::Histogram.new(n)
GSL::Histogram.new(n, [xmin, xmax])
GSL::Histogram.new(n, xmin, xmax)
GSL::Histogram.alloc(n)
Constructor for a histogram object with n bins
GSL::Histogram.equal_bins_p(h1, h2)

2 Methods

GSL::Histogram#set_ranges(v)
This sets the ranges of the existing histogram using a GSL::Vector object.
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)
GSL::Histogram#fill(x)
These methods updates the histogram self by adding one (1.0) to the bin whose range contains the coordinate x.
GSL::Histogram#accumulate(x, weight)
This method is similar to gsl_histogram_increment but increases the value of the appropriate bin in the histogram self by the floating-point number weight.
GSL::Histogram#get(i)
This returns the contents of the i-th bin of the histogram self.
GSL::Hiatogram#get_range(i)
This method finds the upper and lower range limits of the i-th bin of the histogram self, and returns an array [lower, upper].
GSL::Histogram#range
This returns a Vector::View object as a reference to the pointer double *range in the gsl_histogram struct.
GSL::Histogram#bin
This returns a Vector::View object to access the pointer double *bin in the gsl_histogram struct.
GSL::Histogram#max
GSL::Histogram#min
GSL::Histogram#bins
These methods return the maximum upper and minimum lower range limits and the number of bins of the histogram self.
GSL::Histogram#reset
This method resets all the bins in the histogram self to zero.
GSL::Histogram#find(x)
This method finds and sets the index i to the bin number which covers the coordinate x in the histogram self.
GSL::Histogram#max_val
This returns the maximum value contained in the histogram bins.
GSL::Histogram#max_bin
This returns the index of the bin containing the maximum value. In the case where several bins contain the same maximum value the smallest index is returned.
GSL::Histogram#min_val
This returns the minimum value contained in the histogram bins.
GSL::Histogram#min_bin
This returns the index of the bin containing the minimum value. In the case where several bins contain the same maximum value the smallest index is returned.
GSL::Histogram#mean
This returns the mean of the histogrammed variable, where the histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation. The accuracy of the result is limited by the bin width.
GSL::Histogram#sigma
This function returns the standard deviation of the histogrammed variable, where the histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation. The accuracy of the result is limited by the bin width.
GSL::Histogram#sum
This function returns the sum of all bin values. Negative bin values are included in the sum.

2.1 Histogram Operations

GSL::Histogram#add
GSL::Histogram#sub
GSL::Histogram#mul
GSL::Histogram#div
GSL::Histogram#scale
GSL::Histogram#scale!
GSL::Histogram#shift
GSL::Histogram#shift!

2.2 Reading and writing histograms

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)

3 The histogram probability distribution

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.

3.1 GSL::Histogram::Pdf class

GSL::Histogram::Pdf.new(n)
GSL::Histogram::Pdf.alloc(n)
Constructors
GSL::Histogram::Pdf#init(h)
This initializes the probability distribution self with the contents of the histogram 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
This returns the number of bins of the probability distribution function.
GSL::Histogram:Pdf#range
This returns a Vector::View object as a reference to the pointer double *range in the gsl_histogram_pdf struct.
GSL::Histogram:Pdf#sum
This returns a Vector::View object as a reference to the pointer double *sum in the gsl_histogram_pdf struct.

back