How to save neural network

7 views (last 30 days)
Parth Moradiya
Parth Moradiya on 14 Nov 2012
I have used neural network to the datasets and now if i trained network one time and now i want to apply this network to different datasets then how i can apply? I want to do this because i want to compare how efficient the transferability? I am eager to find solution.

Accepted Answer

Greg Heath
Greg Heath on 14 Nov 2012
Edited: Greg Heath on 7 Apr 2013
clear all, close all, clc;
[x,t] = simplefit_dataset;
[I N ] = size(x)
[O N ] = size(t)
xtrn = x(1:2:N);
ttrn = t(1:2:N);
MSEtrn00 = var(ttrn',1) % Reference MSEtrn
xval = []; % No val data for Early Stopping
tval = [];
xtst = x(2:2:N); % For post training testing
ttst = t(2:2:N);
MSEtst00 = var(ttst',1) % Reference MSEtst
H = 4 % Minimized by trial & error
net = fitnet(H);
net.divideFcn = ''; % No automatic data division
net.trainParam.goal = 0.01*MSEtrn00; % Want training R^2 >= 0.99
[net tr Ytrn Etrn] = train(net,xtrn,ttrn);
ytrn = net(xtrn);
etrn = ttrn-ytrn;
MSEtrn =mse(etrn)
check1 = max(abs(ytrn - Ytrn))
check2 = max(abs(etrn - Etrn))
check3 = max(abs(MSEtrn - tr.perf(end)))
NMSEtrn = MSEtrn/MSEtrn00 % Normalized
R2trn = 1-NMSEtrn % R^2
% Save for use with other data
net01 = net;
save net01 % Save
whos net net01 % Both in workspace
pause(5)
clear net net01 % Cleared from workspace
whos % Proof
%Retrieve and use
load net01
ytst = net01(xtst);
MSEtst = mse(ttst-ytst)
R2tst = 1-MSEtst/MSEtst00
Hope this helps
Thank you for formally accepting my answer
Greg
  3 Comments
Greg Heath
Greg Heath on 7 Apr 2013
Close. I had defined a similar function which wasn't quite as general: max(abs(x)) instead of max(abs(x(:))

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!