-
Notifications
You must be signed in to change notification settings - Fork 1
/
dicefg_handler_fit.m
56 lines (56 loc) · 3.24 KB
/
dicefg_handler_fit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function metric=dicefg_handler_fit(metric,dicefg_disp)
t_run = tic;
dicefg_disp(2,sprintf('Direct fitting from measurement selected (%s).',metric.Algorithm));
supportedAlgorithms = {'fit-mean','fit-erl','fit-exp','fit-gamma','fit-norm','fit-ph2','fit-map2'};
try
metric.Algorithm = validatestring(metric.Algorithm,supportedAlgorithms);
trace = get_data(metric,metric.Metric, metric.ResIndex, metric.ClassIndex);
switch metric.Algorithm
case 'fit-norm'
dicefg_disp(1,sprintf('Fitting normal distribution (%s).',metric.Algorithm))
[muhat,sigmahat,muci,sigmaci] = normfit(trace);
metric.Result = [muhat; sigmahat];
metric.ConfInt = [muci(1), muci(2); sigmaci(1), sigmaci(2)];
case 'fit-gamma'
dicefg_disp(1,sprintf('Fitting gamma distribution (%s).',metric.Algorithm))
metric.Result = gamfit(get_data(metric,metric.Metric,metric.ResIndex,metric.ClassIndex));
case 'fit-mean'
dicefg_disp(1,sprintf('Fitting mean only (%s).',metric.Algorithm))
metric.Result = mean(get_data(metric,metric.Metric,metric.ResIndex,metric.ClassIndex));
case 'fit-exp'
dicefg_disp(1,sprintf('Fitting exponential distribution (%s).',metric.Algorithm))
metric.Result = expfit(get_data(metric,metric.Metric,metric.ResIndex,metric.ClassIndex));
case 'fit-erl'
dicefg_disp(1,sprintf('Fitting Erlang distribution (%s).',metric.Algorithm))
% we fit an erlang by fitting a gamma and rounding
% up the shape parameter later on
metric.Result = gamfit(get_data(metric,metric.Metric,metric.ResIndex,metric.ClassIndex));
case 'fit-ph2'
dicefg_disp(1,sprintf('Fitting PH(2) distribution (%s).',metric.Algorithm))
trace = kpcfit_init(get_data(metric,metric.Metric,metric.ResIndex,metric.ClassIndex));
metric.Result = kpcfit_auto(trace,'OnlyAC',1,'NumStates',2,'MaxRunsAC',1);
if map_isfeasible(metric.Result)
g2 = 0; % acf decay rate - 0 since PH is a renewal process
PH2 = mmpp2_fit3(map_moment(metric.Result,1),map_moment(metric.Result,2),map_moment(metric.Result,3),g2);
if map_isfeasible(PH2)
metric.Result = PH2;
end
else
dicefg_disp(1,'Infeasible PH(2) fitting. Returning exponential.')
metric.Result = expfit(get_data(metric,metric.Metric,metric.ResIndex,metric.ClassIndex));
end
case 'fit-map2'
dicefg_disp(1,sprintf('Fitting MAP(2) process (%s).',metric.Algorithm))
trace = kpcfit_init(get_data(metric,metric.Metric,metric.ResIndex,metric.ClassIndex));
metric.Result = kpcfit_auto(trace,'OnlyAC',1,'NumStates',2,'MaxRunsAC',1);
if ~map_isfeasible(metric.Result) || length(metric.Result{1})==1
dicefg_disp(1,'Infeasible MAP(2) fitting. Returning exponential.')
metric.Result = expfit(get_data(metric,metric.Metric,metric.ResIndex,metric.ClassIndex));
end
end
catch err
error('Unexpected error (%s): %s', metric.Algorithm, err.message);
exit
end
dicefg_disp(2,sprintf('Fitting completed in %.6f seconds.',toc(t_run)));
end