1classdef (Sealed) Cox2 < Markovian
2 % Static
class to fit two-phase coxian statistical distribution
4 % Copyright (c) 2012-2026, Imperial College London
8 function cx = fit(MEAN,SCV,SKEW)
9 % CX = FIT(MEAN,SCV,SKEW)
11 cx = Cox2.fitCentral(MEAN,SCV*MEAN^2,SKEW);
13 jline_mu = java.util.ArrayList();
14 jline_phi = java.util.ArrayList();
15 if length(line_dist.params) == 3
16 jline_mu.add(cx.getParam(1).paramValue);
17 jline_mu.add(cx.getParam(2).paramValue);
18 jline_phi.add(cx.getParam(3).paramValue);
20 mu = line_dist.getParam(1).paramValue;
21 phi = line_dist.getParam(2).paramValue;
27 jline_phi.add(phi(i));
30 cx.obj = jline.lang.processes.Coxian(jline_mu, jline_phi);
33 function cx = fitCentral(MEAN,VAR,SKEW)
34 % CX = FITCENTRAL(MEAN,VAR,SKEW)
36 % Fit the distribution from first three central moments (mean,
40 cx = Cox2.fitMeanAndSCV(MEAN,SCV);
45 e3 = -(2*e1^3-3*e1*e2-SKEW*(e2-e1^2)^(3/2));
46 % consider the two possible solutions
47 phi = (6*e1^3 - 6*e2*e1 + e3)/(- 6*e1^3 + 3*e2*e1);
49 (2*(e3 - 3*e1*e2))/(- 3*e2^2 + 2*e1*e3) + (3*e1*e2 - e3 + (24*e1^3*e3 - 27*e1^2*e2^2 - 18*e1*e2*e3 + 18*e2^3 + e3^2)^(1/2))/(- 3*e2^2 + 2*e1*e3)
50 (2*(e3 - 3*e1*e2))/(- 3*e2^2 + 2*e1*e3) - (e3 - 3*e1*e2 + (24*e1^3*e3 - 27*e1^2*e2^2 - 18*e1*e2*e3 + 18*e2^3 + e3^2)^(1/2))/(- 3*e2^2 + 2*e1*e3)
53 -(3*e1*e2 - e3 + (24*e1^3*e3 - 27*e1^2*e2^2 - 18*e1*e2*e3 + 18*e2^3 + e3^2)^(1/2))/(- 3*e2^2 + 2*e1*e3)
54 (e3 - 3*e1*e2 + (24*e1^3*e3 - 27*e1^2*e2^2 - 18*e1*e2*e3 + 18*e2^3 + e3^2)^(1/2))/(- 3*e2^2 + 2*e1*e3)];
55 if phi>=0 && phi<=1 && mu1(1) >= 0 && mu2(1) >= 0
56 %
if the first solution
is feasible
57 cx = Coxian([mu1(1),mu2(1)],[phi,1]);
58 elseif phi >=0 && phi <=1 && mu1(2) >= 0 && mu2(2) >= 0
59 %
if the second solution
is feasible
60 cx = Coxian([mu1(2),mu2(2)],[phi,1]);
62 line_warning(mfilename,
'Cox2.fitCentral: Third moment could not be fitted exactly.\n');
65 %line_warning(mfilename,
'Infeasible combination of central moments, fitting only mean and squared coefficient of variation.');
66 cx = Cox2.fitMeanAndSCV(MEAN, SCV);
68 %line_warning(mfilename,
'Infeasible combination of central moments, fitting only mean.');
69 cx = Cox2.fitMean(MEAN);
74 function cx = fitMean(MEAN)
77 p = 1.0-GlobalConstants.CoarseTol;
80 cx = Coxian([l0,l1],[p,1]);
83 function cx = fitMeanAndSCV(MEAN, SCV)
84 % CX = FITMEANANDSCV(MEAN, SCV)
86 % Fit a 2-phase Coxian distribution with given mean and squared coefficient of variation (SCV=variance/mean^2)
87 if (SCV <1 && SCV >=0.5)
88 l0 = 2/MEAN/(1+sqrt(1+2*(SCV-1)));
89 l1 = 2/MEAN/(1-sqrt(1+2*(SCV-1)));
100 cx = Coxian([l0,l1],[p,1]);