-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrain_filters.m
47 lines (35 loc) · 1.34 KB
/
train_filters.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
function train_filters(net, layerID, file2load, basesPath)
% trains the filters for the specific layer
% load data files
load(file2load); % loading data, i.e., X, etc
n_samples = 150000;
X = X(:, 1:n_samples);
if isinteger(X)
X = im2single(X);
end
if layerID > 1
% ToDo perform the convolution
fprintf('computing the activation functions on previous layers\n');
for i = 1:layerID-1
tic
X = feedForward(X, net.layer{i}, net.layer{layerID}, net.input_type);
toc
end
end
fprintf('removing the DC component\n');
X = removeDC(X);
fprintf('training filters of layer %d\n', layerID);
% perform PCA whitening
fprintf('whiten the data\n');
[V, E, D] = pca(X);
Z = V(1:net.layer{layerID}.pca_dim, :)*X;
saveFileName = [basesPath filesep net.layer{layerID}.base_id '.mat'];
fprintf('Estimating %s bases and saving them to \n %s\n', net.layer{layerID}.type, saveFileName);
switch lower(net.layer{layerID}.type)
case 'isa'
%estimate_isa(Z, V(1:net.layer{layerID}.pca_dim, :), net.layer{layerID}.pca_dim, net.layer{layerID}.group_size, saveFileName);
estimate_isaStochasticDescent(Z, V(1:net.layer{layerID}.pca_dim, :), net.layer{layerID}.pca_dim, net.layer{layerID}.group_size, saveFileName);
otherwise
error('the basis type, %s, is not supported', net.layer{ID}.type);
end
end