| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter describes functions for creating histograms. Histograms
provide a convenient way of summarizing the distribution of a set of
data. A histogram consists of a set of bins which count the number
of events falling into a given range of a continuous variable
.
In GSL the bins of a histogram contain floating-point numbers, so they
can be used to record both integer and non-integer distributions. The
bins can use arbitrary sets of ranges (uniformly spaced bins are the
default). Both one and two-dimensional histograms are supported.
Once a histogram has been created it can also be converted into a probability distribution function. The library provides efficient routines for selecting random samples from probability distributions. This can be useful for generating simulations based on real data.
The functions are declared in the header files ‘gsl_histogram.h’ and ‘gsl_histogram2d.h’.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A histogram is defined by the following struct,
size_t nThis is the number of histogram bins
double * rangeThe ranges of the bins are stored in an array of
elements
pointed to by range.
double * binThe counts for each bin are stored in an array of n elements pointed to by bin. The bins are floating-point numbers, so you can increment them by non-integer values if necessary.
The range for bin[i] is given by range[i] to
range[i+1]. For
bins there are
entries in the
array range. Each bin is inclusive at the lower end and exclusive
at the upper end. Mathematically this means that the bins are defined by
the following inequality,
Here is a diagram of the correspondence between ranges and bins on the
number-line for
,
[ bin[0] )[ bin[1] )[ bin[2] )[ bin[3] )[ bin[4] )
---|---------|---------|---------|---------|---------|--- x
r[0] r[1] r[2] r[3] r[4] r[5]
|
In this picture the values of the range array are denoted by
. On the left-hand side of each bin the square bracket
‘[’ denotes an inclusive lower bound
(
), and the round parentheses ‘)’ on the right-hand
side denote an exclusive upper bound (
). Thus any samples
which fall on the upper end of the histogram are excluded. If you want
to include this value for the last bin you will need to add an extra bin
to your histogram.
The gsl_histogram struct and its associated functions are defined
in the header file ‘gsl_histogram.h’.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The functions for allocating memory to a histogram follow the style of
malloc and free. In addition they also perform their own
error checking. If there is insufficient memory available to allocate a
histogram then the functions call the error handler (with an error
number of GSL_ENOMEM) in addition to returning a null pointer.
Thus if you use the library error handler to abort your program then it
isn't necessary to check every histogram alloc.
This function allocates memory for a histogram with n bins, and
returns a pointer to a newly created gsl_histogram struct. If
insufficient memory is available a null pointer is returned and the
error handler is invoked with an error code of GSL_ENOMEM. The
bins and ranges are not initialized, and should be prepared using one of
the range-setting functions below in order to make the histogram ready
for use.
This function sets the ranges of the existing histogram h using
the array range of size size. The values of the histogram
bins are reset to zero. The range array should contain the
desired bin limits. The ranges can be arbitrary, subject to the
restriction that they are monotonically increasing.
The following example shows how to create a histogram with logarithmic bins with ranges [1,10), [10,100) and [100,1000).
gsl_histogram * h = gsl_histogram_alloc (3);
/* bin[0] covers the range 1 <= x < 10 */
/* bin[1] covers the range 10 <= x < 100 */
/* bin[2] covers the range 100 <= x < 1000 */
double range[4] = { 1.0, 10.0, 100.0, 1000.0 };
gsl_histogram_set_ranges (h, range, 4);
|
Note that the size of the range array should be defined to be one element bigger than the number of bins. The additional element is required for the upper value of the final bin.
This function sets the ranges of the existing histogram h to cover
the range xmin to xmax uniformly. The values of the
histogram bins are reset to zero. The bin ranges are shown in the table
below,
where
is the bin spacing,
.
This function frees the histogram h and all of the memory associated with it.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function copies the histogram src into the pre-existing histogram dest, making dest into an exact copy of src. The two histograms must be of the same size.
This function returns a pointer to a newly created histogram which is an exact copy of the histogram src.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
There are two ways to access histogram bins, either by specifying an
coordinate or by using the bin-index directly. The functions
for accessing the histogram through
coordinates use a binary
search to identify the bin which covers the appropriate range.
This function updates the histogram h by adding one (1.0) to the bin whose range contains the coordinate x.
If x lies in the valid range of the histogram then the function
returns zero to indicate success. If x is less than the lower
limit of the histogram then the function returns GSL_EDOM, and
none of bins are modified. Similarly, if the value of x is greater
than or equal to the upper limit of the histogram then the function
returns GSL_EDOM, and none of the bins are modified. The error
handler is not called, however, since it is often necessary to compute
histograms for a small range of a larger dataset, ignoring the values
outside the range of interest.
This function is similar to gsl_histogram_increment but increases
the value of the appropriate bin in the histogram h by the
floating-point number weight.
This function returns the contents of the i-th bin of the histogram
h. If i lies outside the valid range of indices for the
histogram then the error handler is called with an error code of
GSL_EDOM and the function returns 0.
This function finds the upper and lower range limits of the i-th
bin of the histogram h. If the index i is valid then the
corresponding range limits are stored in lower and upper.
The lower limit is inclusive (i.e. events with this coordinate are
included in the bin) and the upper limit is exclusive (i.e. events with
the coordinate of the upper limit are excluded and fall in the
neighboring higher bin, if it exists). The function returns 0 to
indicate success. If i lies outside the valid range of indices for
the histogram then the error handler is called and the function returns
an error code of GSL_EDOM.
These functions return the maximum upper and minimum lower range limits
and the number of bins of the histogram h. They provide a way of
determining these values without accessing the gsl_histogram
struct directly.
This function resets all the bins in the histogram h to zero.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following functions are used by the access and update routines to
locate the bin which corresponds to a given
coordinate.
This function finds and sets the index i to the bin number which
covers the coordinate x in the histogram h. The bin is
located using a binary search. The search includes an optimization for
histograms with uniform range, and will return the correct bin
immediately in this case. If x is found in the range of the
histogram then the function sets the index i and returns
GSL_SUCCESS. If x lies outside the valid range of the
histogram then the function returns GSL_EDOM and the error
handler is invoked.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function returns the maximum value contained in the histogram bins.
This function 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.
This function returns the minimum value contained in the histogram bins.
This function 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.
This function 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.
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.
This function returns the sum of all bin values. Negative bin values are included in the sum.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function returns 1 if the all of the individual bin ranges of the two histograms are identical, and 0 otherwise.
This function adds the contents of the bins in histogram h2 to the
corresponding bins of histogram h1, i.e.
. The two histograms must have identical bin ranges.
This function subtracts the contents of the bins in histogram h2
from the corresponding bins of histogram h1, i.e.
. The two histograms must have identical bin ranges.
This function multiplies the contents of the bins of histogram h1
by the contents of the corresponding bins in histogram h2,
i.e.
. The two histograms must have
identical bin ranges.
This function divides the contents of the bins of histogram h1 by
the contents of the corresponding bins in histogram h2,
i.e.
. The two histograms must have
identical bin ranges.
This function multiplies the contents of the bins of histogram h
by the constant scale, i.e.
.
This function shifts the contents of the bins of histogram h by
the constant offset, i.e.
.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The library provides functions for reading and writing histograms to a file as binary data or formatted text.
This function writes the ranges and bins of the histogram h to the
stream stream in binary format. The return value is 0 for success
and GSL_EFAILED if there was a problem writing to the file. Since
the data is written in the native binary format it may not be portable
between different architectures.
This function reads into the histogram h from the open stream
stream in binary format. The histogram h must be
preallocated with the correct size since the function uses the number of
bins in h to determine how many bytes to read. The return value is
0 for success and GSL_EFAILED if there was a problem reading from
the file. The data is assumed to have been written in the native binary
format on the same architecture.
This function writes the ranges and bins of the histogram h
line-by-line to the stream stream using the format specifiers
range_format and bin_format. These should be one of the
%g, %e or %f formats for floating point
numbers. The function returns 0 for success and GSL_EFAILED if
there was a problem writing to the file. The histogram output is
formatted in three columns, and the columns are separated by spaces,
like this,
range[0] range[1] bin[0] range[1] range[2] bin[1] range[2] range[3] bin[2] .... range[n-1] range[n] bin[n-1] |
The values of the ranges are formatted using range_format and the value of the bins are formatted using bin_format. Each line contains the lower and upper limit of the range of the bins and the value of the bin itself. Since the upper limit of one bin is the lower limit of the next there is duplication of these values between lines but this allows the histogram to be manipulated with line-oriented tools.
This function reads formatted data from the stream stream into the
histogram h. The data is assumed to be in the three-column format
used by gsl_histogram_fprintf. The histogram h must be
preallocated with the correct length since the function uses the size of
h to determine how many numbers to read. The function returns 0
for success and GSL_EFAILED if there was a problem reading from
the file.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A histogram made by counting events can be regarded as a measurement of
a probability distribution. Allowing for statistical error, the height
of each bin represents the probability of an event where the value of
falls in the range of that bin. The probability distribution
function has the one-dimensional form
where,
In this equation
is the number of events in the bin which
contains
,
is the width of the bin and
is
the total number of events. The distribution of events within each bin
is assumed to be uniform.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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
. A probability
distribution function is defined by the following struct, 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.
size_t nThis is the number of bins used to approximate the probability distribution function.
double * rangeThe ranges of the bins are stored in an array of
elements
pointed to by range.
double * sumThe cumulative probability for the bins is stored in an array of n elements pointed to by sum.
The following functions allow you to create a gsl_histogram_pdf
struct which represents this probability distribution and generate
random samples from it.
This function allocates memory for a probability distribution with
n bins and returns a pointer to a newly initialized
gsl_histogram_pdf struct. If insufficient memory is available a
null pointer is returned and the error handler is invoked with an error
code of GSL_ENOMEM.
This function initializes the probability distribution p with
the contents of the histogram h. If any of the bins of h are
negative then the error handler is invoked with an error code of
GSL_EDOM because a probability distribution cannot contain
negative values.
This function frees the probability distribution function p and all of the memory associated with it.
This function uses r, a uniform random number between zero and
one, to compute a single random sample from the probability distribution
p. The algorithm used to compute the sample
is given by
the following formula,
where
is the index which satisfies
and
is
.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following program shows how to make a simple histogram of a column
of numerical data supplied on stdin. The program takes three
arguments, specifying the upper and lower bounds of the histogram and
the number of bins. It then reads numbers from stdin, one line at
a time, and adds them to the histogram. When there is no more data to
read it prints out the accumulated histogram using
gsl_histogram_fprintf.
|
Here is an example of the program in use. We generate 10000 random samples from a Cauchy distribution with a width of 30 and histogram them over the range -100 to 100, using 200 bins.
$ gsl-randist 0 10000 cauchy 30 | gsl-histogram -100 100 200 > histogram.dat |
A plot of the resulting histogram shows the familiar shape of the Cauchy distribution and the fluctuations caused by the finite sample size.
$ awk '{print $1, $3 ; print $2, $3}' histogram.dat
| graph -T X
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A two dimensional histogram consists of a set of bins which count
the number of events falling in a given area of the
plane. The simplest way to use a two dimensional histogram is to record
two-dimensional position information,
. Another possibility
is to form a joint distribution by recording related
variables. For example a detector might record both the position of an
event (
) and the amount of energy it deposited
. These
could be histogrammed as the joint distribution
.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Two dimensional histograms are defined by the following struct,
size_t nx, nyThis is the number of histogram bins in the x and y directions.
double * xrangeThe ranges of the bins in the x-direction are stored in an array of
elements pointed to by xrange.
double * yrangeThe ranges of the bins in the y-direction are stored in an array of
elements pointed to by yrange.
double * binThe counts for each bin are stored in an array pointed to by bin.
The bins are floating-point numbers, so you can increment them by
non-integer values if necessary. The array bin stores the two
dimensional array of bins in a single block of memory according to the
mapping bin(i,j) = bin[i * ny + j].
The range for bin(i,j) is given by xrange[i] to
xrange[i+1] in the x-direction and yrange[j] to
yrange[j+1] in the y-direction. Each bin is inclusive at the lower
end and exclusive at the upper end. Mathematically this means that the
bins are defined by the following inequality,
Note that any samples which fall on the upper sides of the histogram are
excluded. If you want to include these values for the side bins you will
need to add an extra row or column to your histogram.
The gsl_histogram2d struct and its associated functions are
defined in the header file ‘gsl_histogram2d.h’.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The functions for allocating memory to a 2D histogram follow the style
of malloc and free. In addition they also perform their
own error checking. If there is insufficient memory available to
allocate a histogram then the functions call the error handler (with
an error number of GSL_ENOMEM) in addition to returning a null
pointer. Thus if you use the library error handler to abort your program
then it isn't necessary to check every 2D histogram alloc.
This function allocates memory for a two-dimensional histogram with
nx bins in the x direction and ny bins in the y direction.
The function returns a pointer to a newly created gsl_histogram2d
struct. If insufficient memory is available a null pointer is returned
and the error handler is invoked with an error code of
GSL_ENOMEM. The bins and ranges must be initialized with one of
the functions below before the histogram is ready for use.
This function sets the ranges of the existing histogram h using the arrays xrange and yrange of size xsize and ysize respectively. The values of the histogram bins are reset to zero.
This function sets the ranges of the existing histogram h to cover the ranges xmin to xmax and ymin to ymax uniformly. The values of the histogram bins are reset to zero.
This function frees the 2D histogram h and all of the memory associated with it.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function copies the histogram src into the pre-existing histogram dest, making dest into an exact copy of src. The two histograms must be of the same size.
This function returns a pointer to a newly created histogram which is an exact copy of the histogram src.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You can access the bins of a two-dimensional histogram either by
specifying a pair of
coordinates or by using the bin
indices
directly. The functions for accessing the histogram
through
coordinates use binary searches in the x and y
directions to identify the bin which covers the appropriate range.
This function updates the histogram h by adding one (1.0) to the bin whose x and y ranges contain the coordinates (x,y).
If the point
lies inside the valid ranges of the
histogram then the function returns zero to indicate success. If
lies outside the limits of the histogram then the
function returns GSL_EDOM, and none of the bins are modified. The
error handler is not called, since it is often necessary to compute
histograms for a small range of a larger dataset, ignoring any
coordinates outside the range of interest.
This function is similar to gsl_histogram2d_increment but increases
the value of the appropriate bin in the histogram h by the
floating-point number weight.
This function returns the contents of the (i,j)-th bin of the
histogram h. If (i,j) lies outside the valid range of
indices for the histogram then the error handler is called with an error
code of GSL_EDOM and the function returns 0.
These functions find the upper and lower range limits of the i-th
and j-th bins in the x and y directions of the histogram h.
The range limits are stored in xlower and xupper or
ylower and yupper. The lower limits are inclusive
(i.e. events with these coordinates are included in the bin) and the
upper limits are exclusive (i.e. events with the value of the upper
limit are not included and fall in the neighboring higher bin, if it
exists). The functions return 0 to indicate success. If i or
j lies outside the valid range of indices for the histogram then
the error handler is called with an error code of GSL_EDOM.
These functions return the maximum upper and minimum lower range limits
and the number of bins for the x and y directions of the histogram
h. They provide a way of determining these values without
accessing the gsl_histogram2d struct directly.
This function resets all the bins of the histogram h to zero.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following functions are used by the access and update routines to
locate the bin which corresponds to a given
coordinate.
This function finds and sets the indices i and j to the to
the bin which covers the coordinates (x,y). The bin is
located using a binary search. The search includes an optimization for
histograms with uniform ranges, and will return the correct bin immediately
in this case. If
is found then the function sets the
indices (i,j) and returns GSL_SUCCESS. If
lies outside the valid range of the histogram then the
function returns GSL_EDOM and the error handler is invoked.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function returns the maximum value contained in the histogram bins.
This function finds the indices of the bin containing the maximum value in the histogram h and stores the result in (i,j). In the case where several bins contain the same maximum value the first bin found is returned.
This function returns the minimum value contained in the histogram bins.
This function finds the indices of the bin containing the minimum value in the histogram h and stores the result in (i,j). In the case where several bins contain the same maximum value the first bin found is returned.
This function returns the mean of the histogrammed x variable, where the histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation.
This function returns the mean of the histogrammed y variable, where the histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation.
This function returns the standard deviation of the histogrammed x variable, where the histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation.
This function returns the standard deviation of the histogrammed y variable, where the histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation.
This function returns the covariance of the histogrammed x and y variables, where the histogram is regarded as a probability distribution. Negative bin values are ignored for the purposes of this calculation.
This function returns the sum of all bin values. Negative bin values are included in the sum.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function returns 1 if all the individual bin ranges of the two histograms are identical, and 0 otherwise.
This function adds the contents of the bins in histogram h2 to the
corresponding bins of histogram h1,
i.e.
.
The two histograms must have identical bin ranges.
This function subtracts the contents of the bins in histogram h2 from the
corresponding bins of histogram h1,
i.e.
.
The two histograms must have identical bin ranges.
This function multiplies the contents of the bins of histogram h1
by the contents of the corresponding bins in histogram h2,
i.e.
.
The two histograms must have identical bin ranges.
This function divides the contents of the bins of histogram h1
by the contents of the corresponding bins in histogram h2,
i.e.
.
The two histograms must have identical bin ranges.
This function multiplies the contents of the bins of histogram h
by the constant scale, i.e.
.
This function shifts the contents of the bins of histogram h
by the constant offset, i.e.
.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The library provides functions for reading and writing two dimensional histograms to a file as binary data or formatted text.
This function writes the ranges and bins of the histogram h to the
stream stream in binary format. The return value is 0 for success
and GSL_EFAILED if there was a problem writing to the file. Since
the data is written in the native binary format it may not be portable
between different architectures.
This function reads into the histogram h from the stream
stream in binary format. The histogram h must be
preallocated with the correct size since the function uses the number of
x and y bins in h to determine how many bytes to read. The return
value is 0 for success and GSL_EFAILED if there was a problem
reading from the file. The data is assumed to have been written in the
native binary format on the same architecture.
This function writes the ranges and bins of the histogram h
line-by-line to the stream stream using the format specifiers
range_format and bin_format. These should be one of the
%g, %e or %f formats for floating point
numbers. The function returns 0 for success and GSL_EFAILED if
there was a problem writing to the file. The histogram output is
formatted in five columns, and the columns are separated by spaces,
like this,
xrange[0] xrange[1] yrange[0] yrange[1] bin(0,0) xrange[0] xrange[1] yrange[1] yrange[2] bin(0,1) xrange[0] xrange[1] yrange[2] yrange[3] bin(0,2) .... xrange[0] xrange[1] yrange[ny-1] yrange[ny] bin(0,ny-1) xrange[1] xrange[2] yrange[0] yrange[1] bin(1,0) xrange[1] xrange[2] yrange[1] yrange[2] bin(1,1) xrange[1] xrange[2] yrange[1] yrange[2] bin(1,2) .... xrange[1] xrange[2] yrange[ny-1] yrange[ny] bin(1,ny-1) .... xrange[nx-1] xrange[nx] yrange[0] yrange[1] bin(nx-1,0) xrange[nx-1] xrange[nx] yrange[1] yrange[2] bin(nx-1,1) xrange[nx-1] xrange[nx] yrange[1] yrange[2] bin(nx-1,2) .... xrange[nx-1] xrange[nx] yrange[ny-1] yrange[ny] bin(nx-1,ny-1) |
Each line contains the lower and upper limits of the bin and the contents of the bin. Since the upper limits of the each bin are the lower limits of the neighboring bins there is duplication of these values but this allows the histogram to be manipulated with line-oriented tools.
This function reads formatted data from the stream stream into the
histogram h. The data is assumed to be in the five-column format
used by gsl_histogram_fprintf. The histogram h must be
preallocated with the correct lengths since the function uses the sizes
of h to determine how many numbers to read. The function returns 0
for success and GSL_EFAILED if there was a problem reading from
the file.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
As in the one-dimensional case, a two-dimensional histogram made by
counting events can be regarded as a measurement of a probability
distribution. Allowing for statistical error, the height of each bin
represents the probability of an event where (
,
) falls in
the range of that bin. For a two-dimensional histogram the probability
distribution takes the form
where,
In this equation
is the number of events in the bin which
contains
,
is the area of the bin and
is
the total number of events. The distribution of events within each bin
is assumed to be uniform.
size_t nx, nyThis is the number of histogram bins used to approximate the probability distribution function in the x and y directions.
double * xrangeThe ranges of the bins in the x-direction are stored in an array of
elements pointed to by xrange.
double * yrangeThe ranges of the bins in the y-direction are stored in an array of
pointed to by yrange.
double * sumThe cumulative probability for the bins is stored in an array of nx*ny elements pointed to by sum.
The following functions allow you to create a gsl_histogram2d_pdf
struct which represents a two dimensional probability distribution and
generate random samples from it.
This function allocates memory for a two-dimensional probability
distribution of size nx-by-ny and returns a pointer to a
newly initialized gsl_histogram2d_pdf struct. If insufficient
memory is available a null pointer is returned and the error handler is
invoked with an error code of GSL_ENOMEM.
This function initializes the two-dimensional probability distribution
calculated p from the histogram h. If any of the bins of
h are negative then the error handler is invoked with an error
code of GSL_EDOM because a probability distribution cannot
contain negative values.
This function frees the two-dimensional probability distribution function p and all of the memory associated with it.
This function uses two uniform random numbers between zero and one, r1 and r2, to compute a single random sample from the two-dimensional probability distribution p.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This program demonstrates two features of two-dimensional histograms. First a 10-by-10 two-dimensional histogram is created with x and y running from 0 to 1. Then a few sample points are added to the histogram, at (0.3,0.3) with a height of 1, at (0.8,0.1) with a height of 5 and at (0.7,0.9) with a height of 0.5. This histogram with three events is used to generate a random sample of 1000 simulated events, which are printed out.
|
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by Autobuild on September, 26 2007 using texi2html 1.78.