Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions SparseDeepNeuralNetwork/matlab/inferenceReLUvec.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,39 @@

% Initialized feature vectors.
Y = Y0;
octaveinfo=exist('octave_config_info');
% If using Matlab take advantage of sparse implementation
% of singleton expansion, otherwise for Octave use
% bsxfun
if(octaveinfo==0)
% Loop through each weight layer W{i}
for i=1:length(W)

% Loop through each weight layer W{i}
for i=1:length(W)
% Propagate through layer.
% Note: using graph convention of A(i,j) means connection from i *to* j,
% that requires *left* multiplication feature *row* vectors.
Z = Y*W{i};
b = bias{i};
% Apply bias to non-zero entries.
Y = Z + sparse(double(logical(Z)) .* b);
% Threshold negative values.
Y(Y < 0) = 0;
end
else
% Loop through each weight layer W{i}
for i=1:length(W)

% Propagate through layer.
% Note: using graph convention of A(i,j) means connection from i *to* j,
% that requires *left* multiplication feature *row* vectors.
Z = Y*W{i};
b = bias{i};

% Apply bias to non-zero entries.
Y = Z + (double(logical(Z)) .* b);

% Threshold negative values.
Y(Y < 0) = 0;

end
% Propagate through layer.
% Note: using graph convention of A(i,j) means connection from i *to* j,
% that requires *left* multiplication feature *row* vectors.
Z = Y*W{i};
b = bias{i};
% Apply bias to non-zero entries.
Y = Z + bsxfun(@(x,y) x .* y,double(logical(Z)),b);
% Threshold negative values.
Y(Y < 0) = 0;
end
endif

return
end
Expand All @@ -31,4 +47,3 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) <2019> Massachusetts Institute of Technology
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%