Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^10: Randomly biased, random numbers.

by BrowserUk (Patriarch)
on Dec 06, 2013 at 20:30 UTC ( [id://1066054]=note: print w/replies, xml ) Need Help??


in reply to Re^9: Randomly biased, random numbers.
in thread Randomly biased, random numbers.

Okay. This is my brute force conversion from MatLab to perl, and a simple test harness.:

#! perl -slw use strict; use Data::Dump qw[ pp ]; use List::Util qw[ reduce ]; $a = $b; use GD; use constant { X => 0, Y=> 1, R => 2 }; sub rgb2n{ unpack 'N', pack 'CCCC', 0, @_ } my $RED = rgb2n( 255, 0, 0 ); my $GREEN = rgb2n( 0, 255, 0 ); my $BLUE = rgb2n( 0, 0, 255 ); my $YELLOW = rgb2n( 255, 255, 0 ); my $MAGENTA = rgb2n( 255, 0, 255 ); my $CYAN = rgb2n( 0, 255, 255 ); my $WHITE = rgb2n( 255,255,255 ); ## Brute force from MatLab code node:1065900 ## fx = [0,cumsum(unifrnd(0,1,1,10))]; my @fx = @{ reduce( sub{ push @$a, $a->[-1]+$b; $a }, [ 0 ], map{ 1+ra +nd 10 } 1..10 ) }; ## tmp=unifrnd(1,10,1,1e5); my @tmp = map{ 1+ rand 10 } 1 .. 1e5; ## ix=floor(tmp); my @ix = map int, @tmp; ## dx=rem(tmp,1); my @dx = map $_-int($_), @tmp; ## values = (fx(ix) + (fx(ix+1)-fx(ix)).*dx)./fx(end-1); my @values = map{ ( $fx[ $ix[$_] ] + ( $fx[ $ix[$_+1] ] - $fx[ $ix[$_] ] ) * $dx[$_] + ) / $fx[-1] } 0 .. $#ix-1; our $N //= 100; our $X = our $Y //= 800; ## pick points from values my @points = map[ int( $values[ rand @values ]*$X ), int( $values[ rand @values ]*$Y + ) ], 1 .. $N; my $im = GD::Image->new( 1000, 1000, 1 ); $im->fill( 0, 0, $WHITE ); $im->rectangle( 100, 100, 900, 900, 0 ); $im->filledArc( 100+$_->[X], 100+$_->[Y], 5, 5, 0, 360, $RED ) for @po +ints; open PNG, '>:raw', "$0.png" or die $!; print PNG $im->png; close PNG; system "$0.png";

Does the conversion look right? Am I using the values correctly?

It produces datasets like this which doesn't appear to demonstrate much in the way of clumping. What did I do wrong?


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.

Replies are listed 'Best First'.
Re^11: Randomly biased, random numbers.
by educated_foo (Vicar) on Dec 08, 2013 at 01:24 UTC
    Your translation looks correct, so I'm a bit surprised by the result. I only tested it in 1-D, but the histogram looked plenty spiky. You could make it spikier by raising the random numbers used to generate @fx to some power, but it sounds like you found another solution.
      You could make it spikier by raising the random numbers used to generate @fx to some power

      Indeed, adding a power component causes much more clumpiness, and making the power component variable:

      my @fx = @{ reduce( sub{ push @$a, $a->[-1]+$b; $a }, [ 0 ], map{ rand()**rand +(3) } 1..10 ) };

      gives a nice variability.

      But yes, I am currently much enamoured of my weight-map solution. Some of the grey-scale images it produces are just downright beautiful :)

      But thankyou for your input. The vectorising of the 3D weight-map to 1D weight-stick my solution uses. came directly from your example, and I understand a little more about matlab/octave now :)


      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://1066054]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found