## File: Resampling-from-2D-histograms.html

package info (click to toggle)
gsl-ref-html 2.3-1
• area: non-free
• in suites: bullseye, buster, sid
• size: 6,876 kB
• ctags: 4,574
• sloc: makefile: 35
 file content (157 lines) | stat: -rw-r--r-- 8,148 bytes parent folder | download
 `123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157` `````` GNU Scientific Library – Reference Manual: Resampling from 2D histograms

23.21 Resampling from 2D histograms

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 (x,y) falls in the range of that bin. For a two-dimensional histogram the probability distribution takes the form p(x,y) dx dy where,

p(x,y) = n_{ij}/ (N A_{ij})

In this equation n_{ij} is the number of events in the bin which contains (x,y), A_{ij} is the area of the bin and N is the total number of events. The distribution of events within each bin is assumed to be uniform.

Data Type: gsl_histogram2d_pdf
size_t nx, ny

This is the number of histogram bins used to approximate the probability distribution function in the x and y directions.

double * xrange

The ranges of the bins in the x-direction are stored in an array of nx + 1 elements pointed to by xrange.

double * yrange

The ranges of the bins in the y-direction are stored in an array of ny + 1 pointed to by yrange.

double * sum

The 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.

Function: gsl_histogram2d_pdf * gsl_histogram2d_pdf_alloc (size_t nx, size_t ny)

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.

Function: int gsl_histogram2d_pdf_init (gsl_histogram2d_pdf * p, const gsl_histogram2d * h)

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.

Function: void gsl_histogram2d_pdf_free (gsl_histogram2d_pdf * p)

This function frees the two-dimensional probability distribution function p and all of the memory associated with it.

Function: int gsl_histogram2d_pdf_sample (const gsl_histogram2d_pdf * p, double r1, double r2, double * x, double * y)

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.

``````