-
Notifications
You must be signed in to change notification settings - Fork 1
/
HAL_isomatrix_uncertainty.m
128 lines (105 loc) · 3.79 KB
/
HAL_isomatrix_uncertainty.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function [] = HAL_isomatrix_uncertainty(id,varargin)
p = inputParser;
% if odd number of arguments:
if ((mod(nargin,2) == 0) && (nargin > 1))
% no user specified id, with extra arguments
varargin = [ { id }, varargin ];
id=[1,2,3];
addOptional(p,'id',id);
elseif (nargin == 0)
% no user specified id, with no extra arguments
id=[1,2,3];
end
%% set up default values for optional parameters: ('Labels')
labels = {'','',''};
defaultFilename = 'IsoMaTrixGrid.csv';
% validation of user input labels:
errorMsg1 = strcat('Labels error: please provide vector of size=3.');
errorMsg2 = 'Incorrect label formatting (must be cell-array).';
labelLength = @(x) assert(length(x)==3,errorMsg1);
labelType = @(x) assert(length(x)==3,errorMsg2); % this is incorrect
isstringy = @(x) assert(ischar(x),'Filename must be a string');
addParameter(p,'Labels',labels);
% read in optional parameters
[nParams] = length(varargin);
for param = 1:1:(nParams/2)
ind = (param-1)*2 + 1;
if strcmp(varargin{ind}, 'Labels')
labels=varargin{ind+1};
labelLength(labels);
labelType(labels);
elseif strcmp(varargin{ind}, 'Filename')
defaultFilename=varargin{ind+1};
% check if string
isstringy(defaultFilename);
end
end
h = gcf;
figure_number=h.Number;
figure(figure_number); hold on;
% string concatenate filepath:
filepath = strcat('HALMatrixGame/HALMatrix-output/',defaultFilename);
%% read in data
data = dlmread(filepath,',',2,0);
x0 = data(:,1:3);
xF = data(:,4:6);
sims = max(data(:,7))+1;
gridlines = max(data(:,8));
%% set up meshgrid
step = 1/gridlines;
x_grid = 0:step:(1);
y_grid = x_grid;
[P,Q] = meshgrid(x_grid,y_grid); % Generate domain.
N = sum(x0(1,:));
grid_step = N/gridlines;
%% remove irrelevant area of domain (outside triangle)
w = P + Q;
out = w > 1;
P(out) = nan;
Q(out) = nan;
%% coordinate transformation
y1 = (P./(tan(pi/3)) + (1-P-Q)./(sin(pi/3)))*sin(pi/3);
y2 = P * (1/2)*tan(60*pi/180);
%% prepare matrices
[rows,~] = size(data);
[n,m] = size(P);
Z = zeros(n,m); Zsd = zeros(n,m);
Z1 = zeros(n,m); Z1sd = zeros(n,m);
Z2 = zeros(n,m); Z2sd = zeros(n,m);
Z3 = zeros(n,m); Z3sd = zeros(n,m);
for row = 1:sims:rows
j = round(x0(row,1)/grid_step) + 1;
i = round(x0(row,2)/grid_step) + 1;
R = xF(row:(row+sims-1),:) - x0(row:(row+sims-1),:);
Z1(i,j) = mean(R(:,1)); Z1sd(i,j) = std(R(:,1));
Z2(i,j) = mean(R(:,2)); Z2sd(i,j) = std(R(:,2));
Z3(i,j) = mean(R(:,3)); Z3sd(i,j) = std(R(:,3));
% mean of the mags, not mag of the means
Mag = sqrt(R(:,1).^2 + R( :,2).^2 + R( :,3).^2);
Z(i,j) = mean(Mag);
Zsd(i,j) = std(Mag);
end
if (length(id) == 3)
BINS = 10;
[~,h]=contourf(y1,y2,Zsd,BINS);hold on;
set(h,'LineColor','none');
cmap = pink; %get current colormap
cmap=cmap(10:end,:); % remove black regions of this colormap
colormap(gca,cmap);colorbar('FontSize',16);
else
BINS = 40;
Zsd = Z3sd;
if (id == 1)
Zsd = Z1sd;
elseif (id == 2)
Zsd = Z2sd;
end
%% plot uncertainty, too
[~,h]=contourf(y1,y2,Zsd,BINS);
set(h,'LineColor','none');
cmap = pink; %get current colormap
cmap=cmap(10:end,:); % remove black regions of this colormap
colormap(gca,cmap);colorbar('FontSize',16);
end
add_labels(labels);
end