資源簡介
回聲狀態網絡(ESN)以及確定性跳躍循環狀態網絡(CRJ)的實現

代碼片段和文件信息
%?A?minimalistic?Echo?State?Networks?demo?with?Mackey-Glass?(delay?17)?data?
%?in?“plain“?Matlab.
%?by?Mantas?Lukosevicius?2012
%?http://minds.jacobs-university.de/mantas
%?load?the?data
trainLen?=?3000;
testLen?=?1000;
initLen?=?100;
data?=?load(‘MackeyGlass-t17.txt‘);
load(‘signv.mat‘);
%?plot?some?of?it
%?figure(10);
%?plot(data(1:1000));
%?title(‘A?sample?of?data‘);
%?generate?the?ESN?reservoir
inSize?=?1;?outSize?=?1;
resSize?=?500;
a?=?0.3;?%?leaking?rate
signal?=?y(1:5001:2);?%signal?of?W_in
%rand(?‘seed‘?42?);
Win?=?(zeros(resSize1+inSize)+0.5)?.*?signal;?%r=0.5
W?=?eye(resSize)?*?0.8;
W?=?circshift(W[12]);?%?generate?circle
W?=?reshape(W1resSize*resSize);
step?=?10;
for?i=1:resSize
????if?mod(i?step)?==?1
????????W(i)?=?0.7;
????end
end
W?=?reshape(WresSizeresSize)
%?Option?1?-?direct?scaling?(quick&dirty?reservoir-specific):
%?W?=?W?.*?0.13;
%?Option?2?-?normalizing?and?setting?spectral?radius?(correct?slower):
disp?‘Computing?spectral?radius...‘;
opt.disp?=?0;
rhoW?=?abs(eigs(W1‘LM‘opt));
disp?‘done.‘
W?=?W?.*?(?1.25?/rhoW);
%?allocated?memory?for?the?design?(collected?states)?matrix
X?=?zeros(1+inSize+resSizetrainLen-initLen);
%?set?the?corresponding?target?matrix?directly
Yt?=?data(initLen+2:trainLen+1)‘;
%?run?the?reservoir?with?the?data?and?collect?X
x?=?zeros(resSize1);
for?t?=?1:trainLen
u?=?data(t);
x?=?(1-a)*x?+?a*tanh(?Win*[1;u]?+?W*x?);
if?t?>?initLen
X(:t-initLen)?=?[1;u;x];
end
end
%?train?the?output
reg?=?1e-8;??%?regularization?coefficient
X_T?=?X‘;
%?Wout?=?Yt*X_T?*?inv(X*X_T?+?reg*eye(1+inSize+resSize));
Wout?=?Yt*X_T?/?(X*X_T?+?reg*eye(1+inSize+resSize));
%?Wout?=?Yt*pinv(X);
%?run?the?trained?ESN?in?a?generative?mode.?no?need?to?initialize?here?
%?because?x?is?initialized?with?training?data?and?we?continue?from?there.
Y?=?zeros(outSizetestLen);
u?=?data(trainLen+1);
for?t?=?1:testLen?
x?=?(1-a)*x?+?a*tanh(?Win*[1;u]?+?W*x?);
y?=?Wout*[1;u;x];
Y(:t)?=?y;
%?generative?mode:
u?=?y;
%?this?would?be?a?predictive?mode:
u?=?data(trainLen+t+1);
end
errorLen?=?1000;
mse?=?sum((data(trainLen+2:trainLen+errorLen+1)‘-Y(11:errorLen)).^2)./errorLen;
disp(?[‘MSE?=?‘?num2str(?mse?)]?);
%?plot?some?signals
figure(1);
plot(?data(trainLen+2:trainLen+testLen+1)?‘color‘?[00.750]?);
hold?on;
plot(?Y‘?‘b‘?);
hold?off;
axis?tight;
title(‘Target?and?generated?signals?y(n)?starting?at?n=0‘);
legend(‘Target?signal‘?‘Free-running?predicted?signal‘);
figure(2);
plot(?X(1:201:200)‘?);
title(‘Some?reservoir?activations?x(n)‘);
figure(3);
bar(?Wout‘?)
title(‘Output?weights?W^{out}‘);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2686??2018-05-19?15:27??minimalCRJ.m
?????文件????????2420??2018-05-19?15:00??minimalESN.m
?????文件????????2574??2015-12-10?00:33??signv.mat
?????文件??????265429??2016-11-21?18:13??MackeyGlass-t17.txt
評論
共有 條評論