Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

P=0.5:0.

01:3;
T= sin(P.^2-15*P+3)-sin(P).^2

T = 1×251
0.6651 0.7101 0.7365 0.7435 0.7311 0.6993 0.6487 0.5802

T1 = con2seq(T(1:end - 20));
P1 = con2seq(P(1:end - 20));
net = timedelaynet(1:5,8);
display(net);

net =

Neural Network

name: 'Time Delay Neural Network'


userdata: (your custom info)

dimensions:

numInputs: 1
numLayers: 2
numOutputs: 1
numInputDelays: 5
numLayerDelays: 0
numFeedbackDelays: 0
numWeightElements: 8
sampleTime: 1

connections:

biasConnect: [1; 1]
inputConnect: [1; 0]
layerConnect: [0 0; 1 0]
outputConnect: [0 1]

subobjects:

input: Equivalent to inputs{1}


output: Equivalent to outputs{2}

inputs: {1x1 cell array of 1 input}


layers: {2x1 cell array of 2 layers}
outputs: {1x2 cell array of 1 output}
biases: {2x1 cell array of 2 biases}
inputWeights: {2x1 cell array of 1 weight}
layerWeights: {2x2 cell array of 1 weight}

functions:

adaptFcn: 'adaptwb'
adaptParam: (none)
derivFcn: 'defaultderiv'
divideFcn: 'dividerand'
divideParam: .trainRatio, .valRatio, .testRatio
divideMode: 'time'
initFcn: 'initlay'
performFcn: 'mse'
performParam: .regularization, .normalization
plotFcns: {'plotperform', 'plottrainstate', 'ploterrhist',
'plotregression', 'plotresponse', 'ploterrcorr',
'plotinerrcorr'}

1
plotParams: {1x7 cell array of 7 params}
trainFcn: 'trainlm'
trainParam: .showWindow, .showCommandLine, .show, .epochs,
.time, .goal, .min_grad, .max_fail, .mu, .mu_dec,
.mu_inc, .mu_max

weight and bias values:

IW: {2x1 cell} containing 1 input weight matrix


LW: {2x2 cell} containing 1 layer weight matrix
b: {2x1 cell} containing 2 bias vectors

methods:

adapt: Learn while in continuous use


configure: Configure inputs & outputs
gensim: Generate Simulink model
init: Initialize weights & biases
perform: Calculate performance
sim: Evaluate network outputs given inputs
train: Train network with examples
view: View diagram
unconfigure: Unconfigure inputs & outputs

[Ps,Pi,Ai,Ts] = preparets(net,P1,T1);
net.trainParam.epochs = 600;
net.trainParam.goal = 1e-8;
net = train(net,Ps,Ts,Pi,Ai);
Y = net(P1,Pi,Ai);
W = net.IW{1}

W = 8×5
-1.7718 -0.9489 0.0416 -0.9491 -2.5935
0.8947 -0.8596 -1.3233 -1.3630 -0.1580
0.3864 1.1810 0.3548 -0.9780 1.2729
-1.8842 -1.1242 -0.2500 -0.5649 -1.9348
-0.4053 1.6520 -0.0232 1.5893 1.2604
0.3339 -1.4759 -1.6659 -1.9416 -0.1994
0.8096 1.0620 0.7720 0.5709 0.1025
-1.5457 -1.2563 -1.3843 0.4237 -0.1965

LW = net.LW{2,1}

LW = 1×8
1.3312 -111.7705 -145.5059 1.5468 13.2824 -3.3976 78.0522 54.4521

b1 = net.b{1}

b1 = 8×1
5.9941
-2.3759
0.9202
2.4549
-0.5646
3.4082
1.0605
-3.5754

b2 = net.b{2}

2
b2 = -4.5630

error = cell2mat(Y)-cell2mat(T1);
mse_error = sqrt(mse(error))

mse_error = 1.0963

plot(cell2mat(P1),cell2mat(T1),cell2mat(P1),cell2mat(Y)),grid;
legend('reference','output');
plot(cell2mat(P1),error),grid;
legend('error');
P2 = con2seq(P(end-19:end));
T2 = con2seq(T(end-19:end));
Y2 = net(P2,P1(end-4:end));
error2 = cell2mat(Y2)-cell2mat(T2);
mse_error2 = sqrt(mse(error2));
plot(cell2mat(P2),cell2mat(T2),cell2mat(P2),cell2mat(Y2)),grid;
legend('reference','output');
plot(cell2mat(P2),error2),grid;
legend('error');

You might also like