in reply to Randomly biased, random numbers.
G'day BrowserUk,
"But the worse case scenarios for the algorithm are when you get a bunch of points grouped in one place and then a few outliers far away. Either in another bunch, or widespread."
Perhaps the following might be suitable. The "bunch of points grouped in one place" tend towards the centre of the plane; the outliers are typically widespread rather than forming outlying clumps.
#!/usr/bin/env perl use strict; use warnings; my $rand_bias; # Boolean (for testing) my ($x_high, $y_high) = (80, 80); my $N = 10_000; for my $rand_bias_bool (0, 1) { $rand_bias = $rand_bias_bool; print '*** ', $rand_bias ? 'WITH' : 'NO', ' RANDOM BIAS', " ***\n" +; my @points = map [ gen_rand($x_high), gen_rand($y_high) ], 1 .. $N +; print_matrix(\@points); } sub gen_rand { my $rand_high = shift; return int rand $rand_high unless $rand_bias; # For testing only! my $high_part = $rand_high; my $rand_sum = 0; while ($high_part) { my $rand_arg = 1 + int rand $high_part; $high_part -= $rand_arg; $rand_sum += int rand $rand_arg; } return $rand_sum; } sub print_matrix { my $coords = shift; my %matrix; for (@$coords) { my ($x, $y) = @$_; ++$matrix{$x}{$y}; } for my $y (reverse 0 .. $y_high - 1) { for my $x (0 .. $x_high - 1) { if (exists $matrix{$x}{$y}) { $matrix{$x}{$y} = '@' if $matrix{$x}{$y} > 9; } else { $matrix{$x}{$y} = ' '; } print $matrix{$x}{$y}; } print "\n"; } }
Here's a sample run showing an (ASCII) graphical representation of the generated data. Note that I've only used an 80x80 grid (rather than your posted 500x500) to get a reasonable display.
Update: I removed two lines with $loops which I'd used for testing but aren't part of the solution.
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Randomly biased, random numbers.
by BrowserUk (Patriarch) on Dec 06, 2013 at 18:16 UTC |