function varargout = NN(varargin)
% NN MATLAB code for NN.fig
% NN, by itself, creates a new NN or raises the existing
% singleton*.
%
% H = NN returns the handle to a new NN or the handle to
% the existing singleton*.
%
% NN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in NN.M with the given input arguments.
%
% NN('Property','Value',...) creates a new NN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before NN_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to NN_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help NN
% Last Modified by GUIDE v2.5 15-Dec-2017 21:31:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @NN_OpeningFcn, ...
'gui_OutputFcn', @NN_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before NN is made visible.
function NN_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to NN (see VARARGIN)
% Choose default command line output for NN
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes NN wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = NN_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
NumOfSample=str2num(get(handles.edit1,'string'));%样本个数
g=str2num(get(handles.edit2,'string'));%训练步长
z=str2num(get(handles.edit3,'string'));%阻尼因子
NE=str2num(get(handles.edit4,'string'));%训练次数
l=str2num(get(handles.edit5,'string'));%遗忘因子1
a=str2num(get(handles.edit6,'string'));%遗忘因子2
A={'radiobutton1','radiobutton2','radiobutton3','radiobutton4',};
B={'BP算法','改进BP算法','Davidon最小二乘法','阻尼最小二乘法'}';
str1=handles.select1;
C={'radiobutton5','radiobutton6','radiobutton7',};
D={'随机数','正弦信号','方波信号'}';
str2=handles.select2;
for j=1:1:3
if(strcmp(str2,C{j}))
if j==1
u=rand(1,101);%随机数
end
if j==2
t=1:101;
u=sin(t); %正弦
end
if j==3
u=5*[zeros(100/4,1);-ones(100/4,1);zeros(100/4,1);-ones(100/4+1,1)];%方波
end
end
end
for j=1:1:4
if(strcmp(str1,A{j}))
if j==1
% NumOfSample=100;
%NumOfHP为隐藏节点数
NumOfHP=8;
%g为训练速率
%g=-0.2;
%NumOfEpoch为训练次数
%NE=1000;
NumOfEpoch=NumOfSample*NE;
%原系统的输入量u(个数为NumOfSample)
%for m=1:NumOfSample+1
% u(m)=sin(m);
%end
%u=rand(1,101);
%u=rand(1,NumOfSample+1);
%原系统的理想输出量y
y(1)=0;
y(2)=0;
for m=3:NumOfSample+2
y(m)=(0.8-0.5*exp(-(y(m-1))^2))*y(m-1)-(0.3+0.9*exp(-(y(m-1))^2))*y(m-2)...
+u(m-1)+0.2*u(m-2)+0.1*u(m-1)*u(m-2);
end
%下面建立初始网络,4个输入节点,NumOfHP个隐藏节点,1个输出节点
%设定输入层与隐藏层之间的默认初始权值矩阵 V_ih,阈值为1
V_ih=2*(2*rand(NumOfHP,5)-1);
%设定隐藏层与输出层之间的默认初始权值矩阵W_ji,阈值为1
W_ji=2*(2*rand(1,NumOfHP+1)-1);
%下面训练开始神经网络
k=1;
while k<=NumOfEpoch
k_=k;
k_=mod(k_,NumOfSample);
if k_==0
k_=NumOfSample;
end
%给出输入节点S_h的值
S_h=[y(k_),y(k_+1),u(k_),u(k_+1),1];
%给出输出目标D_j
D_j=y(k_+2);
%求隐藏层的输出
Net_Ai=S_h* V_ih';
for i=1:NumOfHP
A_i(i)=1/(1+exp(-Net_Ai(i)));
end
A_i(NumOfHP+1)=1;
%求输出节点的输出
R_j=A_i*W_ji';
%求误差
e=D_j-R_j;
%调整输入层与隐藏层之间的连接权值和阈值
for i=1:NumOfHP
for h=1:5
V_ih(i,h)=V_ih(i,h)-g*e*W_ji(1,i)*(1-(A_i(i)))*A_i(i)*S_h(h);
end
end
%调整隐藏层与输出层之间的连接权值和阈值
for i=1:NumOfHP+1
W_ji(1,i)=W_ji(1,i)-g*e*A_i(i);
end
k=k+1;
end
%下面为仿真验证
uu=u;
%uu=rand(1,101);
yy(1)=0;
yy(2)=0;
for m=3:102
yy(m)=(0.8-0.5*exp(-(yy(m-1))^2))*yy(m-1)-(0.3+0.9*exp(-(yy(m-1))^2))*yy(m-2)...
+uu(m-1)+0.2*uu(m-2)+0.1*uu(m-1)*uu(m-2);
end
for kk=1:100
SS_h=[yy(kk),yy(kk+1),uu(kk),uu(kk+1),1];
DD_j(kk)=yy(kk+2);
NNet_Ai=SS_h* V_ih';
for i=1:NumOfHP
AA_i(i)=1/(1+exp(-NNet_Ai(i)));
end
AA_i(NumOfHP+1)=1;
RR_j(kk)=AA_i*W_ji';
end
for t=1:100
a(t)=yy(t+2);
b(t)=RR_j(t);
c(t)=a(t)-b(t);
end
for t=1:100;
set(handles.edit7,'string',t)%动态显示运行步数
t=1:t
axes(handles.axes1);
plot(t,a(t),'r')
hold on
plot(t,b(t),'b')
legend('y','y^');
hold off
%figure(2);
axes(handles.axes2);
plot(t,c(t),'g')
pause(0.1);%动态绘图
hold on
end
end
if j==2
% NumOfSample=100;
%NumOfHP为隐藏节点个数
NumOfHP=8;
%g为训练速率
%g=-0.2;
%a为遗忘因子
%a=0.2;
%NumOfEpoch为训练次数
%NE=100;
NumOfEpoch=NumOfSample*NE;
%原系统的输入量u(个数为NumOfSample)
%for m=1:NumOfSample+1
%u(m)=sin(m);
%end
%u=rand(1,NumOfSample+1);
%原系统的理想输出量y
y(1)=0;
y(2)=0;
for m=3:NumOfSample+2
y(m)=(0.8-0.5*exp(-(y(m-1))^2))*y(m-1)-(0.3+0.9*exp(-(y(m-1))^2))*y(m-2)...
+u(m-1)+0.2*u(m-2)+0.1*u(m-1
神经网络预测.zip_combinationynm_神经网络智能预测_神经网预测
版权申诉
76 浏览量
2022-07-14
18:33:30
上传
评论
收藏 20KB ZIP 举报
局外狗
- 粉丝: 69
- 资源: 1万+
最新资源
- 数据库管理工具:dbeaver-ce-23.3.3-stable.x86-64.rpm
- 网络安全详细介绍.docx
- 爱普生打印机L805废墨仓清零软件永久版和说明
- 数据库管理工具:dbeaver-ce-23.3.3-macos-x86-64.dmg
- 数据库管理工具:dbeaver-ce-23.3.3-macos-aarch64.dmg
- 神经网络详细介绍.docx
- 数据库管理工具:dbeaver-ce-23.3.2-x86-64-setup.exe
- 小米电视2刷机包55寸48寸通刷包V1.2.15,降级专用
- 数据库管理工具:dbeaver-ce-23.3.2-stable.x86-64.rpm
- 无人驾驶汽车如何处理地图和定位?
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0