diff --git a/LAB3_1/Assignment1/README.txt b/LAB3_1/Assignment1/README.txt index 9ecc34b..33c5a40 100644 --- a/LAB3_1/Assignment1/README.txt +++ b/LAB3_1/Assignment1/README.txt @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/LAB3_1/Assignment1/idnn.m b/LAB3_1/Assignment1/idnn.m index f148e26..9253272 100644 --- a/LAB3_1/Assignment1/idnn.m +++ b/LAB3_1/Assignment1/idnn.m @@ -37,6 +37,7 @@ infos = []; infoFieldnames = []; valErrors = []; + trErrors = []; for g=1:size(grid,1) params = grid(g,:); @@ -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'); diff --git a/LAB3_1/Assignment1/idnn_tr.mat b/LAB3_1/Assignment1/idnn_tr.mat index 36bb7e9..feba92e 100644 Binary files a/LAB3_1/Assignment1/idnn_tr.mat and b/LAB3_1/Assignment1/idnn_tr.mat differ diff --git a/LAB3_1/Assignment1/images/idnn_learning_curve.png b/LAB3_1/Assignment1/images/idnn_learning_curve.png index 8deb9d4..8c2a9c7 100644 Binary files a/LAB3_1/Assignment1/images/idnn_learning_curve.png and b/LAB3_1/Assignment1/images/idnn_learning_curve.png differ diff --git a/LAB3_1/Assignment1/images/idnn_test_targets.png b/LAB3_1/Assignment1/images/idnn_test_targets.png index 5861189..efc4733 100644 Binary files a/LAB3_1/Assignment1/images/idnn_test_targets.png and b/LAB3_1/Assignment1/images/idnn_test_targets.png differ diff --git a/LAB3_1/Assignment1/images/idnn_training_targets.png b/LAB3_1/Assignment1/images/idnn_training_targets.png index b5e725f..856c0e1 100644 Binary files a/LAB3_1/Assignment1/images/idnn_training_targets.png and b/LAB3_1/Assignment1/images/idnn_training_targets.png differ diff --git a/LAB3_1/Assignment1/images/rnn_learning_curve.png b/LAB3_1/Assignment1/images/rnn_learning_curve.png index 62cacfd..775bd75 100644 Binary files a/LAB3_1/Assignment1/images/rnn_learning_curve.png and b/LAB3_1/Assignment1/images/rnn_learning_curve.png differ diff --git a/LAB3_1/Assignment1/images/rnn_test_targets.png b/LAB3_1/Assignment1/images/rnn_test_targets.png index 36c3892..1bd2476 100644 Binary files a/LAB3_1/Assignment1/images/rnn_test_targets.png and b/LAB3_1/Assignment1/images/rnn_test_targets.png differ diff --git a/LAB3_1/Assignment1/images/rnn_training_targets.png b/LAB3_1/Assignment1/images/rnn_training_targets.png index a4aedee..6452b8e 100644 Binary files a/LAB3_1/Assignment1/images/rnn_training_targets.png and b/LAB3_1/Assignment1/images/rnn_training_targets.png differ diff --git a/LAB3_1/Assignment1/rnn.m b/LAB3_1/Assignment1/rnn.m index 17f79e2..4edae24 100644 --- a/LAB3_1/Assignment1/rnn.m +++ b/LAB3_1/Assignment1/rnn.m @@ -37,6 +37,7 @@ infos = []; infoFieldnames = []; valErrors = []; + trErrors = []; for g=1:size(grid,1) params = grid(g,:); @@ -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; @@ -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'); diff --git a/LAB3_1/Assignment1/rnn_tr.mat b/LAB3_1/Assignment1/rnn_tr.mat index 94ad2d3..a41ce5c 100644 Binary files a/LAB3_1/Assignment1/rnn_tr.mat and b/LAB3_1/Assignment1/rnn_tr.mat differ diff --git a/LAB3_2/Assignment1/README.txt b/LAB3_2/Assignment1/README.txt index 7bb5096..7e9c870 100644 --- a/LAB3_2/Assignment1/README.txt +++ b/LAB3_2/Assignment1/README.txt @@ -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 diff --git a/LAB3_2/Assignment1/Win.mat b/LAB3_2/Assignment1/Win.mat index 8c27412..3985ab9 100644 Binary files a/LAB3_2/Assignment1/Win.mat and b/LAB3_2/Assignment1/Win.mat differ diff --git a/LAB3_2/Assignment1/Wout.mat b/LAB3_2/Assignment1/Wout.mat index e82f87d..01918aa 100644 Binary files a/LAB3_2/Assignment1/Wout.mat and b/LAB3_2/Assignment1/Wout.mat differ diff --git a/LAB3_2/Assignment1/Wr.mat b/LAB3_2/Assignment1/Wr.mat index e0667e1..fa6adc7 100644 Binary files a/LAB3_2/Assignment1/Wr.mat and b/LAB3_2/Assignment1/Wr.mat differ diff --git a/LAB3_2/Assignment1/esn.m b/LAB3_2/Assignment1/esn.m index 0ae65ff..5bc86d1 100644 --- a/LAB3_2/Assignment1/esn.m +++ b/LAB3_2/Assignment1/esn.m @@ -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 = []; @@ -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'); diff --git a/LAB3_2/Assignment1/images/esn_test_targets.png b/LAB3_2/Assignment1/images/esn_test_targets.png index 0bec809..8073ac9 100644 Binary files a/LAB3_2/Assignment1/images/esn_test_targets.png and b/LAB3_2/Assignment1/images/esn_test_targets.png differ diff --git a/LAB3_2/Assignment1/images/esn_training_targets.png b/LAB3_2/Assignment1/images/esn_training_targets.png index 33c27af..1091409 100644 Binary files a/LAB3_2/Assignment1/images/esn_training_targets.png and b/LAB3_2/Assignment1/images/esn_training_targets.png differ