Hey all -

That error message is in the current version of
PDL<http://sourceforge.net/p/pdl/code/ci/master/tree/Basic/Core/Basic.pm#l504>and
is not related to the recent fixes to the bin size type that Chris
mentions. The problem arises when the min and max of your data are
identical. For good data, this usually means that every value in your
piddle is the same.

I encountered this problem when working on PDL::Graphics::Prima and
ultimately solved it by implementing a function called
min_max_for_degenerate<https://github.com/run4flat/PDL-Graphics-Prima/blob/master/lib/PDL/Graphics/Prima/Scaling.pm#L36>,
which takes a given value and returns a sensible min and max for purposes
of plotting. Note that it is difficult for hist() to solve this problem
because a sensible min/max depends on the axis scaling. For example,
logarithmic axes perform a different
calculation<https://github.com/run4flat/PDL-Graphics-Prima/blob/master/lib/PDL/Graphics/Prima/Scaling.pm#L201>than
linear axes. Since hist() provides linearly binned data, it seems
sensible to me that we could have it use a calculation similar to
min_max_for_degenerate<https://github.com/run4flat/PDL-Graphics-Prima/blob/master/lib/PDL/Graphics/Prima/Scaling.pm#L36>for
linear scaling. I would be happy to add similar code to PDL::Basic's
hist() if others think it's a good idea.

So, barring such an update, how do you detect this? You simply ask for the
piddle's minmax and see if they are equal:

----%<----
use Carp;
my ($data_min, $data_max) = $data->minmax;
if ($data_min == $data_max) {
    carp('All (good) data are identical!');
}
else {
    bin hist $data;
}
---->%----

That said, I know that at least one plotting library (mine) will properly
handle a degenerate distribution, and I suspect that Gnuplot will also
handle this scenario. I'll let Craig or Dima chime in with how to handle
this with Gnuplot.

With PDL::Graphics::Prima, you can just send your data to the plotting
library and it will detect a degenerate distribution and give a mostly
sensible result:

----%<----
use PDL::Graphics::Prima::Simple;
hist_plot($data);
---->%----

I say mostly sensible because the default behavior is to normalize the bin
heights so that the integral of the histogram is the number of data points.
This matters a lot more for nonlinearly spaced bins, like log binning. For
nondegenerate data with linear spacing, the shape of what's shown doesn't
matter if it's normalized or not; it's just a scaling factor. However, for
the degenerate case, the mostly sensible degenerate bin size can be hard to
interpret if it's the first time you've seen it. To make a long story
short, you can turn normalization off with this:

----%<----
use PDL::Graphics::Prima::Simple;
# Set up linear, non-normalized binning
hist_plot($data, bt::Linear(normalize => 0));
---->%----

Craig, Dima, how does Gnuplot handle this?

David


On Sat, Oct 26, 2013 at 7:56 AM, Hernán De Angelis <[email protected]>wrote:

> OK. Did not know that. I use hist often and never suspected anything was
> wrong with it.
>
>
>
>
>
> On Sat, Oct 26, 2013 at 1:37 PM, Chris Marshall <[email protected]>wrote:
>
>> There was a bug in hist fixed for PDL-2.006.
>>
>
>
>
> --
> Hernán De Angelis
> http://talesoficeandstone.blogspot.se/
>
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
>


-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to