24小时热门版块排行榜    

查看: 466  |  回复: 0

haomeng12

新虫 (小有名气)

[求助] 遗传算法BP预测中调试程序的问题

求助各位高手,下面程序中,数据不太清楚,能否有人告知'data.txt'中的数据几行几列?我自己输上了45行14列,程序运行后,老是出现“Index exceeds matrix dimensions”
程序如下:
clear all
close all
p=textread('data.txt');
p1=p';
t=p1;
[pn,minp,maxp,tn,mint,maxt] = premnmx(p1,t);
p_train=[pn(1,:);pn(2,:);pn(3,:);pn(4,:);pn(5,:);pn(6,:);pn(7,:);pn(8,:);pn(9,:);pn(10,:);pn(11,:);pn(12,:);pn(13,:);...
    pn(14,:);pn(15,:);pn(16,:);pn(17,:);pn(18,:);pn(19,:);pn(20,:);pn(21,:);pn(22,:);pn(23,:);pn(24,:);pn(25,:);pn(26,:);pn(27,:);...
    pn(28,:);pn(29,:);pn(30,:);pn(31,:);pn(32,:);pn(33,:);pn(34,:);pn(35,:);pn(36,:);pn(37,:);pn(38,:);pn(39,:)]'
t_train=[pn(2,:);pn(3,:);pn(4,:);pn(5,:);pn(6,:);pn(7,:);pn(8,:);pn(9,:);pn(10,:);pn(11,:);pn(12,:);pn(13,:);pn(14,:);pn(15,:);pn(16,:);...
    pn(17,:);pn(18,:);pn(19,:);pn(20,:);pn(21,:);pn(22,:);pn(23,:);pn(24,:);pn(25,:);pn(26,:);pn(27,:);pn(28,:);pn(29,:);pn(30,:);...
    pn(31,:);pn(32,:);pn(33,:);pn(34,:);pn(35,:);pn(36,:);pn(37,:);pn(38,:);pn(39,:);;pn(40,:)]';
save p_train
save t_train
threshold=minmax(p_train);
%创建网络
net=newff(threshold,[12,25,12],{'tansig','tansig','purelin'},'trainlm');
%下面使用遗传算法对网络进行优化
P=p_train;
T=t_train;
R=size(P,1);
S2=size(T,1);
S1=25;%隐含层节点数
S=R*S1+S1*S2+S1+S2;%遗传算法编码长度
aa=ones(S,1)*[-1,1];
popu=50;%种群规模
initPpp=initializega(popu,aa,'gabpEval');%初始化种群
gen=100;%遗传代数
%下面调用gaot工具箱,其中目标函数定义为gabpEval
[x,endPop,bPop,trace]=ga(aa,'gabpEval',[],initPpp,[1e-6 1 1],'maxGenTerm',gen,...
   'normGeomSelect',[0.09],['arithXover'],[2],'nonUnifMutation',[2 gen 3]);
%绘收敛曲线图
figure(1)
plot(trace(:,1),1./trace(:,3),'r-');
hold on
plot(trace(:,1),1./trace(:,2),'b-');
xlabel('Generation');
ylabel('Sum-Squared Error');
figure(2)
plot(trace(:,1),trace(:,3),'r-');
hold on
plot(trace(:,1),trace(:,2),'b-');
xlabel('Generation');
ylabel('Fittness');
%下面将初步得到的权值矩阵赋给尚未开始训练的BP网络
[W1,B1,W2,B2,P,T,A1,A2,SE,val]=gadecod(x);
net.LW{2,1}=W1;
net.LW{3,2}=W2;
net.b{2,1}=B1;
net.b{3,1}=B2;
XX=P;
YY=T;
%设置训练参数
net.trainParam.show=10;
net.trainParam.lr=0.05;
net.trainParam.epochs=7000;
net.trainParam.goal=0.01;
%训练网络
net=train(net,p_train,t_train);
p_test=[pn(40,:)]';   
T=sim(net,p_test);  
a = postmnmx(T',mint(41,1),maxt(41,1));
number=round(a);
error=p1(41,:)-number;
time=[1 2 3 4 5 6 7 8 9 10 11 12];
plot(time,number,'ro--');
hold on
plot(time,p1(41,:),'gd-')
hold on
plot(time,error)
legend('red is yuce','green is actual','blue is error');
title('time(month)')
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

相关版块跳转 我要订阅楼主 haomeng12 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 投票:  有多少人是今天查系统知道结果的? +17 爱看书的可乐 2026-08-26 19/950 2026-08-31 11:51 by xiangy672
[基金申请] 29号明天会评吗 +4 笨笨唐 2026-08-28 4/200 2026-08-31 09:30 by huixian257
[基金申请] 国社科又开始会评了,不知道这次命运如何 +6 雨打竹帘 2026-08-30 10/500 2026-08-31 09:29 by huixian257
[基金申请] 中青基了要发朋友圈吗? +6 349506619 2026-08-28 6/300 2026-08-31 08:43 by kingkocxr
[基金申请] 面上意见出来了 +10 黄鸟于飞Chao 2026-08-29 19/950 2026-08-31 08:01 by blueearth171
[基金申请] 麻烦专家们看看评委们的意见(F口面上) +6 gdd2018 2026-08-28 11/550 2026-08-30 08:58 by 超级无敌华子
[基金申请] 为什么资助数各大高校都创新高,自己申请怎么就这么难 +12 Kittylucky 2026-08-27 13/650 2026-08-29 00:04 by superceng
[基金申请] 系统查不到 +11 董八千 2026-08-26 11/550 2026-08-28 18:06 by Leogzhya
[基金申请] 哪位高人中了,把查询到的截图贴出来让我看看,让我长长见识 +5 yuleib84 2026-08-26 6/300 2026-08-28 00:02 by yudaoqian88
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +5 a089 2026-08-26 6/300 2026-08-27 14:05 by jonewore
[基金申请] 怎么看青基中了没有啊 +5 叶九微 2026-08-26 5/250 2026-08-27 10:35 by l_zh2008
[基金申请] 为什么 国际(地区)合作与交流项目 没有放榜? 10+3 majunge000 2026-08-26 11/550 2026-08-27 08:42 by 北京莱茵编辑
[基金申请] 我不理解! +15 Edward_pc 2026-08-26 23/1150 2026-08-26 20:34 by zzuzxg
[基金申请] 2026年8月25日国自然放榜前突然收到列入评审专家邮件,有关系吗? +25 木水思豆 2026-08-25 28/1400 2026-08-26 14:53 by draco1987
[基金申请] 为什么国自然不能直接公布 +4 bjdxyxy 2026-08-26 4/200 2026-08-26 13:12 by qingmu1201
[基金申请] 国合里面能看到了 +7 一怀馨秋 2026-08-26 7/350 2026-08-26 11:23 by zhaosm1982
[基金申请] 国际合作可查了,中了面上 (EPI+1)(金币+50) +18 Ldrop2023 2026-08-26 18/900 2026-08-26 11:15 by cmrandy
[基金申请] 项目信息和经费信息在系统里都可以看到了 +6 wittyboy 2026-08-26 14/700 2026-08-26 10:55 by wittyboy
[基金申请] 国合现在查不到了吗? +10 chengyan1220 2026-08-24 20/1000 2026-08-26 08:57 by peasantsprig
[基金申请] 在坚冰还盖着北海的时候,我看到了怒放的梅花。 (金币+10) +6 ziyangfang 2026-08-25 9/450 2026-08-25 20:26 by huagongfeihu
信息提示
请填处理意见