Skip to content

Commit

Permalink
fixes rasmusbergpalm#21. Thanks @skaae
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusbergpalm committed Mar 3, 2013
1 parent 918c1a1 commit 44eaad5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions SAE/saetrain.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
sae.ae{i} = nntrain(sae.ae{i}, x, x, opts);
t = nnff(sae.ae{i}, x, x);
x = t.a{2};
%remove bias term
x = x(:,2:end);
end
end
36 changes: 36 additions & 0 deletions tests/test_example_SAE.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,39 @@
nn = nntrain(nn, train_x, train_y, opts);
[er, bad] = nntest(nn, test_x, test_y);
assert(er < 0.16, 'Too big error');

%% ex2 train a 100-100 hidden unit SDAE and use it to initialize a FFNN
% Setup and train a stacked denoising autoencoder (SDAE)
rng(0);
sae = saesetup([784 100 100]);
sae.ae{1}.normalize_input = 0;
sae.ae{1}.activation_function = 'sigm';
sae.ae{1}.learningRate = 1;
sae.ae{1}.inputZeroMaskedFraction = 0.5;

sae.ae{2}.normalize_input = 0;
sae.ae{2}.activation_function = 'sigm';
sae.ae{2}.learningRate = 1;
sae.ae{2}.inputZeroMaskedFraction = 0.5;

opts.numepochs = 1;
opts.batchsize = 100;
sae = saetrain(sae, train_x, opts);
visualize(sae.ae{1}.W{1}(:,2:end)')

% Use the SDAE to initialize a FFNN
nn = nnsetup([784 100 100 10]);
nn.normalize_input = 0;
nn.activation_function = 'sigm';
nn.learningRate = 1;

%add pretrained weights
nn.W{1} = sae.ae{1}.W{1};
nn.W{2} = sae.ae{2}.W{1};

% Train the FFNN
opts.numepochs = 1;
opts.batchsize = 100;
nn = nntrain(nn, train_x, train_y, opts);
[er, bad] = nntest(nn, test_x, test_y);
assert(er < 0.1, 'Too big error');

0 comments on commit 44eaad5

Please sign in to comment.