LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ctmc_timeaverage.m
1function [piTimeAvg,piExit,kmax]=ctmc_timeaverage(pi0,Q,t,tol,maxiter)
2% [PITIMEAVG,PIEXIT,KMAX]=CTMC_TIMEAVERAGE(PI0,Q,T,TOL,MAXITER)
3%
4% Time-averaged transient distribution of a CTMC with generator Q over [0,T],
5% starting from the (arbitrary) initial distribution PI0, via Jensen's
6% uniformization. Companion of CTMC_UNIFORMIZATION, which returns only the
7% endpoint PI0*exp(Q*T); this function additionally returns the time average
8%
9% PITIMEAVG = PI0 * (1/T) * \int_0^T exp(Q*tau) d(tau)
10%
11% as well as the endpoint PIEXIT = PI0*exp(Q*T) (computed from the same series).
12% Both are obtained without forming any dense matrix exponential.
13%
14% Uniformization: with q = 1.1*max|diag(Q)| and P = I + Q/q (row-stochastic),
15% PI0*exp(Q*T) = sum_j w_j(qT) * (PI0*P^j)
16% PI0*\int_0^T exp(Q*tau) = (1/q) * sum_j (1 - W_j(qT)) * (PI0*P^j)
17% where w_j and W_j are the Poisson(qT) PMF and CDF. The time average divides
18% the integral by T (equivalently the integral sum by q*T).
19%
20% Copyright (c) 2012-2026, Imperial College London
21% All rights reserved.
22
23if nargin<4 % tol
24 tol = 1e-12;
25end
26if nargin<5 % maxiter
27 maxiter = 100;
28end
29
30q = 1.1*max(abs(diag(Q)));
31Qs = speye(size(Q)) + sparse(Q)/q;
32qt = q*t;
33
34% Number of Poisson terms needed (right-tail below tol), as in ctmc_uniformization
35k = 0; s = 1; r = 1; iter = 0; kmax = 1;
36while iter < maxiter
37 iter = iter + 1;
38 k = k + 1;
39 r = r*qt/k;
40 s = s + r;
41 if (1 - exp(-qt)*s) <= tol
42 kmax = k;
43 break;
44 end
45end
46
47% Accumulate endpoint and integral over the shared PI0*P^j sequence
48w = exp(-qt); % Poisson PMF w_0
49W = w; % Poisson CDF W_0
50P = pi0; % PI0*P^0
51piExit = w * P;
52piIntSum = max(1 - W, 0) * P;
53for j = 1:kmax
54 P = P * Qs; % PI0*P^j
55 w = w * qt / j; % w_j
56 W = W + w; % W_j
57 piExit = piExit + w * P;
58 piIntSum = piIntSum + max(1 - W, 0) * P;
59end
60
61piTimeAvg = piIntSum / qt; % (1/q)*sum / t = sum/(q*t)
62end