Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
antodima committed May 13, 2021
1 parent b928471 commit e512490
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 23 deletions.
4 changes: 2 additions & 2 deletions LAB3_1/Assignment1/README.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
IDNN MSEs: training error=0.00476, validation error=0.00473, test error=0.00442
RNN MSEs: training error=0.00499, validation error=0.00556, test error=0.00490
IDNN MSEs: training error=0.00478, validation error=0.00484, test error=0.00451
RNN MSEs: training error=0.00257, validation error=0.00280, test error=0.00459
25 changes: 15 additions & 10 deletions LAB3_1/Assignment1/idnn.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
infos = [];
infoFieldnames = [];
valErrors = [];
trErrors = [];

for g=1:size(grid,1)
params = grid(g,:);
Expand Down Expand Up @@ -65,39 +66,43 @@
err = immse(cell2mat(y_train),cell2mat(y_pred));
val_err = immse(cell2mat(y_val),cell2mat(y_val_pred));
valErrors(end+1) = val_err;
trErrors(end+1) = err;

fprintf('#%d/%d: delays=%d, hiddenSize=%d, epochs=%d, lr=%0.3f, lambda=%0.3f, tr.err=%0.5f, val.err=%0.5f \n',g,size(grid,1),delay,hiddenSize,epochs,lr,lambda,err,val_err);
end
[val, idx] = min(valErrors);
[val_err, idx] = min(valErrors);
tr_err = trErrors(idx);
infoCell = infos(:,idx);
info = cell2struct(infoCell, infoFieldnames);
fprintf('min.val.err.=%0.5f, idx=%d, params={delays=%d, hiddenSize=%d, epochs=%d, lr=%0.3f, lambda=%0.3f} \n',val,idx,grid(idx,:));
fprintf('Best params: tr.err=%0.5f, val.err=%0.5f, idx=%d, params={delays=%d, hiddenSize=%d, epochs=%d, lr=%0.3f, lambda=%0.3f} \n',tr_err,val_err,idx,grid(idx,:));
plotperform(info);
else
disp('>> Model assessment...');
% min.val.err.=0.00477, idx=391, params={delays=2, hiddenSize=10, epochs=90, lr=0.100, lambda=0.100}
% Best params: tr.err=0.00478, val.err=0.00484, idx=391, params={delays=2, hiddenSize=10, epochs=90, lr=0.100, lambda=0.100}
net = timedelaynet(0:2,10,'traingdx');
net.performParam.regularization = 0.100;
net.performParam.regularization = 0.1;
net.trainParam.epochs = 90;
net.divideFcn = 'dividetrain';
net.trainParam.lr = 0.1;
net.trainParam.showWindow = false;
[Xs,Xi,Ai,Ts] = preparets(net,X_design,y_design);
[net,info] = train(net,Xs,Ts,'useParallel','yes');
plotperform(info);
%plotperform(info);

ds_pred = net(X_design);
tr_pred = net(X_train);
vl_pred = net(X_val);
ts_pred = net(X_test);

tr_err = immse( cell2mat(y_train), cell2mat(tr_pred) );
vl_err = immse( cell2mat(y_val) , cell2mat(vl_pred) );
ts_err = immse( cell2mat(y_test) , cell2mat(ts_pred) );
ds_err = immse( cell2mat(y_design), cell2mat(ds_pred) );
tr_err = immse( cell2mat(y_train), cell2mat(tr_pred) );
vl_err = immse( cell2mat(y_val) , cell2mat(vl_pred) );
ts_err = immse( cell2mat(y_test) , cell2mat(ts_pred) );

fig = figure;
scatter((1:size(y_train,2)),cell2mat(y_train));
scatter((1:size(y_design,2)),cell2mat(y_design));
hold on;
scatter((1:size(tr_pred,2)),cell2mat(tr_pred));
scatter((1:size(ds_pred,2)),cell2mat(ds_pred));
xlabel('time')
ylabel('target');
title('Training targets and predictions');
Expand Down
Binary file modified LAB3_1/Assignment1/idnn_tr.mat
Binary file not shown.
Binary file modified LAB3_1/Assignment1/images/idnn_learning_curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LAB3_1/Assignment1/images/idnn_test_targets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LAB3_1/Assignment1/images/idnn_training_targets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LAB3_1/Assignment1/images/rnn_learning_curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LAB3_1/Assignment1/images/rnn_test_targets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LAB3_1/Assignment1/images/rnn_training_targets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 11 additions & 6 deletions LAB3_1/Assignment1/rnn.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
infos = [];
infoFieldnames = [];
valErrors = [];
trErrors = [];

