dtmcmtta
Compute the expected number of steps before absorption for a DTMC with state space and transition probability matrix P.
INPUTS
P(i,j)
transition probability matrix.
P(i,j)
is the transition probability from state
to state .
p0(i)
Initial state occupancy probabilities (vector of length ).
OUTPUTS
t
t(i)
When called with a single argument, t is a vector of length
such that t(i)
is the expected number of steps
before being absorbed in any absorbing state, starting from state
; if is absorbing, t(i) = 0
. When
called with two arguments, t is a scalar, and represents the
expected number of steps before absorption, starting from the initial
state occupancy probability p0.
N(i)
N(i,j)
When called with a single argument, N is the
fundamental matrix for P. N(i,j)
is the expected
number of visits to transient state j before absorption, if the
system started in transient state i. The initial state is counted
if . When called with two arguments, N is a vector
of length such that N(j)
is the expected number
of visits to transient state j before absorption, given initial
state occupancy probability P0.
B(i)
B(i,j)
When called with a single argument, B is a
matrix where B(i,j)
is the probability of being
absorbed in state , starting from transient state ;
if is not absorbing, B(i,j) = 0
; if
is absorbing, B(i,i) = 1
and B(i,j) = 0
for all . When called with two arguments, B is
a vector of length where B(j)
is the
probability of being absorbed in state j, given initial state
occupancy probabilities p0.
REFERENCES
See also: ctmcmtta
n = 6; P = zeros(101,101); for j=0:(100-n) i=1:n; P(1+j,1+j+i) = 1/n; endfor for j=(101-n):100 P(1+j,1+j) = (n-100+j)/n; endfor for j=(101-n):100 i=1:(100-j); P(1+j,1+j+i) = 1/n; endfor Pstar = P; ## setup snakes and ladders SL = [ 1 38; 4 14; 9 31; 16 6; 21 42; ... 28 84; 36 44; 47 26; 49 11; 51 67; ... 56 53; 62 19; 64 60; 71 91; 80 100; ... 87 24; 93 73; 95 75; 98 78 ]; for ii=1:rows(SL); i = SL(ii,1); j = SL(ii,2); Pstar(1+i,:) = 0; for k=0:100 if ( k != i ) Pstar(1+k,1+j) = P(1+k,1+j) + P(1+k,1+i); endif endfor Pstar(:,1+i) = 0; endfor Pstar += diag( 1-sum(Pstar,2) ); # spy(Pstar); pause nsteps = 250; # number of steps Pf = zeros(1,nsteps); # Pf(i) = prob. of finishing after step i pstart = zeros(1,101); pstart(1) = 1; pn = pstart; for i=1:nsteps pn = pn*Pstar; Pf(i) = pn(101); # state 101 is the ending (absorbing) state endfor f = dtmcmtta(Pstar,pstart); printf("Average n. of steps to complete 'snakes and ladders': %f\n", f ); plot(Pf,"linewidth",2); line([f,f],[0,1]); text(f*1.1,0.2,["Mean Time to Absorption (" num2str(f) ")"]); xlabel("Step number (n)"); title("Probability of finishing 'snakes and ladders' before step n"); Average n. of steps to complete 'snakes and ladders': 39.225122 |
N = 50; birth = death = 0.5*ones(1,N-1); birth(1) = death(N-1) = 0; P = diag(birth,1)+diag(death,-1); P = P + eye(N) - diag(sum(P,2)); t = zeros(1,N/2); initial_state = 1:(N/2); for i=initial_state p = zeros(1,N); p(i) = 1; t(i) = dtmcmtta(P,p); endfor plot(initial_state,t,"+"); title(sprintf("Birth-Death process, %d states, absorbing states=1,%d",N,N)); xlabel("Initial state"); ylabel("MTTA"); |