Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Weighted random number generator
Date: Tue, 22 Jul 2008 15:42:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 88
Message-ID: <g64v49$8cm$1@fred.mathworks.com>
References: <g647ip$2d5$1@fred.mathworks.com> <g64alt$1kr$1@fred.mathworks.com> <g64fa3$hc7$1@fred.mathworks.com> <g64ls2$22d$1@fred.mathworks.com> <g64o91$3sh$1@fred.mathworks.com> <g64thp$h45$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216741321 8598 172.30.248.35 (22 Jul 2008 15:42:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 22 Jul 2008 15:42:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1446565
Xref: news.mathworks.com comp.soft-sys.matlab:480992


"Adam " <not.real@email.com> wrote in message
<g64thp$h45$1@fred.mathworks.com>...
> "stinkinrich88 Coombez" <stinkinrich88@gmail.com> wrote in
> message <g64o91$3sh$1@fred.mathworks.com>...
> > "Adam " <not.real@email.com> wrote in message
> > <g64ls2$22d$1@fred.mathworks.com>...
> > > "stinkinrich88 Coombez" <stinkinrich88@gmail.com> wrote in
> > > message <g64fa3$hc7$1@fred.mathworks.com>...
> > > 
> > > <SNIP>
> > > 
> > > > a curve. Is there a way I can adjust the steepness
of the
> > > > slop while keeping it flat? 
> > > 
> > > Maybe I'm missing something.  But if you want the pdf
to be
> > > a straight line...  It has to pass through (0,0) and (1,x)
> > > where x is determined by the number of bins.  so how
is the
> > > slope going to change?
> > > 
> > > another way:
> > > 
> > > N = 1e5;
> > > vRandom = rand(1, N);
> > > vWeighted = vRandom.^0.5;
> > > 
> > > ~Adam
> > 
> > Thanks Adam. I made a little script to put your solution
> > into a graph:
> > 
> > N = 100000;
> > vRandom = rand(1, N);
> > vWeighted = vRandom.^0.5;
> <snip: reinventing the wheel...
> 
> try this
> hist(vWeighted, 0:0.01:1)
> 
> > It looks great, but I just literally want to be able to tilt
> > that slope about the centre so the probability of getting a
> > 0 goes up and the probability of getting a 1 goes down and
> > everything in between gets adjusted accordingly. I want it
> > to work so that I could tilt the slope right back to
> > horizontal, i.e. a uniform distribution. 
> 
> ok.  You want your pdf to be a line.  This line has
> adjustable slope, m, and goes through point (0.5, 0.5)
> 
> y = m(x-0.5) + 0.5
> 
> integrate to get cdf
> 
> y = m/2*x^2 + 0.5*(1-m)*x
> 
> set equal to zero and solve for x
> 
> x = (0.5(m-1) + sqrt(0.25*(1-m)^2+m*y))/m
> 
> y is rand(1, N)
> x has adjustable slopey distribution based on m in [-1 1]
> 
> test
> N = 1e6;
> y = rand(1, N);
> m = 0.25;
> x = (0.5*(m-1)+sqrt(.25*(1-m)^2+m*y))/m;
> hist(x, 0:0.01:1)
> 
> Really hope this wasn't a homework
> ~Adam


Ahh!! Thanks so much, Adam! What a legend. I promise I'm
going to work really hard, now. I'm going to do all the
maths stuff myself from now on. I only started using matlab
last week so I feel a bit out of my depth, but I'm getting
there.

No, not homework! I'm making an opportunistic data network
simulator for a studentship! This random number generator is
going to be used to solve the problem with the Random
Waypoint Mobility Model where the average speed of the nodes
tends to minSpeed. 

Thanks again! Problem solved!