Message Boards Message Boards

0
|
4900 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

How do i obtain a sample random times that the walks crosses the boundary?

Posted 10 years ago
RandomWalk[n_, d_] :=   NestList[(# + Table[Random[Real, {-1, 1}], {d}]) &, Table[0, {d}], n];

ThreeDim = RandomWalk[5000, 3];ThreeDim = RandomWalk[5000, 3];

I defined a security boundary for a random walk:
p = 5000;(*steps*)
tc = 15;(*cube edge length*)
tp = 0.2;
random = Accumulate[
Join[{RandomReal[{-tc, tc}/2, 3]},
RandomVariate[NormalDistribution[0, tp], {p, 3}]]];
periodizedWalk = Mod[random, tc, -tc/2];
splitPeriodizedWalk =
Split[periodizedWalk, EuclideanDistance[#1, #2] < tc/2 &];
With[{cube = First[PolyhedronData["Cube"]]},
Graphics3D[{{Opacity[0.1], Scale[cube, tc]}, Line[random]},
Boxed -> False]]
and now i want to obtain a sample of the random times at which the random walk crosses the boundary for the first time. Something like this:
 W = {}; For[i = 1, i <= 5000, i++,
 PosFinal = {0, 0}; EME = 1;
 While[True,
 PosFinal = PosFinal + step[Random[]];
 If[Norm[PosFinal] > 15, Break[]];
 
 EME=EME+1;
 ];
 W=Append[W,EME];
]
but i want these two codes to be related and the second one that gives me the sample of the random times at which the random walk crosses the boundary for the first time is very slow, my pc takes too much time to run it. Would like some help please emoticon
POSTED BY: mariana ferreira

For a symmetric random walk on integers:

In[1]:= proc = RandomWalkProcess[1/2];
sample[pathLength_, numberOfPaths_] := RandomFunction[proc, {pathLength}, numberOfPaths]

Simulate 30 paths of length 5000 each:

In[3]:= sim = sample[5*10^3, 30];

Find first time each path goes above 15 or below -15:

In[4]:= Map[Min[Select[#, (Abs[Last[#]] > 15) &][[All, 1]]] &, sim["Paths"]]

Out[4]= {302, 54, 600, 48, 418, 118, 250, 244, 638, 488, 214, 230, 702, 320, 230, 146, 
158, 962, 182, 258, 78, 264, 224, 130, 628, 102, 170, 54, 66, 320}
POSTED BY: Gosia Konwerska
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract