function learn(a_n, a_k, t_k, lambda)
%  LEARN  Implements standard back propagation.
%  LEARN(A_N, A_K, T_K, LAMBDA), where A_N is the input vector, A_K is the
%  actual output vector, T_K is the desired output vector, and LAMBDA is the
%  decay factor, runs a standard back propagation rule as shown below:
%.
%  d_k  = a_k * (1 - a_k) * (t_k - a_k)
%  d_h  = a_h * (1 - a_h) * (transpose(w_2) x d_k)
%  dw_2 = lambda * eta * d_k x transpose(a_h)
%  dw_1 = lambda * eta * d_h x transpose(a_n)
%  w_2  = w_2 + dw_2
%  w_1  = w_1 + dw_1
%
%  where eta is the learning rate
%  THIS FUNCTION UPDATES GLOBAL VARIABLES.


global A_H DELTA_K DELTA_H W1 W2 DELTA_W1 DELTA_W2 ETA;


DELTA_K = a_k .* (1 - a_k) .* (t_k - a_k);
DELTA_H = A_H .* (1 - A_H) .* (W2' * DELTA_K);
DELTA_W2 = lambda * ETA * (DELTA_K * A_H');
DELTA_W1 = lambda * ETA * (DELTA_H * a_n');
W2 = W2 + DELTA_W2;
W1 = W1 + DELTA_W1;
