神经网络算法

%BP神经网络
clear all
clc
X=-1:0.1:1;
D=[-0.9602 -0.5770 -0.0729 0.3771 0.6405 0.6600 0.4609...
    0.1336 -0.2013 -0.4344 -0.5000 -0.3930 -0.1647 -.0988...
    0.3072 0.3960 0.3449 0.1816 -0.312 -0.2189 -0.3201];
net = newff(minmax(X),[5 1],{'tansig','tansig'}, 'trainlm');%隐含层5个神经元,输出层1个神经元
net.trainParam.epochs = 10000; %训练的最大次数
net.trainParam.goal = 1e-5; %全局最小误差
net = train(net,X,D); 
O = sim(net,X); %仿真模拟
figure;
plot(X,D,X,O,'r'); %绘制训练后得到的结果和误差曲线
legend('原始数据','仿真数据')
V = net.iw{1,1}%输入层到中间层权值
theta1 = net.b{1}%中间层各神经元阈值
W = net.lw{2,1}%中间层到输出层权值
theta2 = net.b{2}%输出层各神经元阈值
 
%%以下是计算结果
V =
 
   63.2827
  -21.7727
  -19.3926
    4.2953
    1.7695
 
 
theta1 =
 
  -44.7043
    7.6890
    2.1589
    1.4575
    2.2024
 
 
W =
 
   -0.3473   -0.2570   -0.2184   -1.3224    6.1471
 
 
theta2 =
 
   -5.2381

 

你可能感兴趣的:(算法)