[已解决] 求助MATLAB中net=train(net,p,t); Error using

[复制链接]
taoyingying123 发表于 2015-5-7 20:28:41
本帖最后由 taoyingying123 于 2015-5-7 20:32 编辑

本人初学matlab,想写个小程序,输入向量P为19*23的向量,输出向量t为3*23的向量,想构建一个19*5*3的网络,进行训练和学习,最后进行仿真,套用别人的程序改了下,运行不出来,还求大师指点,感激不尽。最好能直接发个源程序,我的qq邮箱:493170001@qq.com   谢谢大家了!
  1. 这是代码
复制代码

P=0.103,0.1705,0.0998,0.0435,0.0645,0.151,0.117,0.1165,0.1486,0.162,0.1,0.201,0.023,0.121,0.159,0.0982,0.031,0.045,0.146,0.182,0.171,0.0605,0.1589;0.0308,0.21,0.162,0.131,0.208,0.0276,0.2,0.152,0.03,0.112,0.031,0.152,0.101,0.01,0.091,0.0501,0.079,0.193,0.182,0.167,0.1661,0.1796,0.021;0.191,0.0415,0.15,0.121,0.1013,0.162,0.0973,0.0812,0.1819,0.0531,0.0629,0.0106,0.2005,0.1495,0.0927,0.0238,0.0798,0.1618,0.217,0.1512,0.081,0.0513,0.0908;0.1082,0.2072,0.2006,0.0475,0.0256,0.171,0.1912,0.0721,0.051,0.1421,0.0815,0.0415,0.1096,0.1897,0.0316,0.0712,0.0694,0.0105,0.0708,0.1396,0.182,0.1359,0.105;0.181,0.072,0.0608,0.1508,0.1307,0.1908,0.1728,0.0989,0.0692,0.0297,0.0712,0.061,0.0308,0.2078,0.1409,0.0599,0.091,0.1209,0.0208,0.0919,0.1098,0.059,0.1709;0.0612,0.1907,0.1301,0.0211,0.1389,0.1492,0.0397,0.03,0.07,0.0901,0.2107,0.05,0.2,0.161,0.0671,0.1279,0.1099,0.0389,0.1066,0.1088,0.18,0.0311,0.04;0.1489,0.052,0.191,0.1121,0.081,0.1309,0.142,0.0495,0.03,0.1904,0.05,0.18,0.1128,0.1306,0.1902,0.0411,0.1,0.0612,0.02,0.0711,0.12,0.0912,0.1213;0.071,0.1709,0.0511,0.0605,0.1688,0.07,0.02,0.0511,0.0259,0.19,0.1399,0.1198,0.1,0.101,0.2005,0.0201,0.0708,0.0399,0.07,0.12,0.01,0.0327,0.1789;0.09,0.1608,0.18,0.0635,0.1678,0.1399,0.18,0.0199,0.079,0.1769,0.1809,0.2,0.0917,0.01,0.1279,0.0498,0.0512,0.01,0.101,0.1196,0.0719,0.1921,0.1569;0.071,0.1505,0.131,0.0615,0.1179,0.1579,0.1691,0.06,0.129,0.1501,0.004,0.02,0.1795,0.1439,0.031,0.03,0.1197,0.0539,0.1794,0.21,0.14,0.1705,0.19;0.081,0.2015,0.04,0.12,0.0909,0.1,0.1478,0.05,0.2103,0.0519,0.1098,0.02,0.1273,0.021,0.0295,0.1712,0.18,0.181,0.0496,0.1,0.059,0.0201,0.1579;0.2056,0.0188,0.1605,0.1708,0.08,0.012,0.002,0.1805,0.0809,0.0659,0.102,0.101,0.0189,0.1489,0.2008,0.031,0.1419,0.0499,0.0896,0.0198,0.162,0.1505,0.0144;0.105,0.0376,0.0865,0.0519,0.051,0.12,0.167,0.0901,0.161,0.008,0.19,0.0573,0.1108,0.0495,0.0529,0.0699,0.08,0.101,0.1259,0.1008,0.1467,0.0601,0.1809;0.145,0.149,0.1308,0.17,0.1695,0.0609,0.207,0.0409,0.1305,0.0708,0.0099,0.03,0.1205,0.0899,0.1519,0.1891,0.0702,0.12,0.0908,0.041,0.0803,0.1187,0.1133;0.02,0.19,0.069,0.1705,0.1895,0.17,0.1285,0.1382,0.1279,0.0231,0.1201,0.008,0.2028,0.0959,0.1759,0.021,0.1958,0.19,0.102,0.1005,0.12,0.0271,0.0201;0.0955,0.14,0.16,0.0805,0.11,0.085,0.18,0.1275,0.169,0.0351,0.091,0.01,0.13,0.003,0.159,0.1259,0.0708,0.12,0.06,0.005,0.008,0.495,0.127;0.158,0.091,0.129,0.12,0.05,0.139,0.128,0.01,0.02,0.007,0.07,0.1905,0.1208,0.091,0.0355,0.0598,0.0905,0.0415,0.0477,0.0985,0.2,0.051,0.067;0.121,0.085,0.06,0.0613,0.1812,0.0719,0.165,0.018,0.1355,0.0715,0.02,0.058,0.1705,0.198,0.079,0.041,0.118,0.086,0.141,0.005,0.042,0.009,0.1912;0.185,0.1322,0.0315,0.0508,0.1705,0.0502,0.1766,0.0511,0.165,0.0311,0.095,0.1276,0.108,0.06,0.089,0.03,0.0677,0.174,0.1988,0.04,0.037,0.0922,0.1405];T=[0 1 0 1 0 0 0 1 0 0 0 0 1 0 1 1 0 0 1 0 0 1 0;1 0 1 0 0 1 1 0 0 0 1 1 0 1 0 0 1 0 0 1 1 0 0;0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 1];
Ptest=[0.0277,0.2015;0.149,0.1308;0.0216,0.1609;0.0791,0.0591;0.0819,0.0809;0.0498,0.0711;0.119,0.1501;0.1599,0.0122;0.1108,0.1581;0.01,0.0319;0.1268,0.0205;0.1,0.098;0.0405,0.0518;0.0533,0.0718;0.1691,0.205;0.115,0.149;0.139,0.138;0.1654,0.0986;0.0405,0.0815];
Ttest=[0 1;0 0;1 0];
net=newff(minmax(P'),[5,3],{'logsig','purelin'},'traingdm');
% 设置训练参数
net.trainParam.show = 50;
net.trainParam.lr = 0.05;
net.trainParam.mc = 0.9;
net.trainParam.epochs = 500;
net.trainParam.goal = 0.001;
% 调用TRAINGDM算法训练 BP 网络
[net,tr]=train(net,P',T);
% 对BP网络进行仿真
A=sim(net,P');
Warning: NEWFF used in an obsolete way.
> In obs_use at 18
  In newff>create_network at 127
  In newff at 102
          See help for NEWFF to update calls to the new argument list.

Error using traingdm (line 103)
Inputs and targets have different numbers of samples.

Error in network/train (line 106)
[net,tr] = feval(net.trainFcn,net,X,T,Xi,Ai,EW,net.trainParam);





急用!!!!!希望尽快得到指导!谢谢大家!


最佳答案


yinhefeng 发表于 2015-5-10 21:03:35
taoyingying123 发表于 2015-5-10 09:59
非常感谢您的指导和回复,经过这几天在咱们论坛学习我也自己解决了这个程序的问题,就是输入输出数据没弄 ...

输入和输出数据矩阵的每列均为一个样本数据。

15 条回复


taoyingying123 发表于 2015-5-7 20:47:54
补充下 :  我的MATLAB是R2012a版本的  求指点  谢谢大家

yinhefeng 发表于 2015-5-9 19:16:21
taoyingying123 发表于 2015-5-7 20:47
补充下 :  我的MATLAB是R2012a版本的  求指点  谢谢大家

修改后的程序如下:
  1. clear all
  2. clc
  3. close all

  4. P=[0.103,0.1705,0.0998,0.0435,0.0645,0.151,0.117,0.1165,0.1486,0.162,0.1,0.201,0.023,0.121,0.159,0.0982,0.031,0.045,0.146,0.182,0.171,0.0605,0.1589;0.0308,0.21,0.162,0.131,0.208,0.0276,0.2,0.152,0.03,0.112,0.031,0.152,0.101,0.01,0.091,0.0501,0.079,0.193,0.182,0.167,0.1661,0.1796,0.021;0.191,0.0415,0.15,0.121,0.1013,0.162,0.0973,0.0812,0.1819,0.0531,0.0629,0.0106,0.2005,0.1495,0.0927,0.0238,0.0798,0.1618,0.217,0.1512,0.081,0.0513,0.0908;0.1082,0.2072,0.2006,0.0475,0.0256,0.171,0.1912,0.0721,0.051,0.1421,0.0815,0.0415,0.1096,0.1897,0.0316,0.0712,0.0694,0.0105,0.0708,0.1396,0.182,0.1359,0.105;0.181,0.072,0.0608,0.1508,0.1307,0.1908,0.1728,0.0989,0.0692,0.0297,0.0712,0.061,0.0308,0.2078,0.1409,0.0599,0.091,0.1209,0.0208,0.0919,0.1098,0.059,0.1709;0.0612,0.1907,0.1301,0.0211,0.1389,0.1492,0.0397,0.03,0.07,0.0901,0.2107,0.05,0.2,0.161,0.0671,0.1279,0.1099,0.0389,0.1066,0.1088,0.18,0.0311,0.04;0.1489,0.052,0.191,0.1121,0.081,0.1309,0.142,0.0495,0.03,0.1904,0.05,0.18,0.1128,0.1306,0.1902,0.0411,0.1,0.0612,0.02,0.0711,0.12,0.0912,0.1213;0.071,0.1709,0.0511,0.0605,0.1688,0.07,0.02,0.0511,0.0259,0.19,0.1399,0.1198,0.1,0.101,0.2005,0.0201,0.0708,0.0399,0.07,0.12,0.01,0.0327,0.1789;0.09,0.1608,0.18,0.0635,0.1678,0.1399,0.18,0.0199,0.079,0.1769,0.1809,0.2,0.0917,0.01,0.1279,0.0498,0.0512,0.01,0.101,0.1196,0.0719,0.1921,0.1569;0.071,0.1505,0.131,0.0615,0.1179,0.1579,0.1691,0.06,0.129,0.1501,0.004,0.02,0.1795,0.1439,0.031,0.03,0.1197,0.0539,0.1794,0.21,0.14,0.1705,0.19;0.081,0.2015,0.04,0.12,0.0909,0.1,0.1478,0.05,0.2103,0.0519,0.1098,0.02,0.1273,0.021,0.0295,0.1712,0.18,0.181,0.0496,0.1,0.059,0.0201,0.1579;0.2056,0.0188,0.1605,0.1708,0.08,0.012,0.002,0.1805,0.0809,0.0659,0.102,0.101,0.0189,0.1489,0.2008,0.031,0.1419,0.0499,0.0896,0.0198,0.162,0.1505,0.0144;0.105,0.0376,0.0865,0.0519,0.051,0.12,0.167,0.0901,0.161,0.008,0.19,0.0573,0.1108,0.0495,0.0529,0.0699,0.08,0.101,0.1259,0.1008,0.1467,0.0601,0.1809;0.145,0.149,0.1308,0.17,0.1695,0.0609,0.207,0.0409,0.1305,0.0708,0.0099,0.03,0.1205,0.0899,0.1519,0.1891,0.0702,0.12,0.0908,0.041,0.0803,0.1187,0.1133;0.02,0.19,0.069,0.1705,0.1895,0.17,0.1285,0.1382,0.1279,0.0231,0.1201,0.008,0.2028,0.0959,0.1759,0.021,0.1958,0.19,0.102,0.1005,0.12,0.0271,0.0201;0.0955,0.14,0.16,0.0805,0.11,0.085,0.18,0.1275,0.169,0.0351,0.091,0.01,0.13,0.003,0.159,0.1259,0.0708,0.12,0.06,0.005,0.008,0.495,0.127;0.158,0.091,0.129,0.12,0.05,0.139,0.128,0.01,0.02,0.007,0.07,0.1905,0.1208,0.091,0.0355,0.0598,0.0905,0.0415,0.0477,0.0985,0.2,0.051,0.067;0.121,0.085,0.06,0.0613,0.1812,0.0719,0.165,0.018,0.1355,0.0715,0.02,0.058,0.1705,0.198,0.079,0.041,0.118,0.086,0.141,0.005,0.042,0.009,0.1912;0.185,0.1322,0.0315,0.0508,0.1705,0.0502,0.1766,0.0511,0.165,0.0311,0.095,0.1276,0.108,0.06,0.089,0.03,0.0677,0.174,0.1988,0.04,0.037,0.0922,0.1405];
  5. T=[0 1 0 1 0 0 0 1 0 0 0 0 1 0 1 1 0 0 1 0 0 1 0;1 0 1 0 0 1 1 0 0 0 1 1 0 1 0 0 1 0 0 1 1 0 0;0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 1];
  6. Ptest=[0.0277,0.2015;0.149,0.1308;0.0216,0.1609;0.0791,0.0591;0.0819,0.0809;0.0498,0.0711;0.119,0.1501;0.1599,0.0122;0.1108,0.1581;0.01,0.0319;0.1268,0.0205;0.1,0.098;0.0405,0.0518;0.0533,0.0718;0.1691,0.205;0.115,0.149;0.139,0.138;0.1654,0.0986;0.0405,0.0815];
  7. Ttest=[0 1;0 0;1 0];
  8. net=newff(minmax(P),[5,3],{'logsig','purelin'},'traingdm');
  9. % 设置训练参数
  10. net.trainParam.show = 50;
  11. net.trainParam.lr = 0.05;
  12. net.trainParam.mc = 0.9;
  13. net.trainParam.epochs = 500;
  14. net.trainParam.goal = 0.001;
  15. % 调用TRAINGDM算法训练 BP 网络
  16. [net,tr]=train(net,P,T);
  17. % 对BP网络进行仿真
  18. A=sim(net,P);
复制代码

taoyingying123 发表于 2015-5-10 09:59:41
yinhefeng 发表于 2015-5-9 19:16
修改后的程序如下:

非常感谢您的指导和回复,经过这几天在咱们论坛学习我也自己解决了这个程序的问题,就是输入输出数据没弄明白怎么表示,不过还是非常感谢您!谢谢咱们论坛提供的资源!受益匪浅!

taoyingying123 发表于 2015-5-10 10:03:25
yinhefeng 发表于 2015-5-9 19:16
修改后的程序如下:

还想请教下:我不太明白这个网络训练到达一个怎么样的程度才能算好,可以结束,与测试数据的误差分析mse应该在多少才能算是比较好呢?拿捏不准,还请指教!谢谢!

yinhefeng 发表于 2015-5-10 21:03:35
taoyingying123 发表于 2015-5-10 09:59
非常感谢您的指导和回复,经过这几天在咱们论坛学习我也自己解决了这个程序的问题,就是输入输出数据没弄 ...

输入和输出数据矩阵的每列均为一个样本数据。
回复此楼

yinhefeng 发表于 2015-5-10 21:12:54
taoyingying123 发表于 2015-5-10 10:03
还想请教下:我不太明白这个网络训练到达一个怎么样的程度才能算好,可以结束,与测试数据的误差分析mse应 ...

训练的效果不仅要看mse,还需要看验证集和测试集的性能。(新版本的MATLAB会自动把输入的训练数据分为3部分,训练集、验证集和测试集,比例分别为0.7,0.15,0.15)。
看看链接中的文档33页说的几点:
• The final mean-square error is small.
• The test set error and the validation set error have similar
characteristics.
• No significant overfitting has occurred by iteration 17 (where the best
validation performance occurs).
http://yunpan.cn/cj8s2GhVUuJf8 访问密码 66db

yinhefeng 发表于 2015-5-10 21:13:26
本帖最后由 yinhefeng 于 2015-5-10 21:15 编辑
taoyingying123 发表于 2015-5-10 10:03
还想请教下:我不太明白这个网络训练到达一个怎么样的程度才能算好,可以结束,与测试数据的误差分析mse应 ...



yinhefeng 发表于 2015-5-10 21:13:33
本帖最后由 yinhefeng 于 2015-5-10 21:15 编辑
taoyingying123 发表于 2015-5-10 10:03
还想请教下:我不太明白这个网络训练到达一个怎么样的程度才能算好,可以结束,与测试数据的误差分析mse应 ...



taoyingying123 发表于 2015-5-13 16:29:55
非常感激您的回复!我看了您给的链接,感觉那个mse的误差图跟模式识别工具箱那个图很相似,我是不是直接可以用模式识别工具箱作呢?

yinhefeng 发表于 2015-5-14 03:03:50
taoyingying123 发表于 2015-5-13 16:29
非常感激您的回复!我看了您给的链接,感觉那个mse的误差图跟模式识别工具箱那个图很相似,我是不是直接可 ...

应该也可以的,此外使用工具箱后可以生成代码。

taoyingying123 发表于 2015-5-14 10:53:53
非常感谢您!我终于懂一点了!以后还会持续关注的!再次感谢!

小瘦子 发表于 2017-1-7 19:11:07
yinhefeng 发表于 2015-5-10 21:12
训练的效果不仅要看mse,还需要看验证集和测试集的性能。(新版本的MATLAB会自动把输入的训练数据分为3部 ...

请问这个资料还可以再发一份给我吗?251415688@qq.com

轶文Hit 发表于 2017-4-16 16:48:34
taoyingying123 发表于 2015-5-10 09:59
非常感谢您的指导和回复,经过这几天在咱们论坛学习我也自己解决了这个程序的问题,就是输入输出数据没弄 ...

同学 你好 请问Ptest 和Ttest 是干什么用的   谢谢您

轶文Hit 发表于 2017-4-16 16:49:46
yinhefeng 发表于 2015-5-9 19:16
修改后的程序如下:

版主大神 可以帮我该一个BP程序么?
clear all
clc
close all
tic;        %开始计时
p=[0.0052,0.0041,0.0055;0.0029,0.0019,0.0014; 0.0036,0.0028,0.0057; 0.0017,0.0032,0.0016; 0.0066,0.0036,0.0036; 0.0019,0.0013,0.0031;0.0025,0.0058,0.0036; 0.0079,0.0053,0.0104; 0.0050,0.0087,0.0069;0.0108,0.0308,0.0229; 0.0047,0.0042,0.0077;0.0083,0.0159,0.0097;0.0088,0.0059,0.0046];                                                           
t=[00000;01001;01010;01011;01100;01101;01110;10001;10010;10011;10100;10101;10110];                                                                                                                                                                                                                      
%生成BP网络
net=newff(minmax(p),[3,5],{'tansig','logsig'},'trainlm');        
%BP网络训练的参数设置
net.trainParam.epochs=300;
net.trainParam.goal=0.0001;
net.trainParam.lr=0.1;
%开始训练
net=train(net,p,t);
%仿真结果
A=sim(net,p);
toc                            %结束计时

PP12 发表于 2018-1-27 14:49:47
taoyingying123 发表于 2015-5-10 09:59
非常感谢您的指导和回复,经过这几天在咱们论坛学习我也自己解决了这个程序的问题,就是输入输出数据没弄 ...

想问一下你是怎么解决的,我最近也碰到这个问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则

相关帖子
热门教程
站长推荐
快速回复 返回顶部 返回列表