Skip to content

Commit

Permalink
cleaning up, to account for move to nn-python
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Bachman committed Aug 13, 2014
1 parent 835cc33 commit c3a3ce2
Show file tree
Hide file tree
Showing 25 changed files with 61 additions and 8,702 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified LayerNet/.DS_Store
Binary file not shown.
52 changes: 50 additions & 2 deletions LayerNet/LDLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,60 @@
V = dLdA2 .* A1;
V = sum(V, 2);
dLdA1 = bsxfun(@rdivide, dLdA2, A1N) - ...
bsxfun(@times, A2, (V ./ (A1N.^2.0)));
bsxfun(@times, A2, (V ./ (A1N.^2)));
F = dLdA1 .* dA1dF;
end
return
end

function [ F ] = norm_tanh_trans(X, comp_type, dLdA2, Xin, Win)
% Transform the elements of X by normed tanh, or do backprop
assert((strcmp(comp_type,'ff')||strcmp(comp_type,'bp')),'ff/bp?');
EPS = 1e-3;
if (strcmp(comp_type,'ff'))
% Do feedforward
A1 = single(tanh(X));
A1N = sqrt(sum(A1.^2,2) + EPS);
F = bsxfun(@rdivide, A1, A1N);
else
% Do backprop
A1 = single(tanh(Xin * Win'));
A1N = sqrt(sum(A1.^2,2) + EPS);
A2 = bsxfun(@rdivide, A1, A1N);
% Compute stuff
dA1dF = 1 - A1.^2;
V = dLdA2 .* A1;
V = sum(V, 2);
dLdA1 = bsxfun(@rdivide, dLdA2, A1N) - ...
bsxfun(@times, A2, (V ./ (A1N.^2)));
F = dLdA1 .* dA1dF;
end
return
end

function [ F ] = norm_relu_trans(X, comp_type, dLdA2, Xin, Win)
% Transform the elements of X by normed tanh, or do backprop
assert((strcmp(comp_type,'ff')||strcmp(comp_type,'bp')),'ff/bp?');
EPS = 1e-3;
if (strcmp(comp_type,'ff'))
% Do feedforward
A1 = single(max(X, 0));
A1N = sqrt(sum(A1.^2,2) + EPS);
F = bsxfun(@rdivide, A1, A1N);
else
% Do backprop
A1 = single(max(Xin * Win', 0));
A1N = sqrt(sum(A1.^2,2) + EPS);
A2 = bsxfun(@rdivide, A1, A1N);
% Compute stuff
dA1dF = single((A1 > 0));
V = sum(dLdA2 .* A1, 2);
dLdA1 = bsxfun(@rdivide, dLdA2, A1N) - ...
bsxfun(@times, A2, (V ./ (A1N.^2)));
F = dLdA1 .* dA1dF;
end
return
end


function [ F ] = line_trans(X, comp_type, dLdA, Xin, Win)
% Leave the values in X unchanged. Or, backprop through the
Expand Down
Loading

0 comments on commit c3a3ce2

Please sign in to comment.