LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ctmc_uniformization.m
1function [pi,kmax]=ctmc_uniformization(pi0,Q,t,tol,maxiter)
2% [PI,KMAX]=CTMC_UNIFORMIZATION(PI0,Q,T,TOL,MAXITER)
3%
4% MAXITER caps the Poisson series truncation depth; pass a nonpositive
5% value (or omit it) to size it adaptively as max(100, q*t+10*sqrt(q*t)+20).
6
7% Copyright (c) 2012-2026, Imperial College London
8% All rights reserved.
9if nargin<4%~exist('tol','var')
10 tol = 1e-12;
11end
12if nargin<5%~exist('maxiter','var')
13 maxiter = -1;
14end
15q=1.1*max(abs(diag(Q)));
16% Split the horizon so exp(-q*t) never underflows within a segment
17% (exp(-745)==0 in double precision): exp(Q*t)=(exp(Q*t/nSeg))^nSeg
18MAXQT = 500;
19if q*t > MAXQT
20 nSeg = ceil(q*t/MAXQT);
21 tSeg = t/nSeg;
22 pi = pi0;
23 for seg=1:nSeg
24 [pi,kmax] = ctmc_uniformization(pi,Q,tSeg,tol,maxiter);
25 end
26 return
27end
28if maxiter<=0
29 % The Poisson(q*t) mass concentrates around q*t with spread O(sqrt(q*t));
30 % a fixed cap silently truncates the series for large horizons
31 maxiter = max(100, ceil(q*t+10*sqrt(q*t)+20));
32end
33Qs=speye(size(Q))+sparse(Q)/q;
34k=0;
35s=1;
36r=1;
37iter=0;
38kmax=1;
39while iter<maxiter
40 iter=iter+1;
41 k=k+1;
42 r=r*(q*t)/k;
43 s=s+r;
44 if (1-exp(-q*t)*s)<=tol
45 kmax=k;
46 break;
47 end
48 % Best-effort truncation depth if the loop exhausts maxiter: summing k
49 % terms is always more accurate than the single term a stale kmax=1 gives
50 kmax=k;
51end
52
53pi=pi0*(exp(-q*t));
54P=pi0;
55ri=exp(-q*t);
56for j=1:kmax
57 P=P*Qs;
58 ri=ri*(q*t/j);
59 pi=pi+ri*P;
60end
61end
Definition Station.m:245