[Date Index]
[Thread Index]
[Author Index]
Re: Simulation...Ooops
*To*: mathgroup at smc.vnet.net
*Subject*: [mg19418] Re: [mg19353] Simulation...Ooops
*From*: "Mark E. Harder" <harderm at ucs.orst.edu>
*Date*: Mon, 23 Aug 1999 13:57:24 -0400
*Sender*: owner-wri-mathgroup at wolfram.com
Roberto;
Luckily, I decided to plot several runs of our simulation, and all I
could get were Bear Markets! I made a programming error in ranStep[] which
caused this. Here's a fix which behaves better:
ranStep[]:= (sample=Random[Real,{0.,1.}];
If[
sample<N[1/6,20],Return[-1],
If[sample>N[5/6,20],Return[1],Return[0] ] ]
);
Nstep=6000;
SeedRandom[];
data=Table[NestList[#+0.01*ranStep[]&,5,Nstep]];
The key change is only calculating the random number once per function call.
The other changes I made were:
1. Increased precision in calculating partitions to 20-digits (probably not
important).
2. re-seeding the generator with time-of-day.
Also, I run the following to plot results:
plotData={Table[i,{i,0,Nstep}],data};
ListPlot[Transpose[plotData ],Frame->True ]
Buena Suerte!
-mark
-----Original Message-----
From: Mark E. Harder <harderm at ucs.orst.edu>
To: mathgroup at smc.vnet.net
<mathgroup at smc.vnet.net>
Subject: [mg19418] Re: [mg19353] Simulation
>Roberto,
> First, replace the Random[Integer,...] function with a user-defined
>function ranStep, which returns -1 and 1 1/6 of the time and 0 the
remainder
>of the times (Press, et.al. "Numerical Recipes in Fortran" describe this
>method of converting a uniform random distribution to one with unequal
>probabilities):
>
>ranStep[]:=If[
> Random[Real,{0.,1.}]<N[1/6],Return[-1],
> If[Random[Real,{0.,1.}]>N[5/6],Return[1],Return[0] ] ]
>
>Then use it in the statement you already wrote:
>
>
>data=Table[NestList[#+0.01*ranStep[]&,5,100]]
>
>Out[113]=
>{5,5,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,4.99,5.,5.
,
>
>4.99,4.98,4.98,4.98,4.98,4.98,4.98,4.98,4.98,4.98,4.97,4.97,4.97,4.97,4.97,
>
>4.98,4.98,4.97,4.97,4.96,4.96,4.96,4.96,4.96,4.96,4.97,4.97,4.96,4.95,4.95,
>
>4.95,4.95,4.95,4.95,4.95,4.96,4.96,4.96,4.95,4.95,4.95,4.94,4.94,4.94,4.94,
>
>4.93,4.93,4.93,4.93,4.93,4.93,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.95,
>
>4.96,4.97,4.97,4.98,4.98,4.98,4.98,4.99,4.99,4.99,4.99,4.99,4.98,4.97,4.98,
> 4.97,4.97,4.96,4.96,4.97,4.96,4.96,4.95,4.95}
>
>-mark
>
>
>
>-----Original Message-----
>From: Roberto Diego <r-diego at develnet.es>
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net <mathgroup at smc.vnet.net>
>Date: Friday, August 20, 1999 9:41 PM
>Subject: [mg19418] [mg19353] Simulation
>
>
>>Hi there,
>>
>>I need help on how the expression:
>>
>>data=Table[NestList[#+0.01*Random[Integer,{-1,1}]&,5,1000]];
>>
>>could be modified in order to get -1 with probability 1/6, 0 with p 4/6
and
>>1 with p 1/6 instead of 1/3,1/3,1/3
>>
>>Thanks a lot
>>
>>Roberto Diego
>>Sociedad de Bolsas
>>
>>
>>
>
Prev by Date:
**Re: Simulation**
Next by Date:
**RE: Magnitude of Vector**
Previous by thread:
**Re: Up-Values with GroebnerBasis**
Next by thread:
**Please help me! (Warnings and Messages...)**
| |