Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Randomly biased, random numbers.

by kcott (Archbishop)
on Dec 06, 2013 at 10:09 UTC ( [id://1065949]=note: print w/replies, xml ) Need Help??


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

    That does induce clumping, but it is always just one clump, always in the middle, and very uniform from one run to the next, which doesn't make for good test data.

    I want multiple clumps -- 1, 2, 3, or 4 -- and unevenly distributed -- just 2 big clumps in one corner; or 4 small clumps all down one side or ... -- and different on each run.

    Everything mathematical I've tried, tends to produce uniformity, which is kind of it's thing.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1065949]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found