随机生成x1,x2,然后训练y(x1,x2)=sin(a*pi*x1)cos(b*pi*x2)。
当运行到net = train(net,P,T); 报错:
??? Error using ==> subsindex
Function 'subsindex' is not defined for values of class 'network'.
Error in ==> test at 20
net = train(net,P,T);
求问如何使用train去训练多维input的情况?
程序如下
train=rand(100,2)*2-1;
traindata=[trainx1,trainx2,sin(0.4*pi.*trainx1).*cos(0.8*pi.*trainx2)];
% Construct training signal P and T
P=traindata(:,1:2)';
T=traindata(:,3)'
%Plot training signal
i=find(T>0.5); j=find(T<=0.5);
x=P(1,i); y=P(2,i);
x1=P(1,j); y1=P(2,j);
plot(x,y,'o',x1,y1,'+')
%Push a key to continue
disp('Push a key to continue')
pause
%Define a neural network and train it with the training data
net = newff([-0.5 0.5; -0.5 0.5], [18 1], {'tansig' 'logsig'});
net.trainParam.epochs = 5000;
net = train(net,P,T);
%Generate input data randomly
x2=rand(1,5000)-0.5;
y2=0.8*rand(1,5000)-0.4;
P2=[x2;y2];
%Simulate the trained network
T2 = sim(net,P2);
%Check the generalization ability of the trained network
ii=find(T2>0.5)
plot(x,y,'o',x1,y1,'+',x2(ii),y2(ii),'o')
谢谢。
慕慕森