当前位置: 首页 > news >正文

bp网络实现CPI指标预测

某地的CPI指标,d1、d2、d3、f为连续四年的指数,现在选取d1、d2、d3作为网络初始值,f为网络目标值进行训练网络。

具体数据如下:
d1=[0.2356 0.2589 0.3000 0.2445 0.2589 0.2366 0.2897 0.2368 0.2569 0.2010 0.2111 0.3012];
d2=[0.2562 0.3023 0.2454 0.2465 0.2146 0.2037 0.2898 0.2969 0.2110 0.2111 0.2212 0.3213];
d3=[0.3000 0.2458 0.2315 0.2216 0.2317 0.2218 0.2039 0.2510 0.2111 0.2212 0.2313 0.3114 ];
f=[0.2515 0.2146 0.2147 0.2218 0.2169 0.2260 0.2111 0.2212 0.2313 0.2414 0.2115 0.3216 ];

代码如下:

%% clc; clear; % 数据输入 % 某地的CPI指标,有数据如下: d1=[0.2356 0.2589 0.3000 0.2445 0.2589 0.2366 0.2897 0.2368 0.2569 0.2010 0.2111 0.3012]; d2=[0.2562 0.3023 0.2454 0.2465 0.2146 0.2037 0.2898 0.2969 0.2110 0.2111 0.2212 0.3213]; d3=[0.3000 0.2458 0.2315 0.2216 0.2317 0.2218 0.2039 0.2510 0.2111 0.2212 0.2313 0.3114 ]; f=[0.2515 0.2146 0.2147 0.2218 0.2169 0.2260 0.2111 0.2212 0.2313 0.2414 0.2115 0.3216 ]; k=1:1:12; % 使用12个月的数据训练得到网络仿真计算相对误差 p1=zeros(1,12); p2=zeros(1,12); p3=zeros(1,12); t=zeros(1,12); p1(1)=d1(1); for i=2:12 p1(i)=0.1*d1(i)+p1(i-1); end p2(1)=d2(1); for i=2:12 p2(i)=0.1*d2(i)+p2(i-1); end p3(1)=d3(1); for i=2:12 p3(i)=0.1*d3(i)+p3(i-1); end t(1)=f(1); for i=2:12 t(i)=0.1*f(i)+t(i-1); end %数据标准化处理,标准化为网络输入p,期望输出tt p=[(p1-mean(p1))./std(p1);(p2-mean(p2))./std(p2);(p3-mean(p3))./std(p3)]; tt=(t- mean(t))./std(t); %用newff建立bp网络并训练 net=newff(minmax(p),[4,1],{'tansig','purelin'},'trainlm'); net.iw{1,1}=zeros(size(net.iw{1,1}))+0.5; net.lw{2,1}=zeros(size(net.lw{2,1}))+0.75; net.b{1,1}=zeros(size(net.b{1,1}))+0.5; net.b{2,1}=zeros(size(net.b{2,1})); net.trainParam.epochs=3000; net.trainParam.goal =0.000005; % 训练网络 net=train(net,p,tt); %网络仿真得到网络输出,并计算误差 tt1=sim(net,p); %利用标准化的逆变换得到t1的近似值to % to为总增加率 to=tt1.*std(t)+mean(t); a=zeros(1,12); a(1)=to(1); for i=2:12 a(i)=(to(i)-to(i-1))*10; end %累减得到近似的实际产值a err_net=(tt1-tt)./tt;%网络相对误差 err_add=(to-t)./t;%总值累加数相对误差 err_real=(a-f)./f;%实际总值相对误差 %输出结果% r1=[err_net;err_add;err_real]'%网络相对误差/累加数相对误差/实际值相对误差 r=err_real./err_add %误差放大倍数 l=[to;t;to-t;a;f;a-f]'%累加数计算值/累加数/绝对误差//计算的实际值/实际值/绝对误差 plotyy(k,to,k,t);%仿真累加值(to)随时间变化曲线与实际累加值(t)随时间变化曲线 % Create graphs with y-axes on both left and right side % plotyy(X1,Y1,X2,Y2) plots X1 versus Y1 with y-axis labeling on the left % and plots X2 versus Y2 with y-axis labeling on the right. % % This example graphs two mathematical functions using plot as the plotting function. % The two y-axes enable you to display both sets of data on one graph % even though relative values of the data are quite different. x = 0:0.01:20; % y1 = 200*exp(-0.05*x).*sin(x); % y2 = 0.8*exp(-0.5*x).*sin(10*x); % [AX,H1,H2] = plotyy(x,y1,x,y2,'plot'); % % You can use the handles returned by plotyy to label the axes % and set the line styles used for plotting. % With the axes handles you can specify the YLabel properties of the left- % and right-side y-axis: set(get(AX(1),'Ylabel'),'String','Left Y-axis') % set(get(AX(2),'Ylabel'),'String','Right Y-axis') % % Use the xlabel and title commands to label the x-axis and add a title: % xlabel('Zero to 20 \musec.') % title('Labeling plotyy') % % Use the line handles to set the LineStyle properties of the left- % and right-side plots: set(H1,'LineStyle','--') % set(H2,'LineStyle',':') figure(2); plotyy(k,a,k,f);%仿真值(a)随时间变化曲线与实际值(f)随时间变化曲线

