如果经过训练,出现隐含层到输出层无连接,说明输入的数据和输出的数据之间无法进行求解,要更改输入和输出值。
例如:
1 2 3 4 5 6 7 8 | a=rand(1,10); train_x=[a;a+10;a+20]; for i = 1 : size(train_x,1) train_y(i)=sum(train_x(i,:).^2); end % QNet_eval = fitnet([40,40]); x = train_x'; y = train_y; |
总代码:
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 | rng(0) a=rand(1,10); train_x=[a;a+10;a+20]; for i = 1 : size(train_x,1) train_y(i)=sum(train_x(i,:).^2); end % QNet_eval = fitnet([40,40]); x = train_x'; y = train_y; % 一个隐藏层,神经元数为5 hiddenLayerSize = [40,40]; % 训练函数为 trainlm trainFcn = 'trainlm'; % 初始化网络 net = fitnet(hiddenLayerSize,trainFcn); % 设置比例 % net.divideParam.trainRatio = 70/100; % net.divideParam.valRatio = 15/100; % net.divideParam.testRatio = 15/100; % 训练网络 [net,tr] = train(net,x,y); % 计算所有训练样本预测值 yp = sim(net,x); % 计算总体均方误差 performance = perform(net,y,yp); % 查看网络结构 view(net) |
原问题:
最近,在学习神经网络计算,应用到fitnet函数,在调用fitnet函数拟合神经网络时候,通过view查看神经网络结构,发现从隐含层到输出层少了连接,想了解下这种情况是什么原因,应该怎么修改?

正常的函数拟合神经网络,应该是从input到output全过程连接的,比如这样:

代码如下:
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 | load S1.mat %S1里有sample数据,数据格式 80*25,取前11列数据 P_len = 10; % 转置 % x = X'; y = Y'; x = sample(:, 1:P_len)'; y = sample(:, P_len+1)'; % 一个隐藏层,神经元数为5 hiddenLayerSize = 5; % 训练函数为 trainlm trainFcn = 'trainlm'; % 初始化网络 net = fitnet(hiddenLayerSize,trainFcn); % 设置比例 net.divideParam.trainRatio = 70/100; net.divideParam.valRatio = 15/100; net.divideParam.testRatio = 15/100; % 训练网络 [net,tr] = train(net,x,y); % 计算所有训练样本预测值 yp = sim(net,x); % 计算总体均方误差 performance = perform(net,y,yp); % 查看网络结构 view(net) |
参考资料:
https://blog.csdn.net/qq_43575267/article/details/95337353?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase