Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: Randomly biased, random numbers.

by educated_foo (Vicar)
on Dec 06, 2013 at 04:55 UTC ( [id://1065900]=note: print w/replies, xml ) Need Help??


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

You more or less have it.
I haven't a clue how I'd go about it though :( (Offers?:)
For my standard consulting rate? ;-)

Basically, you want to take a uniform distribution between 0 and M, and map it to a non-uniform one between 0 and N, so that X+I < X+J when I < J. One way to do this is to generate a step-functionpiecewise linear function, then translate values through that step function. In Matlab, it looks something like this for a 10-step function:

fx = [0,cumsum(unifrnd(0,1,1,10))]; tmp=unifrnd(1,10,1,1e5); ix=floor(tmp); dx=rem(tmp,1); values = (fx(ix) + (fx(ix+1)-fx(ix)).*dx)./fx(end-1);
Using a spline would be more complicated, but would be smoother.

Replies are listed 'Best First'.
Re^6: Randomly biased, random numbers.
by BrowserUk (Patriarch) on Dec 06, 2013 at 06:57 UTC
    In Matlab, it looks something like this for a 10-step function:

    Great, thanks. Now all I gotta do is translate that from matlab, a lingo I am not familiar with.

    Darn it. Fell at the first hurdle. I cannot sense of your parameters to unifrnd()?


    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.
      Sorry -- it's much terser than Perl for math.
      unifrnd(MIN, MAX, ROWS, COLUMNS); # uniform random numbers in [MIN,MAX +) cumsum(VECTOR) = #cumulative sum of vector # .OP = element-wise application of OP to operands

        Is this fx(ix) (roughly) equivalent to this: @fx[ @ix ]?

        If it is, then I don't understand how you can index the 10-element fx with the 1e5-element ix?


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

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

    No recent polls found