-
Notifications
You must be signed in to change notification settings - Fork 3
/
infomax.m
52 lines (45 loc) · 1.29 KB
/
infomax.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
% Face Recognition using Independent Component Analysis (ICA)
% Created on Mar 2015
% Authors: Sid Ali Rezetane, Sina M. Baharlou, Harold Agudelo
% calculate demixing matrix using infoMax algorithm
% x = input signal
% bs = block size
% epochs
% lr = learning rate
% wh = whittening the data
% ----
% W = demixing matrix
% A = mixing matrix
% U = independent signals
function [U, A, W] = infomax(x, blockSize, epochs, lr, wh)
% get the size of input matrix
[N, P] = size(x);
if (wh == true)
fprintf('Whitening input data...\n');
[x, wz] = whiten(x);
end
fprintf('Performing infoMax...\n');
% initialize W with random numbers near zero
W = randn(N) * 0.01;
% divide input signal to blocks of size 'blockSize'
blockCount = floor(P / blockSize);
% start the iteration
for i = 1:epochs
% update W for each block
for j = 1:blockSize:blockCount * blockSize
% calculate u
u = W * x(:, j:j + blockSize - 1);
% sigmoid activation function
y = 1 ./ (1 + exp(- u));
% update W
W = W + lr * ((eye(N) + (1 - 2 * y) * u')*W);
end
fprintf('.')
end
fprintf('\n');
U = W * x;
if (wh == true)
W = W * wz;
end
A = inv(W);
end