I was in a party last night and a guy was totally drunk. Not just the guy who had a few drinks and speaks a bit too loud, but the one who is not very likely to remember what he has done during his night, but who is rather very likely to suffer from a huge headache today. The guy was literally randomly walking. One step on the left, another forward, then another backward. I immediately remembered one of my courses where our teacher was talking about random walk process. A random walk process, is a stochastic process which represents something moving randomly on a map. It may be something else than a map, but we will keep focus on a map to make it simpler.

Many questions may be of interest in such a model. The question I was wondering yesterday night is "how long would it take to this guy to go out from the garden if he was really walking randomly?". Here, we consider the guy to be in a map where you can go toward South-East, North-East, South-West or North-West. Each direction being chosen with the same probability 0.25.

Such a random process is illustrated by the following plots.

A few steps of a long random walk for a garden with 75 units long sides. This process needed 4192 steps to stop.


The question was "how long would it take to this guy to go out of the garden if he was really walking randomly?". Obviously, the answer depends on the size of the garden. We will consider a garden which is a square. The length of a side will vary and we will measure how many steps the process needs to reach one of the side of the garden. We then make the size of the garden change to estimate the number of steps according to the size. The following plot illustrates the number of steps needed according to the size of the garden. Without any surprise, the bigger is the garden, the longer the time our poor little guy will need. Besides, the variance of the required time seems to increase with the size of the garden.

Now I would like to estimate with a quantitative approach these observations. I will assume that the number of required steps increases exponentially. I do an exponential regression to estimate it. In other words I assume that numberStep = a*size^b and I want to estimate the couple (a,b). In the simulation I have done, I found a = 0.759 which is not considered as significantly different from 1 (which is the neutral element for multiplication) and b = 1.91. If I use these values, I can estimate the number of steps I would need as shown by the red line in the next plot.



The code (R):

#The function to randomly assign the movement
decision = function(){
  a = runif(1)
  if(a<=0.25){return(c(1,1))}
  else if(a<= 0.5){return(c(1,-1))}
  else if(a<= 0.75){return(c(-1,1))}
  else {return(c(-1,-1))}
}

#The simulation for different size
long = 150
record = 1:long
for (max  in 1 : long){
  position = matrix(0, nrow = 2, ncol = 1)
  k = 0
  test = FALSE
  while(!test){
    k = k+1
    dec = decision()
    pos1 = position[1, length(position[1,])] + dec[1]
    pos2 = position[2, length(position[2,])] + dec[2]
    position = cbind(position, c(pos1, pos2))
    if(abs(pos1)>max | abs(pos2) > max){
      test = TRUE
    }
    record[max] = k
  }
 
}

plot(record, type = 'l', xlab = 'Size of the garden', ylab = 'Number of steps needed')

# Plot of one random walk process
max = 75
position = matrix(0, nrow = 2, ncol = 1)
k = 0
test = FALSE
while(!test){
  k = k+1
  dec = decision()
  pos1 = position[1, length(position[1,])] + dec[1]
  pos2 = position[2, length(position[2,])] + dec[2]
  position = cbind(position, c(pos1, pos2))
      mypath = file.path("U:","Blog","Post10","Plot", paste("myplot", k, ".png", sep = ""))
      png(file=mypath)
      mytitle = paste("my title is", k)
      plot(position[1,], position[2,], type = 'l', xlim = c(-max,max), ylim = c(-max, max), xlab = '', ylab = '')
      dev.off()
  if(abs(pos1)>max | abs(pos2) > max){
    test = TRUE
  }
}

# The exponential regression

fit = lm(log(record)~log(1:150))

exp(fit$coef[1])
# a = 0.759
fit$coef[2]
# b = 1.91


0

Add a comment

Pricing of a financial product : A pricer of a call option.
Temporal network model - Barabási-Albert model with the library igraph
3
How to plot a network (package network) - Tip 2
1
Have you tried to understand your network? - Random generation of network models
Function apply() - Tip 1
1
Want to win "Guess who?" - Have an institutional neural network approach
How to choose your next holidays destination - Uniform distribution on a sphere
4
Generation of a normal distribution from "scratch" - The box-muller method
Generate stock option prices - How to simulate a Brownian motion
1
The consequence of merging insurance companies - Risk simulation and probability of ruin
Estimation of the number PI - A Monte Carlo simulation
The movement of a drunk guy - Random Walk and exponential regression
How does my computer know what language I am using? – An approach of statistical learning (Language, Computer Science)
How does my computer know what language I am using? – An approach of statistical learning (Language, Computer Science)
The fear-index: is the VIX efficient to be warned about high volatility? (Finance & Systematic Processus)
Who is the most complete athlete? – An insight with the Mahalanobis distance (sport & data analysis)
Who is the most complete athlete? – An insight with the Mahalanobis distance (sport & data analysis)
ProbaPerception: Introduction
Blog Archive
Translate
Translate
Loading