for g=1:size(grid,1)
params = grid(g,:);
Expand Down Expand Up @@ -64,17 +65,19 @@
err = immse(cell2mat(y_train),cell2mat(y_pred));
val_err = immse(cell2mat(y_val),cell2mat(y_val_pred));
valErrors(end+1) = val_err;
trErrors(end+1) = err;

fprintf('#%d/%d: hiddenSize=%d, epochs=%d, lr=%0.3f, lambda=%0.3f, tr.err=%0.5f, val.err=%0.5f \n',g,size(grid,1),hiddenSize,epochs,lr,lambda,err,val_err);
end
[val, idx] = min(valErrors);
[val_err, idx] = min(valErrors);
tr_err = trErrors(idx);
infoCell = infos(:,idx);
info = cell2struct(infoCell, infoFieldnames);
fprintf('min.val.err.=%0.5f, idx=%d, params={hiddenSize=%d, epochs=%d, lr=%0.3f, lambda=%0.3f} \n',val,idx,grid(idx,:));
fprintf('Best params: tr.err=%0.5f, val.err=%0.5f, idx=%d, params={hiddenSize=%d, epochs=%d, lr=%0.3f, lambda=%0.3f} \n',tr_err,val_err,idx,grid(idx,:));
plotperform(info);
else
disp('>> Model assessment...');
% min.val.err.=0.00432, idx=42, params={hiddenSize=20, epochs=90, lr=0.100, lambda=0.001}
% Best params: tr.err=0.00257, val.err=0.00280, idx=89, params={hiddenSize=40, epochs=90, lr=0.100, lambda=0.010}
net = layrecnet(1,20,'traingdx');
net.performParam.regularization = 0.001;
net.trainParam.epochs = 90;
Expand All @@ -83,20 +86,22 @@
net.trainParam.showWindow = false;
[Xs,Xi,Ai,Ts] = preparets(net,X_design,y_design);
[net,info] = train(net,Xs,Ts,'useParallel','yes');
plotperform(info);
%plotperform(info);

ds_pred = net(X_design);
tr_pred = net(X_train);
vl_pred = net(X_val);
ts_pred = net(X_test);

ds_err = immse( cell2mat(y_design), cell2mat(ds_pred) );
tr_err = immse( cell2mat(y_train), cell2mat(tr_pred) );
vl_err = immse( cell2mat(y_val) , cell2mat(vl_pred) );
ts_err = immse( cell2mat(y_test) , cell2mat(ts_pred) );

fig = figure;
scatter((1:size(y_train,2)),cell2mat(y_train));
scatter((1:size(y_design,2)),cell2mat(y_design));
hold on;
scatter((1:size(tr_pred,2)),cell2mat(tr_pred));
scatter((1:size(ds_pred,2)),cell2mat(ds_pred));
xlabel('time')
ylabel('target');
title('Training targets and predictions');
Expand Down
Binary file modified LAB3_1/Assignment1/rnn_tr.mat
Binary file not shown.
6 changes: 3 additions & 3 deletions LAB3_2/Assignment1/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Echo State Network best hyper-parameters:
- Number of guesses = 10

Mean Squared Errors:
- Training MSE = 0.00106
- Validation MSE = 0.00111
- Test MSE = 0.00097
- Training MSE = 0.00092
- Validation MSE = 0.00242
- Test MSE = 0.00118
Binary file modified LAB3_2/Assignment1/Win.mat
Binary file not shown.
Binary file modified LAB3_2/Assignment1/Wout.mat
Binary file not shown.
Binary file modified LAB3_2/Assignment1/Wr.mat
Binary file not shown.
5 changes: 3 additions & 2 deletions LAB3_2/Assignment1/esn.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
D = y_design(:,Nh+1:end);
% train the readout
V = D*H'*inv(H*H'+lambda*eye(Nh+1)); % solve the linear system (Nh+1 for the bias)
Y = V * H;

% compute training error
H_tr = [];
Expand Down Expand Up @@ -175,9 +176,9 @@
fprintf('tr_err=%0.5f, vl_err=%0.5f, ts_err=%0.5f \n',tr_err,vl_err,ts_err);

fig = figure;
scatter((1:size(y_train,2)),y_train);
scatter((1:size(y_design(:,Nh+1:end),2)),y_design(:,Nh+1:end));
hold on;
scatter((1:size(Y_tr,2)),Y_tr);
scatter((1:size(Y,2)),Y);
xlabel('time')
ylabel('target');
title('Training targets and predictions');
Expand Down
Binary file modified LAB3_2/Assignment1/images/esn_test_targets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LAB3_2/Assignment1/images/esn_training_targets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e512490

Please sign in to comment.