-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats_get_pphpc.m
85 lines (76 loc) · 2.88 KB
/
stats_get_pphpc.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function sdata = stats_get_pphpc(args, file, num_outputs)
% STATS_GET_PPHPC Obtain the max, argmax, min, argmin, mean and std
% statistical summaries from simulation outputs given in a file.
%
% stats = STATS_GET_PPHPC(args, file, num_outputs)
%
% Parameters:
% args - Iteration after which outputs are in steady-state (for mean
% and std statistical summaries).
% file - File containing simulation outputs, columns correspond to
% outputs, rows correspond to iterations.
% num_outputs - Number of outputs in file.
%
% Returns:
% sdata - A 6 x num_outputs matrix, with 6 statistical summaries and
% num_outputs outputs. If no arguments are given, this
% function returns a struct with two fields:
% text - Cell array of strings containing the names of the
% statistical measures in plain text.
% latex - Cell array of strings containing the names of the
% statistical measures in LaTeX format.
%
% Notes:
% The names of the statistical summaries in LaTeX format assume the
% following LaTeX definitions:
% % For \argmax and \argmin
% \@ifpackageloaded{amsmath}{
% \DeclareMathOperator*{\argmax}{arg\,max}
% \DeclareMathOperator*{\argmin}{arg\,min}}
% {}
% \makeatother
% % For \mean
% \newcommand*\mean[1]{\overline{#1}}
%
%
% Copyright (c) 2015 Nuno Fachada
% Distributed under the MIT License (See accompanying file LICENSE or copy
% at http://opensource.org/licenses/MIT)
%
% The first argument is the steady-state truncation point.
ss_idx = args;
% If only the first argument is given...
if nargin == 1
% ...return names of statistic summaries
sdata = struct(...
'text', {{'max', 'argmax', 'min', 'argmin', 'mean', 'std'}}, ...
'latex', {{'\max', '\argmax', '\min', '\argmin', ...
'\mean{X}^{\text{ss}}', 'S^{\text{ss}}'}});
return;
end;
% Read stats file
data = dlmread(file);
dataLen = size(data, 1);
% Initialize stats matrix
sdata = zeros(6, num_outputs);
% Determine stats for each of the outputs
for i = 1:num_outputs
% Iterations start at zero, but Matlab starts indexing at 1, so we have
% to subtract index by one.
% Get current output
curOutput = data(:, i);
% Get maximum
curMax = max(curOutput);
% Get iteration where maximum occurs
curArgMax = find(curOutput == curMax, 1) - 1;
% Get minimum
curMin = min(curOutput);
% Get iteration where minimum occurs
curArgMin = find(curOutput == curMin, 1) - 1;
% Get steady-state mean
curMean = mean(curOutput((ss_idx + 1):dataLen));
% Get steady-state standard deviation
curStd = std(curOutput((ss_idx + 1):dataLen));
% Place current output statistics in output variable
sdata(:, i) = [curMax; curArgMax; curMin; curArgMin; curMean; curStd];
end;