栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【BP神经网络-非线性函数拟合】

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【BP神经网络-非线性函数拟合】

x1 = linspace(-5,5,2000);
x2 = linspace(-5,5,2000);
y = x1.^2 + x2.^2;

Data classification
input = [x1;x2];
output = y;
k = rand(1,2000);
[m,n] = sort(k);

Training set
Input_Train = input(:,n(1:1900));
Output_Train = output(:,n(1:1900));

Test set
Input_Test = input(:,n(1901:end));
Output_Test = output(:,n(1901:end));

Training set normalization
[Input_Y,Input_PS] = mapminmax(Input_Train);
[Output_Y,Output_PS] = mapminmax(Output_Train);

Create BP neural network
net = newff(Input_Y,Output_Y,5);
net.trainParam.epochs = 100;
net.trainParam.lr = 0.1;
net.trainParam.goal = 0.00004;
net = train(net,Input_Y,Output_Y); % Training neural network

Test data normalization
Input_Y_Test = mapminmax('apply',Input_Test,Input_PS);
an = sim(net,Input_Y_Test);% Forecast output
BP_Output = mapminmax('reverse',an,Output_PS);% Output antinormalization

BP network prediction pattern
figure
plot(BP_Output,':og');
hold on;
plot(Output_Test,'-*');
legend('预测输出','期望输出');
title('BP网络预测输出','FontSize',12);
ylabel('函数输出',"FontSize",12);
xlabel('样本',"FontSize",12);

figure;
plot(BP_Output-Output_Test,'-*');
title('BP网络预测误差',"FontSize",12);
ylabel('误差',"FontSize",12);
xlabel('样本',"FontSize",12);

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/739476.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号