Math::...gram2D(3pm)
okay bestie, welcome to the Math::...gram2D(3pm) manual page from User Contributed Perl Documentation β itβs giving Math::GSL::Histogram2D, and weβre about to make 2D histograms make sense πβ¨
πΈ NAME πΈ
Math::GSL::Histogram2D β Create and manipulate histograms of data in 2 dimensions π¦
π SYNOPSIS π
Hereβs the whole vibe, copied exactly:
use Math::GSL::Histogram2D qw/:all/;
# raw interface
my $H = gsl_histogram2d_alloc(100, 100);
gsl_histogram2d_set_ranges_uniform($H,0,101, 0, 101);
gsl_histogram2d_increment($H, -50, -12); # ignored
gsl_histogram2d_increment($H, 70 );
gsl_histogram2d_increment($H, 85.2 );
my $G = gsl_histogram2d_clone($H);
my $value = gsl_histogram2d_get($G, 70, 33);
my ($max,$min) = (gsl_histogram2d_min_val($H), gsl_histogram2d_max_val($H) );
my $sum = gsl_histogram2d_sum($H);
π DESCRIPTION π
This subsystem allows the creation and manipulation of 2D histograms. Currently, only a raw interface exists. periodt. π
gsl_histogram2d_alloc($nx, $ny)β This function allocates memory for a two-dimensional histogram with$nxbins in the x direction and$nybins in the y direction. The function returns a pointer to a newly createdgsl_histogram2dstruct. 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. β¨gsl_histogram2d_callocβ just listed, no extra description in the source. πgsl_histogram2d_calloc_uniformβ same, just a name drop. πgsl_histogram2d_free($h)β This function frees the 2D histogramhand all of the memory associated with it. π«Άgsl_histogram2d_increment($h, $xmin, $xmax, $ymin, $ymax)β This function sets the ranges of the existing histogram$hto cover the ranges$xminto$xmaxand$yminto$ymaxuniformly. The values of the histogram bins are reset to zero. π₯gsl_histogram2d_accumulate($h, $x, $y, $weight)β This function is similar togsl_histogram2d_incrementbut increases the value of the appropriate bin in the histogram$hby the floating-point number$weight. πgsl_histogram2d_find($h, $x, $y)β This function finds indicesiandjto 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($x,$y)is found then the function returnGSL_SUCCESS,iandjin this order. If($x,$y)lies outside the valid range of the histogram then the function returns$GSL_EDOMand the error handler is invoked. πgsl_histogram2d_get($h, $i, $j)β 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_EDOMand the function returns0. πgsl_histogram2d_get_xrange($h, $i)β This functions finds the upper and lower range limits of the$i-th in the x direction of the histogram$h. The range limits are stored in the returned values after0or1in this order :xlowerandxupper. 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 returns0as first value to indicate success. If$ilies outside the valid range of indices for the histogram then the error handler is called with an error code ofGSL_EDOM. πΈgsl_histogram2d_get_yrange($h, $j)β This functions finds the upper and lower range limits of the$j-th in the y direction of the histogram$h. The range limits are stored in the returned values after0or1in this order :ylowerandyupper. 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 returns0as first value to indicate success. If$jlies outside the valid range of indices for the histogram then the error handler is called with an error code ofGSL_EDOM. πΈgsl_histogram2d_xmax($h)β This functions returns the maximum upper range limit for the x direction of the histogram$h. πgsl_histogram2d_xmin($h)β This functions returns the minimum lower range limit for the x direction of the histogram$h. πgsl_histogram2d_nx($h)β This one gives you the number of bins for the x direction. βgsl_histogram2d_ymax($h)β This functions returns the maximum upper range limit for the y direction of the histogram$h. πgsl_histogram2d_ymin($h)β This functions returns the minimum lower range limit for the y direction of the histogram$h. πgsl_histogram2d_ny($h)β This one gives you the number of bins for the y direction. βgsl_histogram2d_reset($h)β This function resets all the bins of the histogram$hto zero. π§gsl_histogram2d_calloc_rangeβ just listed, no extra details in the source. πgsl_histogram2d_set_ranges($h, $xrange, $xsize, $yrange, $ysize)β This function sets the ranges of the existing histogram$husing the arrays$xrangeand$yrangeof size$xsizeand$ysizerespectively. The values of the histogram bins are reset to zero. πgsl_histogram2d_set_ranges_uniform($h, $xmin, $xmax, $ymin, $ymax)β This function sets the ranges of the existing histogram$hto cover the ranges$xminto$xmaxand$yminto$ymaxuniformly. The values of the histogram bins are reset to zero. πgsl_histogram2d_memcpy($dest, $src)β This function copies the histogram$srcinto the pre-existing histogram$dest, making$destinto an exact copy of$src. The two histograms must be of the same size. π«Άgsl_histogram2d_clone($src)β This function returns a pointer to a newly createdMath::GSL::Histogram2D::gsl_histogram2dwhich is an exact copy of the histogram$src.
NOTE: Ranges must be set with a function likegsl_histogram2d_set_ranges_uniformor this function will returnundef. π
gsl_histogram2d_max_val($h)</p> β the biggest value chillin' in any of the histogram bins. that's it, that's the whole vibe πgsl_histogram2d_max_bin($h)</p> β finds the indices of the bin holding the max value in$hand hands you back three things in this exact order:0if the op succeeded,1otherwise, theniandj. if multiple bins are tied for the max, it gives you the first one it found. no favorites, just first come first served β¨gsl_histogram2d_min_val($h)</p> β same energy as above but the smallest value in the bins π«Άgsl_histogram2d_min_bin($h)</p> β finds the indices of the bin with the min value in$h, returns0if it worked,1otherwise, theniandj. ties? first bin found wins, periodt πgsl_histogram2d_xmean($h)</p> β the mean of the histogrammed x variable, treating the histogram like a probability distribution. negative bin values get ignored for this calculation, so don't come crying about your negative bins πgsl_histogram2d_ymean($h)</p> β mean of the histogrammed y variable, histogram-as-probability-distribution style. negative bin values also ignored here, same rule πgsl_histogram2d_xsigma($h)</p> β the standard deviation of the histogrammed x variable, again pretending the histogram is a probability distribution. and yeah, negative bin values are ignored, we been knew πΈgsl_histogram2d_ysigma($h)</p> β standard deviation of the histogrammed y variable, probability-distribution treatment, negative bin values ignored. yes it's the same caveat every time, it's giving consistency πgsl_histogram2d_cov($h)</p> β the covariance of the histogrammed x and y variables, histogram = probability distribution. negative bin values ignored, as always πgsl_histogram2d_sum($h)</p> β the sum of all bin values. plot twist: negative bin values ARE included in this sum, unlike all those means and sigmas up there. it really said "no filtering" πgsl_histogram2d_equal_bins_p($h1, $h2)</p> β returns1if every single individual bin range in the two histograms is identical,0otherwise. vibe check passed or not, no in-between βgsl_histogram2d_add($h1, $h2)</p> β adds the contents of$h2's bins into the corresponding bins of$h1, i.e.h'_1(i,j) = h_1(i,j) + h_2(i,j). the two histograms must have identical bin ranges β no mix-and-matching bestie π₯gsl_histogram2d_sub($h1, $h2)</p> β subtracts$h2's bins from the corresponding bins of$h1, i.e.h'_1(i,j) = h_1(i,j) - h_2(i,j). again: identical bin ranges required, non-negotiable πgsl_histogram2d_mul($h1, $h2)</p> β multiplies the bins of$h1by the corresponding bins of$h2, i.e.h'_1(i,j) = h_1(i,j) * h_2(i,j). identical bin ranges. yes. again. it's the rule π¦gsl_histogram2d_div($h1, $h2)</p> β divides the bins of$h1by the corresponding bins of$h2, i.e.h'_1(i,j) = h_1(i,j) / h_2(i,j). and you guessed it, identical bin ranges required πgsl_histogram2d_scale($h, $scale)</p> β multiplies every bin of$hby the constant$scale, i.e.h'_1(i,j) = h_1(i,j) $scale. β¨gsl_histogram2d_shift($h, $offset)</p> β shifts every bin of$hby the constant$offset, i.e.h'_1(i,j) = h_1(i,j) + $offset. πgsl_histogram2d_fwrite($stream $h)</p> β writes the ranges and bins of$hto$streamin binary format.$streamgets opened with thegsl_fopenfunction from theMath::GSLmodule. returns0on success and$GSL_EFAILEDif something went wrong writing to the file. heads up: since it's native binary format, it is not necessarily portable between different architectures β this data does not travel well πgsl_histogram2d_fread($stream $h)</p> β reads into$hfrom$streamin binary format.$streamis opened withgsl_fopenfromMath::GSL.$hmust be preallocated with the correct size, because the function uses the number of x and y bins in$hto figure out how many bytes to read. returns0on success,$GSL_EFAILEDif reading failed. the data is assumed to have been written in native binary format on the same architecture β so same-machine energy only, bestie πgsl_histogram2d_fprintf($stream, $h, $range_format, $bin_format)</p> β writes the ranges and bins of$hline-by-line to$stream(opened withgsl_fopenfromMath::GSL) using the format specifiers$range_formatand$bin_format. those should be one of the%g,%eor%fformats for floating point numbers. returns0on success and$GSL_EFAILEDif the write went sideways.
the output gets formatted in five columns, separated by spaces, like so:
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)
every line has the lower and upper limits of the bin plus the contents of the bin. and yeah, since the upper limit of each bin is the lower limit of its neighbor, those values get duplicated β but that's on purpose, because it lets you manipulate the histogram with line-oriented tools. iconic design tbh π
gsl_histogram2d_fscanf($stream, $h)</p> β reads formatted data from$stream(opened withgsl_fopenfromMath::GSL) into the histogram$h. the data is assumed to be in the five-column format thatgsl_histogram2d_fprintfproduces.$hmust be preallocated with the correct lengths, because the function uses the sizes of$hto figure out how many numbers to read. returns0on success and$GSL_EFAILEDif there was a problem reading from the file π«Άgsl_histogram2d_pdf_alloc($nx, $ny)</p> β allocates memory for a two-dimensional probability distribution of size$nx-by-$nyand returns a pointer to a freshly initializedgsl_histogram2d_pdfstruct. if there isn't enough memory, a null pointer comes back and the error handler is invoked with an error code of$GSL_ENOMEM. π¬gsl_histogram2d_pdf_init($p, $h)</p> β initializes the two-dimensional probability distribution$pcalculated from the histogram$h. if any of$h's bins are negative, the error handler gets invoked with an error code ofGSL_EDOM, because a probability distribution simply cannot contain negative values. math said no πgsl_histogram2d_pdf_free($p)</p> β frees the two-dimensional probability distribution function$pand all the memory associated with it. clean up after yourself, bestie π§Ήgsl_histogram2d_pdf_sample($p, $r1, $r2)</p> β uses two uniform random numbers between zero and one,$r1and$r2, to compute a single random sample from the two-dimensional probability distributionp. returns0if it worked,1otherwise, followed by the x and y values of the sample. β¨
π AUTHORS π
Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com> β the two legends who built this whole thing, give them their flowers πΈπ
π COPYRIGHT AND LICENSE π
Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie, you made it to the end π₯³ this one shipped with perl v5.42.3, dated 2026-08-20 β go forth and histogram, 2D style πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libmath-gsl-perl 0.49-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms