in reply to build a distribution

You might find something like this useful. It plots line graphs of the sums at each interval, which might serve to help you select the best one for your purpose. The graph produced(*) using random data are pretty uninspiring, but serves its purpose.

Large; you'll need to scroll or scale

#! perl -slw use strict; use GD; use List::Util qw[ sum ]; sub rgb2n { unpack 'N', pack 'CCCC', 0, @_ } ## Gen some data my %counts; ++$counts{ int( rand( 5e3 ) + rand( 5e3 ) ) } for 1 .. 1e6; my @keys = sort{ $a <=> $b } keys %counts; my $gd = GD::Image->new( 10000, 2000, 1 ); for my $step ( reverse 1.. 10 ) { my $start = 0; my $last = 0; my $clr = 2**24 / $step; for( my $end = $start+$step-1; $end < $keys[ -1 ]; $end += $step ) + { my $sum = sum( @counts{ grep( defined $counts{ $_ }, $start..$ +end ) } ) // 0; # printf "%4d - %4d : %d\n", $start, $end, $sum; $gd->line( $start, 2000-$last, $end, 2000-$sum, $clr ) if $las +t; $start = $end + 1; $last = $sum; } } open IMG, '>:raw', 'junk14.png' or die $!; print IMG $gd->png; close IMG; ## Display the graph in the default image viewer system 'junk14.png';

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^2: build a distribution
by sflitman (Hermit) on Aug 07, 2010 at 22:31 UTC
    Very elegant! I ran the code on WinXP ActiveState perl and initially got a black image, but I called rgb2n on $clr and then it worked.

    SSF

      I called rgb2n on $clr and then it worked.

      Hm. That is weird. And I mean re-ally weird!.

      $clr is (already) a number in the range 0 .. 2**24: my $clr = 2**24 / $step;, where $step interates from 10 .. 1.

      rgb2n() expects input of 3 numbers in the range 0 .. 255, which it then converts to a number in the range 0 .. 2**24. So, besides the crapload of warning that should have been issued, half the lines on the graph would have been drawn in black on black:

      c:\test>p1 [0] Perl> sub rgb2n { unpack 'N', pack 'CCCC', 0, @_ } ;; [0] Perl> print rgb2n( 2**24 / $_ ) for reverse 1 .. 10;; Character in 'C' format wrapped in pack at (eval 6) line 1, <STDIN> li +ne 3. 10027008 Character in 'C' format wrapped in pack at (eval 6) line 1, <STDIN> li +ne 3. 13041664 Character in 'C' format wrapped in pack at (eval 6) line 1, <STDIN> li +ne 3. 0 Character in 'C' format wrapped in pack at (eval 6) line 1, <STDIN> li +ne 3. 4784128 Character in 'C' format wrapped in pack at (eval 6) line 1, <STDIN> li +ne 3. 11141120 Character in 'C' format wrapped in pack at (eval 6) line 1, <STDIN> li +ne 3. 3342336 Character in 'C' format wrapped in pack at (eval 6) line 1, <STDIN> li +ne 3. 0 Character in 'C' format wrapped in pack at (eval 6) line 1, <STDIN> li +ne 3. 5570560 Character in 'C' format wrapped in pack at (eval 6) line 1, <STDIN> li +ne 3. 0 Character in 'C' format wrapped in pack at (eval 6) line 1, <STDIN> li +ne 3. 0

      The only possible explanation I can hazard at for this, is that you have a very (very(very)) old version of GD installed that only supports 8-bit color?

      Like pre-v2.0. The libgd history doesn't list dates, but from memory, it must at least 5 years ago. I provided a patch for 2.3x, and that was at least 4 years ago.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.