clear all; nX = 5; % number of inputs nH = 5; % number of hidden units nY = 3; % number of outputs nD = 100; % number of data points Trn = 4; % transfer function type for all units N = nX+nH+nY; % compute total number of units Con = tril(ones(N)); % make fully-connected feedforward network Con = Con - eye(N); X = randn(nX, nD); % generate random data and weights Y = randn(nX, nD); W0 = randn(N) .* Con; [err, grad, out] = backprop( X, Y, W0, Con, Trn); Y = out; % set desired outputs to actual outputs W = randn(N).*Con; % choose different random weights for k=1:500, % gradient descent with fixed learning rate [err(k), grad] = backprop( X, Y, W, Con, Trn); W = W - 0.001*grad; end figure(1); % plot learning curve clf; subplot(1,2,1); plot(err); xlabel('Iteration'); ylabel('Error'); subplot(1,2,2); % compare learned and correct weights plot(W0(:), W(:), '.'); xlabel('Correct weight'); ylabel('Learned weight');