1function PH_EXACT = kpcfit_ph_exact(E,options)
2% Not
for direct call, auxiliary function.
5SCV = ( E(2) - E(1)^2 ) / E(1)^2;
8 fprintf(sprintf(
'kpcfit_ph: HIGHER variability than an exponential (var/mean^2 = %f)\n\n',SCV));
9 fprintf(
'kpcfit_ph: starting exact hyper-exponential fitting method (Prony\''s method)\n
');
11 for n = 2:options.MaxNumStates
14 fprintf(sprintf('kpcfit_ph: not enough moments given in input to fit hyper-exp(%d)\n
',n))
18 PH = kpcfit_ph_prony(E, n);
19 if map_isfeasible(PH) > 0
22 fprintf(sprintf('\t\t\thyper-exp(%d): feasible, matched exactly %d moments. result saved.\n
',n,2*n-1))
26 fprintf(sprintf('\t\t\thyper-exp(%d): infeasible to fit exactly.\n
',n))
33 fprintf(sprintf('kpcfit_ph: LOWER variability than an exponential (var/mean^2 = %f)\n\n
',SCV))
40 fprintf(sprintf('kpcfit_ph: exact fitting of E[X^2] requires at least %d states\n
',n))
42 if options.MinExactMom >= 2 & options.MaxNumStates < n
44 fprintf(sprintf('kpcfit_ph: impossible to fit exactly E[X^2] with MaxNumStates = %d, increasing to MaxNumStates = %d.\n
',options.MaxNumStates,n))
51 fprintf(sprintf('kpcfit_ph: attempting PH(2) fitting method\n
',n));
53 PH = map2_fit(E(1),E(2),E(3),0);
55 PH = map2_fit(E(1),E(2),-1,0);
59 fprintf(sprintf('\t\t\tph(2): feasible, matched exactly 2 moments. result saved.\n
',n))
62 error('anomalous set of moments, please check.
');
67 fprintf(sprintf('\t\t\tph(2): feasible, matched exactly 3 moments. result saved.\n
',n))
70 elseif (SCV > 1/n - kpcfit_tol) && (SCV < 1/n + kpcfit_tol)
71 ERL = map_erlang(E(1),n); % exponential PH-renewal
72 if norm(E - map_moment(ERL,1:length(E))) < kpcfit_tol
74 fprintf(sprintf('kpcfit_ph: erlang moment set. fitted erlang-%d. result saved.\n
',n))
76 PH_EXACT{end+1} = ERL;
79 % fprintf('kpcfit_ph: no exact fitting method available for this moment set.\n
');
80 maxorder = options.MaxNumStates;
82 fprintf(sprintf('kpcfit_ph: fitting APH distribution (best effort, max order = %d).\n
',maxorder));
85 PH = aph_fit(E(1),E(2),E(3),maxorder);
87 % fprintf(sprintf('kpcfit_ph: fitted APH(%d) distribution.\n
',length(PH{1})));
89 for k=1:(2*length(PH{1})-1)
90 if abs(E(k)-map_moment(PH,k)) < kpcfit_tol*map_moment(PH,k)
91 aph_matched = aph_matched + 1;
95 fprintf(sprintf('\t\t\t
aph(%d): feasible, matched exactly %d moments. result saved.\n
',length(PH{1}),aph_matched))
100 fprintf('kpcfit_ph: cannot fit APH distribution.\n
');
107 fprintf(sprintf('kpcfit_ph: SAME variability than an exponential (var/mean^2 = %f)\n\n
',SCV))
109 EXP = {[-1/E(1)],[1/E(1)]}; % exponential PH-renewal
110 if norm(E - map_moment(EXP,1:length(E))) < kpcfit_tol
112 fprintf('kpcfit_ph: exponential moment set. fitted exponential. result saved.\n
')
115 PH_EXACT{end+1} = EXP;