riddles on a line [#2]

September 10, 2018
By

(This article was first published on R – Xi'an's Og, and kindly contributed to R-bloggers)

A second Riddle(r), with a puzzle related with the integer set Ð={,12,3,…,N}, in that it summarises as

Given a random walk on Ð, starting at the middle N/2, with both end states being absorbing states, and a uniform random move left or right of the current value to the (integer) middle of the corresponding (left or right) integer interval, what is the average time to one absorbing state as a function of N?

Once the Markov transition matrix M associated with this random walk is defined, the probability of reaching an absorbing state in t steps can be derived from the successive powers of M by looking at the difference between the probabilities to be (already) absorbed at both t-1 and t steps. From which the average can be derived.

avexit <- function(N=100){
 #transition matrix M for the walk
 #1 and N+2 are trapping states
 tranz=matrix(0,N+2,N+2)
 tranz[1,1]=tranz[N+2,N+2]=1
 for (i in 2:(N+1))
  tranz[i,i+max(trunc((N+1-i)/2),1)]=tranz[i,i-max(trunc((i-2)/2),1)]=1/2
 #probabilities of absorption
 prowin=proloz=as.vector(0)
 init=rep(0,N+2)
 init[trunc((N+1)/2)]=1 #first position
 curt=init
 while(1-prowin[length(prowin)]-proloz[length(prowin)]>1e-10){
  curt=curt%*%tranz
  prowin=c(prowin,curt[1])
  proloz=c(proloz,curt[N+2])}
 #probability of new arrival in trapping state
 probz=diff(prowin+proloz)
 return(sum((2:length(proloz))*probz))}

leading to an almost linear connection between N and expected trapping time.

To leave a comment for the author, please follow the link and comment on their blog: R – Xi'an's Og.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)