分类:
2008-04-23 12:23:55
随机初始化权值矩阵,继续编写学习过程:
Wh = randn(12,3)/3;
Wy = randn(2,12)/12;
C = 2000; % maximum number of training epochs
J = zeros(2,C); % Initialisation of the error function
eta = [0.003 0.1]; % Training gains
for c = 1:C
H = ones(12,N)./(1+exp(-Wh*X)); % Hidden signals (L-1 by N)
Hp = H.*(1-H); % Derivatives of hidden signal
Y = tanh(Wy*H); % Output signals (m by N)
Yp = 1 - Y.^2; % Derivatives of output signals
Ey = D - Y; % The output errors (m by K)
JJ = (sum((Ey.*Ey)'))'; % The total error after one epoch
% the performance function m by 1
delY = Ey.*Yp; % Output delta signal (m by K)
dWy = delY*H'; % Update of the output matrix
% dWy is L by m
Eh = Wy(:,1:12)'*delY % The back-propagated hidden error
% Eh is L-1 by N
delH = Eh.*Hp ; % Hidden delta signals (L-1 by N)
dWh = delH*X'; % Update of the hidden matrix
% dWh is L-1 by p
Wy = Wy+0.003*dWy; Wh = Wh+0.1*dWh;
D1(:)=Y(1,:)'; D2(:)=Y(2,:)';
surfc([X1-2 X1+2], [X2 X2], [D1 D2])
J(:,c) = JJ ;
End