function [deltaout, deltahidden] = mlpbackward(hidden, outputs, targets, w2)
% backpropagates the deltas
% deltaout is N x Nout
% deltahidden is N x Nhidden
%

% output deltas
deltaout = outputs.*(1-outputs).*(outputs - targets);

% hidden deltas
deltahidden = hidden.*(1-hidden).*(deltaout*w2(2:end,:)');  % ignore bias connection
