-
Notifications
You must be signed in to change notification settings - Fork 1
/
adaboost_discriminant.m
38 lines (32 loc) · 1.03 KB
/
adaboost_discriminant.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
function [c] = adaboost_discriminant( data, mu, sigma, p, alpha, classes, T)
%DISCRIMINANT Computes the maximum A Posteriori (MAP) given the data
% INPUT data = data set, a MxN matrix
% INPUT mu = mean for data (bayes_weight.m)
% INPUT sigma = deviation for data (bayes_weight.m)
% INPUT p = prior probability (prior.m using weights)
% INPUT alpha =
% INPUT classes =
% INPUT t =
% RETURN c = a mx1 vector
%
% The discriminant function computes that given a pixel, how likely is it
% to belong to the hand image or the hand plus book image
% data - MxN matrix
% mu - CxN
% sigma- CxN
% g - MxC
% c - Mx1
N = size(data, 2); % N - antal dimensioner
M = size(data,1); % M - antal datapunkter
C = size(sigma, 1); % C - antal klasser
tempC = zeros(M,C);
for i = 1:T
g = discriminant(data, mu(:,:,i), sigma(:,:,i), p(i,:));
[~, class] = max(g, [], 2);
class = class - 1;
for j = 1:C
tempC(:,j) = tempC(:,j) + alpha(i) .* (class == classes(j));
end
end
[~, c] = max(tempC, [], 2);
c = c - 1;