相关文章:

  • 算法:计算1的个数
  • bp网络实现预测
  • 亭中避雨
  • SQL_VARIANT_PROPERTY 返回有关 sql_variant 值的基本数据类型和其他信息
  • 我宣布~~~~~
  • 调整参数对bp网络的影响
  • 协作应用程序标记语言 (CAML)---Query语法示例
  • 用BP网络完成函数的逼近
  • 天终于凉快了!开始工作哦
  • ArcSDE vs. oracle Spatial 4
  • VS2005制作安装包的“系统必备”选项
  • 训练前后bp网络仿真结果分析
  • 如何从SAP中连接其他数据库
  • SQL简繁转换函数
  • 政府部门信息化人员的定位
  • 网络传输文件的问题
  • 【407天】跃迁之路——程序员高效学习方法论探索系列(实验阶段164-2018.03.19)...
  • 【个人向】《HTTP图解》阅后小结
  • bearychat的java client
  • create-react-app项目添加less配置
  • CSS中外联样式表代表的含义
  • gulp 教程
  • HTTP传输编码增加了传输量,只为解决这一个问题 | 实用 HTTP
  • java第三方包学习之lombok
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • Python学习之路16-使用API
  • React 快速上手 - 07 前端路由 react-router
  • Vue.js 移动端适配之 vw 解决方案
  • Vue实战(四)登录/注册页的实现
  • Zepto.js源码学习之二
  • 函数式编程与面向对象编程[4]:Scala的类型关联Type Alias
  • 使用API自动生成工具优化前端工作流
  • 使用Tinker来调试Laravel应用程序的数据以及使用Tinker一些总结
  • 数组的操作
  • 怎么把视频里的音乐提取出来
  • 完善智慧办公建设,小熊U租获京东数千万元A+轮融资 ...
  • ​【已解决】npm install​卡主不动的情况
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • #在线报价接单​再坚持一下 明天是真的周六.出现货 实单来谈
  • $.ajax中的eval及dataType
  • (4)STL算法之比较
  • (C语言)逆序输出字符串
  • (C语言)深入理解指针2之野指针与传值与传址与assert断言
  • (附源码)计算机毕业设计SSM疫情社区管理系统
  • (汇总)os模块以及shutil模块对文件的操作
  • (亲测成功)在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机(ubuntu server版本)...
  • (全注解开发)学习Spring-MVC的第三天
  • (一)python发送HTTP 请求的两种方式(get和post )
  • (最简单,详细,直接上手)uniapp/vue中英文多语言切换
  • .apk文件,IIS不支持下载解决
  • .bat批处理(十一):替换字符串中包含百分号%的子串
  • .NET Core WebAPI中封装Swagger配置
  • .NET Core 项目指定SDK版本
  • .NET Framework杂记
  • .NET 程序如何获取图片的宽高(框架自带多种方法的不同性能)