📄 wrescale.m
字号:
function [W1,W2]=wrescale(W1,W2,Uscale,Yscale,NN)
% WRESCALE
% --------
% Rescale weights of a trained network so that the network
% can work on unscaled data.
%
% Calling [W1,W2]=wrescale(W1,W2,Uscale,Yscale,NN) rescales the weights
% for networks with LINEAR OUTPUT UNITS. The function works for
% plain feed-forward networks as well as for input-output models of dynamic
% systems (i.e. NNAR(X), NNARMA(X) and NNOE type models). Notice that when
% the function is used on a pruned network it will reintrouce the biases removed
% during the pruning session.
%
%
% NN is left out for static models
%
% INPUTS:
% W1 - Input-to-hidden of network trained on scaled data
% W2 - Hidden-to-output weights
% Uscale - Matrix containing sample mean and standard deviation for
% each input. For time series an empty matrix, [], is passed.
% Yscale - Matrix containing mean and std's for each output.
% NN - Vector containing lag spaces (see nnarx, nnarmax, nnoe ..)
%
% OUTPUTS:
% W1, W2 - Scaled weight matrices.
%
% NB! See function 'dscale' on how to scale the data before training.
%
%
% Programmed by Magnus Norgaard, IAU/IMM/EI Technical University of Denmark
% LastEditDate: July 19, 1995
[hidden,netinputs] = size(W1);
[inputs,dummy] = size(Uscale);
[outputs,dummy] = size(Yscale);
% ----- Rescale input-to-hidden weights -----
% -- Static networks --
if nargin<5
meanvec = Uscale(:,1);
stdvec = Uscale(:,2);
% -- Dynamic models --
else
if (2+2*inputs) >= netinputs,
error('You have fucked up in the call of function "wrscale"')
end
meanvec = Yscale(1)*ones(NN(1),1);
stdvec = Yscale(2)*ones(NN(1),1);
if length(NN)==2+2*inputs, % NARMAX model
nc = NN(inputs+2);
nab=sum(NN(1:inputs+1));
if nab==netinputs-1, % NARMAX model, linear noise filter
nc = 0;
end
end
for k=1:inputs,
meanvec = [meanvec;Uscale(k,1)*ones(NN(k+1),1)];
stdvec = [stdvec;Uscale(k,2)*ones(NN(k+1),1)];
end
if nc>0, % NARMAX models
meanvec = [meanvec;zeros(nc,1)];
stdvec = [stdvec;Yscale(2)*ones(nc,1)];
end
end
for k=1:netinputs-1,
W1(:,k) = W1(:,k)/stdvec(k);
W1(:,netinputs) = W1(:,netinputs) - W1(:,k)*meanvec(k);
end
% ----- Rescale hidden-to-output weights -----
meanvec = Yscale(:,1);
stdvec = Yscale(:,2);
for k=1:outputs,
W2(k,:) = W2(k,:)*stdvec(k);
W2(k,hidden+1) = W2(k,hidden+1)+meanvec(k);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -