-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMultipleIterationsOfTheExperiment.m
134 lines (122 loc) · 4.66 KB
/
MultipleIterationsOfTheExperiment.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
129
130
131
132
133
134
% Set parameters for random generation
Size = 300;
p = 10;
k = 3;
metricBasePath = 'experiment_data/metrics/';
segmentationBasePath = 'experiment_data/segmentations/';
%{
T_simple = cell2table(cell(0,8), 'VariableNames', ...
{
'HMRF_MCEM_LastSample', 'HMRF_MCEM_MAP', ...
'K_Means', 'GrabCut', ...
'HMRF_EM_Expansion', 'HMRF_EM_Swap', ...
'HMRF_VEM_LastSample', 'HMRF_VEM_MAP'
});
T_jaccard = cell2table(cell(0,8), 'VariableNames', ...
{
'HMRF_MCEM_LastSample', 'HMRF_MCEM_MAP', ...
'K_Means', 'GrabCut', ...
'HMRF_EM_Expansion', 'HMRF_EM_Swap', ...
'HMRF_VEM_LastSample', 'HMRF_VEM_MAP'
});
T_ssim = cell2table(cell(0,8), 'VariableNames', ...
{
'HMRF_MCEM_LastSample', 'HMRF_MCEM_MAP', ...
'K_Means', 'GrabCut', ...
'HMRF_EM_Expansion', 'HMRF_EM_Swap', ...
'HMRF_VEM_LastSample', 'HMRF_VEM_MAP'
});
%}
%results = zeros([100, 11]);
%T = readtable('exp_data.csv');
%start = 0;
%for i=1:100
% if results(i, 1) == 0
% start = i;
% break;
% end
%end
% Use pre-generated params for reproduceability
load('good_params')
%start=0;
tic;
for i=81:100
InitY = randi(k, [Size, Size]);
[data, gt]=GenerateSynteticData(InitY, p, k, 2, mus, kappas, 20, 4);
s.name = 'GroundTruth';
s.data = reshape(data, [Size,Size,p]);
s.segmentation = reshape(gt, [Size,Size]);
s.beta = 2;
s.kappas = kappas;
s.mus = mus;
save(strcat(segmentationBasePath, s.name, '_', num2str(i)),'s');
% MCEM
[final_segm_mcem, ~, mus_mcem, kappas_mcem, final_segm_mcem2] = HMRF_MCEM(data, randi(k,[Size, Size]), k, 2, close_mus, close_kappas, 10, 10, 10, 4);
s.name = 'HMRF_MCEM_LastSample';
s.segmentation = reshape(final_segm_mcem, [Size,Size]);
s.beta = 2;
s.kappas = kappas_mcem;
s.mus = mus_mcem;
save(strcat(segmentationBasePath, s.name, '_', num2str(i)),'s');
s.name = 'HMRF_MCEM_MAP';
s.segmentation = reshape(final_segm_mcem2, [Size,Size]);
s.beta = 2;
s.kappas = kappas_mcem;
s.mus = mus_mcem;
save(strcat(segmentationBasePath, s.name, '_', num2str(i)),'s');
% Kmeans
final_segm_kmeans = kmeans(data, k);
D = vmffactory(p);
kappas_kmeans = zeros([1, k]);
mus_kmeans = zeros([k, p]);
for j=1:k
data_in_k = data(final_segm_kmeans==j, :);
params = D.estimatedefault(data_in_k');
mus_kmeans(j, :) = squeeze(params.mu);
kappas_kmeans(j) = params.kappa;
end
s.name = 'K_Means';
s.segmentation = reshape(final_segm_kmeans, [Size,Size]);
s.beta = 2;
s.kappas = kappas_kmeans;
s.mus = mus_kmeans;
save(strcat(segmentationBasePath, s.name, '_', num2str(i)),'s');
% Grab Cut
[final_segm_grc, mus_grc, kappas_grc] = Grab_Cut(data, reshape(final_segm_kmeans, [Size,Size]), k, 10, 40, close_mus, close_kappas, 5, 10, 4);
s.name = 'Grab_Cut';
s.segmentation = reshape(final_segm_grc, [Size,Size]);
s.beta = 2;
s.kappas = kappas_grc;
s.mus = mus_grc;
save(strcat(segmentationBasePath, s.name, '_', num2str(i)),'s');
% Hmrf EM
[final_segm_expansion, ~, mus_expansion, kappas_expansion] = HMRF_EM(data, randi(k,[Size, Size]), k, 2, close_mus, close_kappas, 10, 10, 4, 'expansion');
s.name = 'HMRF_EM_Expansion';
s.segmentation = reshape(final_segm_expansion, [Size,Size]);
s.beta = 2;
s.kappas = kappas_expansion;
s.mus = mus_expansion;
save(strcat(segmentationBasePath, s.name, '_', num2str(i)),'s');
[final_segm_swap, ~, mus_swap, kappas_swap] = HMRF_EM(data, randi(k,[Size, Size]), k, 2, close_mus, close_kappas, 10, 10, 4, 'swap');
s.name = 'HMRF_EM_Swap';
s.segmentation = reshape(final_segm_expansion, [Size,Size]);
s.beta = 2;
s.kappas = kappas_swap;
s.mus = mus_swap;
save(strcat(segmentationBasePath, s.name, '_', num2str(i)),'s');
[final_segm_vem, ~, mus_vem, kappas_vem, final_segm_vem2] = HMRF_VEM(reshape(data, [Size,Size,p]), p, k, 2, close_mus, close_kappas, 0.5, 50, 20, 4);
s.name = 'HMRF_VEM_LastSample';
s.segmentation = reshape(final_segm_vem, [Size,Size]);
s.beta = 2;
s.kappas = kappas_swap;
s.mus = mus_swap;
save(strcat(segmentationBasePath, s.name, '_', num2str(i)),'s');
s.name = 'HMRF_VEM_MAP';
s.segmentation = reshape(final_segm_vem2, [Size,Size]);
s.beta = 2;
s.kappas = kappas_swap;
s.mus = mus_swap;
save(strcat(segmentationBasePath, s.name, '_', num2str(i)),'s');
end
toc;
%boxplot([s_mcem, s_expansion, s_grc, s_swap, s_kmeans], 'Notch','on', 'Labels',{'mcem','hmrf-em (exp)', 'grab cut', 'hmrf-em (swap)', 'kmeans'});