Why is the size of my "narx_net_closed.IW{1}" different from the size of my "mrac_net.LW{3,2}" ? I am refering to Reference Model Controller with MATLAB Script
1 view (last 30 days)
Show older comments
% [u,y] = [ouputdata,inputdata];
a=outputdata' %get from the outputdata.mat file attachment
[r,c]=size(a)
u={}
for w = 1:c
u{w}=[a(1,w);a(2,w);a(3,w)]
end
b=inputdata'
[r1,c1]=size(b)
y={}
for x = 1:c1
y{x}=[b(1,x);b(2,x);b(3,x);b(4,x);b(5,x);b(6,x);b(7,x);b(8,x);b(9,x);b(10,x);b(11,x);b(12,x)]
end
% [X,T] = simpleseries_dataset;
% [u,y] = robotarm_dataset;
% u=[1,2,3];
% y=[4,5,6];
d1 = [1:2];
d2 = [1:2];
S1 = 5;
narx_net = narxnet(d1,d2,S1);
narx_net.divideFcn = '';
narx_net.inputs{1}.processFcns = {};
narx_net.inputs{2}.processFcns = {};
narx_net.outputs{2}.processFcns = {};
narx_net.trainParam.min_grad = 1e-10;
[p,Pi,Ai,t] = preparets(narx_net,u,{},y);
narx_net = train(narx_net,p,t,Pi);
narx_net_closed = closeloop(narx_net);
view(narx_net_closed)
mrac_net = feedforwardnet([S1 1 S1]);
mrac_net.layerConnect = [0 1 0 1;1 0 0 0;0 1 0 1;0 0 1 0];
mrac_net.outputs{4}.feedbackMode = 'closed';
mrac_net.layers{2}.transferFcn = 'purelin';
mrac_net.layerWeights{3,4}.delays = 1:2;
mrac_net.layerWeights{3,2}.delays = 1:2;
mrac_net.layerWeights{3,2}.learn = 0;
mrac_net.layerWeights{3,4}.learn = 0;
mrac_net.layerWeights{4,3}.learn = 0;
mrac_net.biases{3}.learn = 0;
mrac_net.biases{4}.learn = 0;
mrac_net.divideFcn = '';
mrac_net.inputs{1}.processFcns = {};
mrac_net.outputs{4}.processFcns = {};
mrac_net.name = 'Model Reference Adaptive Control Network';
mrac_net.layerWeights{1,2}.delays = 1:2;
mrac_net.layerWeights{1,4}.delays = 1:2;
mrac_net.inputWeights{1}.delays = 1:2;
% [refin,refout] = refmodel_dataset;
p=error'
[r3,c3]=size(p)
refin={}
for k = 1:c2
refin{k}=[p(1,k);p(2,k);p(3,k);p(4,k);p(5,k);p(6,k);p(7,k);p(8,k);p(9,k);p(10,k);p(11,k);p(12,k)]
end
f=modelref'
[r2,c2]=size(f)
refout={}
for m = 1:c2
refout{m}=[f(1,m);f(2,m);f(3,m);f(4,m);f(5,m);f(6,m);f(7,m);f(8,m);f(9,m);f(10,m);f(11,m);f(12,m)]
end
ind = 1:length(refin);
plot(ind,cell2mat(refin),ind,cell2mat(refout))
mrac_net = configure(mrac_net,refin,refout);
mrac_net.LW{3,2} = narx_net_closed.IW{1}; %cause of the problem and why i am asking
mrac_net.LW{3,4} = narx_net_closed.LW{1,2};
mrac_net.b{3} = narx_net_closed.b{1};
mrac_net.LW{4,3} = narx_net_closed.LW{2,1};
mrac_net.b{4} = narx_net_closed.b{2};
0 Comments
Answers (1)
Neha
on 4 Sep 2023
Hi Andrew,
I understand that you are facing an error as the size of input weights for the closed NARX network differs from the size of the layer weights pertaining to the MRAC network.
The size of narx_net_closed.IW{1} is 5x6 and the size of mrac_net.LW{3,2} is 5x2.
You can refer to the following documentation link on how the sizes of the weights are calculated:
Since the number of columns in the layer weights of MRAC is essentially the delays associated with layerWeights{3,2}, you can change the number of delays in line 37 from 2 to 6 to ensure that it is equal to the number of columns in narx_net_closed.IW{1}.
mrac_net.layerWeights{3,2}.delays = 1:6;
Hope this helps!
0 Comments
See Also
Categories
Find more on Sequence and Numeric Feature Data Workflows 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!