-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnn_paper.m
80 lines (65 loc) · 2.09 KB
/
nn_paper.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
%% prepare data sets
X = data1(:,1);
Y = data1(:,2);
% 2 link train data
% x = {X(:)';Y(:)'};
% t = [data1(:,3)'; data2(:,3)'];
% 3 link train data
x = {X(:)'; Y(:)';};
t = [data1(:,3)'; data2(:,3)'; data3(:,3)'];
%%
% Choose a Training Function
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation
% Create a Fitting Network
hiddenLayerSize = [6 3];
net = fitnet(hiddenLayerSize,trainFcn);
net.numInputs = 2;
net.InputConnect(1,1) = 1;
net.InputConnect(1,2) = 1;
% manually set the train/val/test points
net.divideFcn = 'divideind';
net.divideParam.trainInd = train_points;
net.divideParam.valInd = val_points;
net.divideParam.testInd = test_points;
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean Squared Error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};
%configure
net = configure(net,x,t);
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% Recalculate Training, Validation and Test Performance
trainTargets = t .* tr.trainMask{1};
valTargets = t .* tr.valMask{1};
testTargets = t .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)
% Deployment
% Change the (false) values to (true) to enable the following code blocks.
% See the help for each generation function for more information.
if (false)
% Generate MATLAB function for neural network for application
% deployment in MATLAB scripts or with MATLAB Compiler and Builder
% tools, or simply to examine the calculations your trained neural
% network performs.
genFunction(net,'MLP_2layers');
% y = MLP_3joints(x);
end