<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162834</link>
    <title>MATLAB Central Newsreader - random number generator from logistic distribution</title>
    <description>Feed for thread: random number generator from logistic distribution</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 30 Jan 2008 10:40:06 -0500</pubDate>
      <title>Re: random number generator from logistic distribution</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162834#411929</link>
      <author>Roger Stafford</author>
      <description>"Jessica " &amp;lt;jandre@mathworks.com&amp;gt; wrote in message &amp;lt;fnod3l$po&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I'm trying to create a random number generator from the &lt;br&gt;
&amp;gt; logistic distribution. Does the following function look &lt;br&gt;
&amp;gt; right or am I completely off track?!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; r=lrnd(m,n,mu,sigma)&lt;br&gt;
&amp;gt; p=rand(m,n)&lt;br&gt;
&amp;gt; r=log(p./(1-p)).*sigma+mu&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks for your help&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Jess&lt;br&gt;
--------&lt;br&gt;
&amp;nbsp;&amp;nbsp;Because you expressed doubt about the validity of the method in your &lt;br&gt;
logistic distribution generator, Jessica, I have decided that it would be &lt;br&gt;
appropriate to show details of the reasoning behind it.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;You defined the random variable p in terms of matlab's 'rand' function:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;p = rand&lt;br&gt;
&lt;br&gt;
(forget for a moment that your p is actually an m by n array) and the random &lt;br&gt;
variable r in terms of p as:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;r = f(p) = log(p/(1-p))*s+m&lt;br&gt;
&lt;br&gt;
This is easily shown to be mathematically equivalent to saying&lt;br&gt;
&lt;br&gt;
&amp;nbsp;p = f_inverse(r) = 1/(1+exp(-(r-m)/s))&lt;br&gt;
&lt;br&gt;
Then we can write the cumulative distribution of r as:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;P{r &amp;lt;= c} = P{f(p) &amp;lt;= c} = &lt;br&gt;
&amp;nbsp;P{p &amp;lt;= f_inverse(c)} = P{p &amp;lt;= 1/(1+exp(-(c-m)/s)&lt;br&gt;
&lt;br&gt;
This holds because f is a monotonically increasing function so that&lt;br&gt;
&lt;br&gt;
&amp;nbsp;f(p) &amp;lt;= c&lt;br&gt;
&lt;br&gt;
is equivalent to&lt;br&gt;
&lt;br&gt;
&amp;nbsp;p &amp;lt;= f_inverse(c)&lt;br&gt;
&lt;br&gt;
and so have equal probabilities.  Next notice that random variable p = rand &lt;br&gt;
has the important special property that P{p &amp;lt;= t} is always equal to t itself for &lt;br&gt;
any t in 0 &amp;lt;= t &amp;lt;= 1, because MathWorks has gone to great lengths to ensure &lt;br&gt;
that rand is uniformly distributed from 0 to 1.  Thus, applying this to t = 1/(1&lt;br&gt;
+exp(-(c-m)/s)), we have&lt;br&gt;
&lt;br&gt;
&amp;nbsp;P{r &amp;lt;= c} = P{p &amp;lt;= 1/(1+exp(-(c-m)/s))} = 1/(1+exp(-(c-m)/s))&lt;br&gt;
&lt;br&gt;
Therefore r has the required cumulative logistic distribution.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;The same kind of reasoning applies to any random variable which is to be &lt;br&gt;
defined in terms of the special random variable p = rand.  One simply applies &lt;br&gt;
the inverse of the desired cumulative distribution function to p.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Wed, 30 Jan 2008 00:59:02 -0500</pubDate>
      <title>Re: random number generator from logistic distribution</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162834#411891</link>
      <author>Roger Stafford</author>
      <description>"Jessica " &amp;lt;jandre@mathworks.com&amp;gt; wrote in message &amp;lt;fnod3l$po&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I'm trying to create a random number generator from the &lt;br&gt;
&amp;gt; logistic distribution. Does the following function look &lt;br&gt;
&amp;gt; right or am I completely off track?!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; r=lrnd(m,n,mu,sigma)&lt;br&gt;
&amp;gt; p=rand(m,n)&lt;br&gt;
&amp;gt; r=log(p./(1-p)).*sigma+mu&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks for your help&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Jess&lt;br&gt;
--------&lt;br&gt;
&amp;nbsp;&amp;nbsp;That looks good to me, except that of course functions are written this way:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;function  r=lrnd(m,n,mu,sigma);&lt;br&gt;
&amp;nbsp;etc.&lt;br&gt;
&lt;br&gt;
You have correctly taken the inverse of the cumulative distribution function:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;p = F(x;mu,sigma) = 1/(1+exp(-(x-mu)/sigma))&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Note: Since sigma is a scalar, you don't need the dot when multiplying by it:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;r=log(p./(1-p))*sigma+mu;&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 29 Jan 2008 23:33:09 -0500</pubDate>
      <title>random number generator from logistic distribution</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/162834#411888</link>
      <author>Jessica </author>
      <description>Hi,&lt;br&gt;
I'm trying to create a random number generator from the &lt;br&gt;
logistic distribution. Does the following function look &lt;br&gt;
right or am I completely off track?!&lt;br&gt;
&lt;br&gt;
r=lrnd(m,n,mu,sigma)&lt;br&gt;
p=rand(m,n)&lt;br&gt;
r=log(p./(1-p)).*sigma+mu&lt;br&gt;
&lt;br&gt;
Thanks for your help&lt;br&gt;
&lt;br&gt;
Jess&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
