-
Notifications
You must be signed in to change notification settings - Fork 2
/
HMRF_EM.m
46 lines (45 loc) · 2.05 KB
/
HMRF_EM.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
%% Àëãîðèòì ïîñëåäîâàòåëüíîé îöåíêè ïàðàìåòðîâ ïîñðåäñòâîì íàõîæäåíèÿ MAP-îöåíêè
%---input---------------------------------------------------------
% data: èñõîäíûå äàííûå, ìàòðèöà NxP, N - êîëè÷åñòâî ïèêñåëåé
% dim: ðàçìåð ìàòðèöû ôèíàëüíîé ñåãìåíòàöèè
% k: êîëè÷åñòâî ìåòîê
% beta: íà÷àëüíîå çíà÷åíèå ïàðàìåòðà ìîäåëè Ïîòòñà, ñêàëÿð
% mus: íà÷àëüíîå çíà÷åíèå ïàðàìåòðà vMF, ìàòðèöà LxP
% kappas: íà÷àëüíîå çíà÷åíèå ïàðàìåòðà vMF, âåêòîð Lx1
% map_iter: ìàêñèìàëüíîå êîëè÷åñòâî èòåðàöèé äëÿ íàõîæäåíèÿ MAP-îöåíêè
% max_iter: ìàêñèìàëüíîå êîëè÷åñòâî èòåðàöèé
% neighbours_count: êîëè÷åñòâî ñîñåäåé, äîñòóïíûå çíà÷åíèÿ
% 2-D: 4, 8, 16
% 3-D: 6, 26
% method: ìåòîä íàõîæäåíèÿ MAP-îöåíêè, äîñòóïíûå çíà÷åíèÿ
% expansion
% swap
%---output--------------------------------------------------------
% sample: ôèíàëüíàÿ ñåãìåíòàöèÿ
% beta: îöåíåííîå çíà÷åíèå beta
% mus: îöåíåííîå çíà÷åíèå mus
% kappas: îöåíåííîå çíà÷åíèå kappas
function [sample, beta, mus, kappas, all_mus, all_kappas] = HMRF_EM(data, segment_init, k, beta, mus, kappas, map_iter, max_iter, neighbours_count, method)
p = size(data, 2);
all_mus = zeros([max_iter, size(mus)]);
all_kappas = zeros([max_iter, size(kappas)]);
for i=1:max_iter
fprintf('\tIteration: %d out of %d\n',i,max_iter);
% ñ÷èòàåì âåðîÿòíîñòè
[~, logprobs] = CalculateLikelihoodProbabilities(data, k, kappas, mus, segment_init);
% ãåíåðèðóåì íà÷àëüíóþ êîíôèãóðàöèþ
%segment_init = randi(k, dim);
% èùåì MAP-îöåíêó
switch method
case "expansion"
[sample, energy] = MRF_MAP_GraphCutAExpansion(segment_init, logprobs, beta, k, map_iter, neighbours_count);
case "swap"
[sample, energy] = MRF_MAP_GraphCutABSwap(segment_init, logprobs, beta, k, map_iter, neighbours_count);
otherwise
error('Unknown method')
end
% íàñòðàèâàåì ïàðàìåòðû
[beta, mus, kappas] = EstimateParametersHMRFEM(data, sample, energy, k, p, beta, mus, kappas);
all_mus(i, :, :) = mus;
all_kappas(i, :) = kappas;
end