1function [bestMAP,fac,fbc,subMAPs,otherMAPs, otherFACs, otherFBCs, otherSubMAPs]=kpcfit_manual(NumMAPs,E,AC,ACLags,BC,BCLags,varargin)
4% Fitting of trace S into a Markovian Arrival Process based on Kronecker
5% Product Composition (KPC) theory
using manual parameter specification.
8%
'OnlyAC' - boolean,
if true fitting
is performed on moments and
9%
'MaxIterAC' - integer, maximum number of iterations
for a single autocorrelation fitting run
10%
'MaxIterBC' - integer, maximum number of iterations
for a single bicovariance fitting run
11%
'MaxRunsAC' - maximum number of autocorrelation fitting runs
12%
'MaxRunsBC' - maximum number of bicovariance fitting runs
13%
'MaxResAC' - maximum number of autocorrelation fitting further analyzed
for bicovariance fitting
40for i = 1:size(OptionNames,1)
41 options.(deblank(OptionNames(i,:)))=[];
44options.OnlyAC = false; % by default fit also bicovariances
45options.AnimateAC = false; % by default fit also bicovariances
46options.MaxIterAC = 300; % iterate up to 300 times to fit autocorrelations
47options.MaxIterBC = 10; % iterate up to 10 times to fit bicorrelations
48options.MaxRunsAC = 50; % maximum number of runs for AC fitting
49options.MaxRunsBC = 30; % maximum number of runs for AC fitting
50options.MaxResAC = min([options.MaxRunsAC,10]); % maximum number of values returned for AC fitting
51options.MaxRetMAPs = 1; % maximum number of MAPs returned
52options.ParallelBC = 0; % parallelize BC runs
55% Parse Optional Parameters
56options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
59%% fit autocorrelations
61[resSCV,resG2,fobjAC] = kpcfit_sub_acfit(E,AC,ACLags,NumMAPs,options.MaxIterAC,options.MaxRunsAC,options.MaxResAC,options.AnimateAC);
65resE1 = cell(length(resSCV),1);
66resE3 = cell(length(resSCV),1);
67fobjBC = zeros(length(resSCV),1);
69if options.OnlyAC == false
70 if options.ParallelBC > 0
71 parfor i = 1:length(resSCV)
72 fprintf(1,'fitting: processing acfit subresult %d of top %d\n',i,length(resSCV));
73 [E1j,E3j,foBC] = kpcfit_sub_bcfit(E,resSCV{i},resG2{i},BC,BCLags,options.MaxIterBC,options.MaxRunsBC);
79 for i = 1:length(resSCV)
80 fprintf(1,
'fitting: processing acfit subresult %d of top %d\n',i,length(resSCV));
81 [E1j,E3j,foBC] = kpcfit_sub_bcfit(E,resSCV{i},resG2{i},BC,BCLags,options.MaxIterBC,options.MaxRunsBC);
87elseif options.OnlyAC ==
true
88 for i = 1:length(resSCV)
89 resE1{i} = ones(1,NumMAPs);
90 resE3{i} = (3/2+0.01).*(1+resSCV{i}).^2;
94 error(
'value of OnlyAC must be true or false')
97%% determine best result
98[v,ind] = sort(fobjBC,1,'ascend');
100% truncate bicorrelations when it gets negative
102for index=1:size(BCLags,1)
103 if find(diff(BCLags(index,:))<0)
110%% compose intermediate results into final MAPs
121 [newMAP,newSubMAPs,errorCode]=kpcfit_sub_compose(resE1{index},resSCV{index},resE3{index},resG2{index}, COMPOSE_VERBOSE);
122 if errorCode ~= 0 || isempty(newMAP)
123 fprintf(
"[%d] Discarded (errorCode=%d).\n", k, errorCode);
127 % scale MAP to match mean exactly
128 newMAP=map_scale(newMAP,E(1));
130 % Compute value of obj. functions
for the resulting MAP
131 [newfAC,newfBC]=evaluate_obj_function(newMAP);
133 composedMAPs = composedMAPs + 1;
135 MAPs{composedMAPs} = newMAP;
136 FACs(composedMAPs) = newfAC;
137 FBCs(composedMAPs) = newfBC;
138 subs{composedMAPs} = newSubMAPs;
140 if COMPOSE_VERBOSE > 0
141 fprintf(1,
"[%d] OK - fac= %f; fbc= %f\n", k, newfAC, newfBC);
144 if composedMAPs == options.MaxRetMAPs
152 fprintf(2,
"+++ KPC FAILED +++\n");
158 fprintf(1,
"Returned %d MAPs:\n", composedMAPs);
159 fprintf(1,
'1) fAC=%f, fBC=%f, SCV=%f, ACF(1)=%f, SKEW=%f\n', ...
160 fac, fbc, map_scv(bestMAP), map_acf(bestMAP,1), map_skew(bestMAP));
165 otherSubMAPs=cell(1,0);
168 for i=1:composedMAPs-1
169 otherMAPs{end+1} = MAPs{1+i};
170 otherFACs(end+1) = FACs(1+i);
171 otherFBCs(end+1) = FBCs(1+i);
172 otherSubMAPs{end+1} = subs{1+i};
173 fprintf(1,
'%d) fAC=%f, fBC=%f, SCV=%f, ACF(1)=%f, SKEW=%f\n', ...
174 i+1, otherFACs(i), otherFBCs(i), map_scv(otherMAPs{i}), ...
175 map_acf(otherMAPs{i},1), map_skew(otherMAPs{i}));
183 function [objAC,objBC] = evaluate_obj_function (
map)
184 tSCV=(E(2)-E(1)^2)/E(1)^2;
185 objAC=norm((AC-map_acf(
map, ACLags)
'),1)/norm(AC,2) + (map_scv(map) - tSCV)^2/tSCV^2;
187 mapBC=ones(1,size(BCLags,1));
188 for j=1:size(BCLags,1)
189 mapBC(j)=map_joint(map,BCLags(j,:),[1,1,1]);
191 objBC = norm(BC-mapBC,2)/norm(BC,2);