1function [MAP,fac,fbc,kpcMAPs,otherMAPs, otherFACs, otherFBCs, otherSubMAPs]=kpcfit_auto(trace, varargin)
2% [MAP,fac,fbc,kpcMAPs] = kpcfit_auto(T,
'option1',val1,
'option2',val2,...)
5% Automatic fitting of trace T into a Markovian Arrival Process based on
6% the Kronecker Product Composition (KPC) method.
9% T - data structure returned by kpcfit_init
13% fac - best-found objective function value
for autocorrelation fitting (smaller = better)
14% fbc - best-found objective function value
for bicorrelation fitting (smaller = better)
15% kpcMAPs - MAP(2)s to were composed by Kronecker products to define MAP
19% MAP = kpcfit_auto(T,'NumMAPs',3,'MaxIterAC',10)
22% 'OnlyAC' - if 1 fitting
is performed on moments and autocorrelations
23% 'NumStates' - integer, equals log2(number of states of the final MAP), default: BIC heuristic
24% 'NumMAPs' - integer, equals log2(number of states of the final MAP), default: BIC heuristic
25% 'MaxRunsAC' - maximum number of autocorrelation fitting runs (run = optimization program execution)
26% 'MaxRunsBC' - maximum number of bicovariance fitting runs
27% 'MaxIterAC' - integer, maximum number of iterations for a single autocorrelation fitting run
28% 'MaxIterBC' - integer, maximum number of iterations for a single bicovariance fitting run
29% 'MaxResAC' - maximum number of autocorrelation fitting runs further considered in bicovariance fitting
30% 'ACLags' - autocorrelation lags to be fitted (e.g., 1:10)
31% 'BCGridLags' - lags defining bicovariance grid to be fitted (e.g., 1:5 gives a 25 points grid 1:5x1:5)
32% 'MaxRetMaps' - maximum number of MAPs returned
33% 'ParallelBC' - enable parallelization of BC runs
36% [1] G.Casale, E.Z.Zhang, E.Smirni. Trace Data Characterization and Fitting
37% for Markov Modeling, Elsevier Performance Evaluation, 67(2):61-79,
40% [2] G.Casale, E.Z.Zhang, E.Smirni. KPC-Toolbox: Simple Yet Effective Trace
41% Fitting Using Markovian Arrival Processes. in Proc. of QEST 2008,
42% 83-92, St.Malo, France, IEEE Press, September 2008.
74for i = 1:size(OptionNames,1)
75 options.(deblank(OptionNames(i,:)))=[];
79options.OnlyAC = false;
80options.AnimateAC = false;
82options.NumStates = [];
83options.MaxIterAC = 300; % iterate up to 300 times to fit autocorrelations
84options.MaxIterBC = 10; % iterate up to 10 times to fit bicorrelations
85options.MaxRunsAC = 50; % maximum number of runs for AC fitting
86options.MaxRunsBC = 30; % maximum number of runs for AC fitting
87options.MaxResAC = min([options.MaxRunsAC,10]); % maximum number of values returned for AC fitting
88options.MaxRetMAPs = 1; % maximum number of MAPs returned
89options.ParallelBC = 0; % parallelize BC runs
91% Parse Optional Parameters
92options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
93if mod(options.NumStates,2) > 0
94 error('error: requested %d states, but kpc-toolbox can return only a number of states that
is a power of 2');
96if isempty(options.NumMAPs)
97 options.NumMAPs = ceil(log2(options.NumStates));
100disp('** KPC fitting algorithm initialized **');
101%% fitting algorithm run parameterization
103if isempty(options.NumMAPs) % if MAP order not given, use automatic BIC selection
104 disp('init: performing order selection');
106 options.NumMAPs = kpcfit_sub_bic(trace.ACFull,[2 4 8 16 32 64 128]);
108 fprintf(2, "BIC order selection failed. Using 3 MAPs\n");
112fprintf(1,'init: kpc-toolbox will search for a MAP with 2^%d=%d states\n',options.NumMAPs,2^options.NumMAPs);
114disp('fitting: running KPC-based fitting script');
115[MAP,fac,fbc,kpcMAPs,otherMAPs, otherFACs, otherFBCs, otherSubMAPs]=kpcfit_manual(options.NumMAPs, ...
121 'MaxIterAC',options.MaxIterAC, ...
122 'MaxRunsAC',options.MaxRunsAC, ...
123 'MaxResAC',options.MaxResAC, ...
124 'MaxRunsBC',options.MaxRunsBC, ...
125 'MaxIterBC',options.MaxIterBC, ...
126 'OnlyAC',options.OnlyAC, ...
127 'AnimateAC',options.AnimateAC, ...
128 'MaxRetMAPs', options.MaxRetMAPs, ...
129 'ParallelBC', options.ParallelBC);
131%% display final moments and autocorrelations
132disp('** KPC fitting algorithm completed ** ');
134disp(' Moments Comparison ');
135disp(' Original Trace Fitted MAP');
137for k=1:length(trace.E)
138 disp([trace.E(k) map_moment(MAP,k)]);
141disp(' Autocorrelation Comparison ');
142disp(' Lag Original Trace Fitted MAP');
144for k=1:min([10,length(trace.ACLags)])
145 disp([trace.ACLags(k) trace.AC(k) map_acf(MAP,k)]);