LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MMPP2.m
1classdef MMPP2 < MarkovModulated
2 % 2-phase Markov-Modulated Poisson Process - MMPP(2)
3 %
4 % Copyright (c) 2012-2026, Imperial College London
5 % All rights reserved.
6
7 methods
8 %Constructor
9 function self = MMPP2(lambda0,lambda1,sigma0,sigma1)
10 % SELF = MMPP2(LAMBDA0,LAMBDA1,SIGMA0,SIGMA1)
11
12 self@MarkovModulated('MMPP2',4);
13 setParam(self, 1, 'lambda0', lambda0);
14 setParam(self, 2, 'lambda1', lambda1);
15 setParam(self, 3, 'sigma0', sigma0);
16 setParam(self, 4, 'sigma1', sigma1);
17 lambda0 = self.getParam(1).paramValue;
18 lambda1 = self.getParam(2).paramValue;
19 sigma0 = self.getParam(3).paramValue;
20 sigma1 = self.getParam(4).paramValue;
21 D0 = [-sigma0-lambda0,sigma0;sigma1,-sigma1-lambda1];
22 D1 = [lambda0,0;0,lambda1];
23 self.process = {D0,D1};
24 end
25
26 function Di = D(self, i, wantSparse)
27 % Di = D(i)
28 if nargin<3
29 wantSparse = false;
30 end
31
32 % Return representation matrix, e.g., D0=MAP.D(0)
33 if wantSparse
34 if nargin<2
35 Di=self.getProcess;
36 else
37 Di=self.getProcess{i+1};
38 end
39 else
40 if nargin<2
41 Di=self.getProcess;
42 for i=1:length(Di)
43 Di(i)=full(Di(i));
44 end
45 else
46 Di=full(self.getProcess{i+1});
47 end
48 end
49 end
50
51 function meant = evalMeanT(self,t)
52 % MEANT = EVALMEANT(SELF,T)
53
54 lambda0 = self.getParam(1).paramValue;
55 lambda1 = self.getParam(2).paramValue;
56 sigma0 = self.getParam(3).paramValue;
57 sigma1 = self.getParam(4).paramValue;
58 lambda = (lambda0*sigma1 + lambda1*sigma0) / (sigma0+sigma1);
59 meant = lambda * t;
60 end
61
62 function vart = evalVarT(self,t)
63 % VART = EVALVART(SELF,T)
64
65 % Evaluate the variance-time curve at t
66 D0 = self.D(0);
67 D1 = self.D(1);
68 MAP = {D0,D1};
69 vart = map_varcount(MAP, t);
70 end
71
72 function rate = getRate(self)
73 rate = 1 / getMean(self);
74 end
75
76 function X = sample(self, n)
77 % X = SAMPLE(N)
78 if nargin<2 %~exist('n','var'),
79 n = 1;
80 end
81 MAP = self.getProcess;
82 if map_isfeasible(MAP)
83 X = map_sample(MAP,n);
84 else
85 line_error(mfilename,'This process is infeasible (negative rates).');
86 end
87 end
88
89 % inter-arrival time properties
90 function mean = getMean(self)
91 % MEAN = GETMEAN()
92
93 lambda0 = self.getParam(1).paramValue;
94 lambda1 = self.getParam(2).paramValue;
95 sigma0 = self.getParam(3).paramValue;
96 sigma1 = self.getParam(4).paramValue;
97 lambda = (lambda0*sigma1 + lambda1*sigma0) / (sigma0+sigma1);
98 mean = 1 / lambda;
99 end
100
101 function scv = getSCV(self)
102 % SCV = GETSCV()
103
104 lambda0 = self.getParam(1).paramValue;
105 lambda1 = self.getParam(2).paramValue;
106 sigma0 = self.getParam(3).paramValue;
107 sigma1 = self.getParam(4).paramValue;
108 scv = (2*lambda0^2*sigma0*sigma1 + lambda0*lambda1*sigma0^2 - 2*lambda0*lambda1*sigma0*sigma1 + lambda0*lambda1*sigma1^2 + lambda0*sigma0^2*sigma1 + 2*lambda0*sigma0*sigma1^2 + lambda0*sigma1^3 + 2*lambda1^2*sigma0*sigma1 + lambda1*sigma0^3 + 2*lambda1*sigma0^2*sigma1 + lambda1*sigma0*sigma1^2)/((sigma0 + sigma1)^2*(lambda0*lambda1 + lambda0*sigma1 + lambda1*sigma0));
109 end
110
111 function skew = getSkewness(self)
112 skew = map_skew(self.getProcess());
113 end
114
115 function id = getIDC(self)
116 % IDC = GETIDC() % INDEX OF DISPERSION FOR COUNTS
117
118 lambda0 = self.getParam(1).paramValue;
119 lambda1 = self.getParam(2).paramValue;
120 sigma0 = self.getParam(3).paramValue;
121 sigma1 = self.getParam(4).paramValue;
122 id = 1 + 2*(lambda0-lambda1)^2*sigma0*sigma1/(sigma0+sigma1)^2/(lambda0*sigma1+lambda1*sigma0);
123 end
124
125 function id = getIDI(self)
126 % IDI = GETIDI() % INDEX OF DISPERSION FOR INTERVALS
127
128 id = self.getIDC(self); % only asymptotic for now
129 end
130
131 function n = getNumberOfPhases(~)
132 % N = GETNUMBEROFPHASES()
133 n = 2;
134 end
135
136 function acf = getACF(self, lags)
137 % ACF = GETACF(self, lags)
138
139 acf = map_acf(self.D,lags);
140 end
141
142 function [gamma2, gamma] = getACFDecay(self)
143 % [gamma2, gamma] = GETACFDECAY(self)
144 %
145 % gamma2: asymptotic decay rate of acf
146 % gamma: interpolated decay rate of acf
147
148 gamma2 = map_gamma2(self.D);
149 if nargout>1
150 gamma = map_gamma(self.D);
151 end
152 end
153
154 function bool = isImmediate(self)
155 % BOOL = ISIMMEDIATE()
156
157 bool = getMean(self) == 0;
158 end
159
160
161 function acf = evalACFT(self, lags, timescale)
162 % ACF = EVALACFT(self, lags)
163 %
164 % Evaluate the autocorrelation in counts at timescale t
165
166 acf = map_acfc(self.D, lags, timescale);
167 end
168 end
169
170 methods (Static)
171
172 function mmpp2 = rand()
173 % MMPP2 = RAND()
174 %
175 % Generate random MAP using uniform random numbers
176
177 D = mmpp_rand(2);
178 mmpp2 = MMPP2(D{1}(1,2), D{1}(2,1), D{2}(1,1), D{2}(2,2));
179 end
180
181 function mmpp2 = fitCentralAndIDC(mean, var, skew, idc)
182 if mean <= GlobalConstants.FineTol
183 mmpp2 = Exp(Inf);
184 else
185 scv = var/mean^2;
186 m = mmpp2_fit1(mean,scv,skew,idc);
187 mmpp2 = MMPP2(m{2}(1,1),m{2}(2,2),m{1}(1,2),m{1}(2,1));
188 end
189 end
190
191 function mmpp2 = fitCentralAndACFLag1(mean, var, skew, rho1)
192 if mean <= GlobalConstants.FineTol
193 mmpp2 = Exp(Inf);
194 else
195 scv = var/mean^2;
196 m = mmpp2_fit4(mean,scv,skew,rho1);
197 mmpp2 = MMPP2(m{2}(1,1),m{2}(2,2),m{1}(1,2),m{1}(2,1));
198 end
199 end
200
201 function mmpp2 = fitCentralAndACFDecay(mean, var, skew, gamma2)
202 if m1 <= GlobalConstants.FineTol
203 mmpp2 = Exp(Inf);
204 else
205 scv = var/mean^2;
206 m = mmpp2_fit2(mean,scv,skew,gamma2);
207 mmpp2 = MMPP2(m{2}(1,1),m{2}(2,2),m{1}(1,2),m{1}(2,1));
208 end
209 end
210
211 function mmpp2 = fitRawMomentsAndIDC(m1, m2, m3, idc)
212 if m1 <= GlobalConstants.FineTol
213 mmpp2 = Exp(Inf);
214 else
215 scv = (m2-m1^2)/m1^2;
216 gamma2=-(scv-idc)/(-1+idc);
217 m = mmpp2_fit3(m1,m2,m3,gamma2);
218 mmpp2 = MMPP2(m{2}(1,1),m{2}(2,2),m{1}(1,2),m{1}(2,1));
219 end
220 end
221
222 function mmpp2 = fitRawMomentsAndACFLag1(m1, m2, m3, rho1)
223 if m1 <= GlobalConstants.FineTol
224 mmpp2 = Exp(Inf);
225 else
226 scv = (m2-m1^2)/m1^2;
227 rho0 = (1-1/scv)/2;
228 gamma2 = rho1/rho0;
229 m = mmpp2_fit3(m1,m2,m3,gamma2);
230 mmpp2 = MMPP2(m{2}(1,1),m{2}(2,2),m{1}(1,2),m{1}(2,1));
231 end
232 end
233
234 function mmpp2 = fitRawMomentsAndACFDecay(m1, m2, m3, gamma2)
235 if m1 <= GlobalConstants.FineTol
236 mmpp2 = Exp(Inf);
237 else
238 m = mmpp2_fit3(m1,m2,m3,gamma2);
239 mmpp2 = MMPP2(m{2}(1,1),m{2}(2,2),m{1}(1,2),m{1}(2,1));
240 end
241 end
242
243 end
244end