⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bpnet.m

📁 结合Matlab的GUI和神经网络开发出来的界面
💻 M
📖 第 1 页 / 共 3 页
字号:
function varargout = BPNET(varargin)% BPNET M-file for BPNET.fig%      BPNET, by itself, creates a new BPNET or raises the existing%      singleton*.%%      H = BPNET returns the handle to a new BPNET or the handle to%      the existing singleton*.%%      BPNET('CALLBACK',hObject,eventData,handles,...) calls the local%      function named CALLBACK in BPNET.M with the given input arguments.%%      BPNET('Property','Value',...) creates a new BPNET or raises the%      existing singleton*.  Starting from the left, property value pairs are%      applied to the GUI before BPNET_OpeningFcn gets called.  An%      unrecognized property name or invalid value makes property application%      stop.  All inputs are passed to BPNET_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 BPNET% Last Modified by GUIDE v2.5 05-Mar-2009 00:00:31% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, ...                   'gui_Singleton',  gui_Singleton, ...                   'gui_OpeningFcn', @BPNET_OpeningFcn, ...                   'gui_OutputFcn',  @BPNET_OutputFcn, ...                   'gui_LayoutFcn',  [] , ...                   'gui_Callback',   []);if nargin && ischar(varargin{1})    gui_State.gui_Callback = str2func(varargin{1});endif 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 BPNET is made visible.function BPNET_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 BPNET (see VARARGIN)% Choose default command line output for BPNEThandles.output = hObject;movegui(gcf,'center');  % 设置窗口居中global sqsq=0;% Update handles structureguidata(hObject, handles);% --- Outputs from this function are returned to the command line.function varargout = BPNET_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 structurevarargout{1} = handles.output;% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton5 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global x y tx ty net S1 S2 TF1 TF2 BTF Epochs Goal Show Lr sq tr canshu errory wc ycp=x';t=y';net=newff(p,t,[S1,S2],{TF1,TF2},BTF);    % 新建神经网络并设置其各种参数net=init(net);                           % 初始化网络net.trainParam.epochs=Epochs;            % 设置网络的训练步数net.trainParam.goal=Goal;                % 设置网络的训练目标net.trainParam.show =Show;               % 设置网络的net.trainParam.lr=Lr;                    % 设置网络的[net,tr]=train(net,p,t);                 % 训练网络并返回网络及其训练记录sq=sq+1;                                 % 记录训练次数str1=strcat({'  S1  = '},num2str(S1),{'            '},{'S2  = '},num2str(S2));str2=strcat({'  TF1 = '},{TF1},{'            '},{'TF2 = '},{TF2});str3=strcat({'  BTF = '},{BTF});str4=strcat({'  Epochs = '},num2str(Epochs),{'    '},{'Goal = '},num2str(Goal));str5=strcat({'  Show   = '},num2str(Show),{'        '},{'Lr   = '},num2str(Lr));canshu{sq}=char([str1;' ';str2;' ';str3;' ';str4;' ';str5]);               % 保存每次所训练的网络的各类参数m=numel(ty);se1=0;se2=0;for i=1:m/2    p_cs(:,i)=tx(i,:)';    yc(:,i)=sim(net,p_cs(:,i));  % 由主界面传递的测试样本进行预测数据    errory(i,1)=ty(i,1)-yc(1,i);  % 计算y1的测试样本中各预测数据的误差    errory(i,2)=ty(i,2)-yc(2,i);  % 计算y2的测试样本中各预测数据的误差    se1=se1+errory(i,1)^2;    se2=se2+errory(i,2)^2;endwc(sq,1)=sqrt(se1/m);    % 计算y1的测试样本的总均方误差wc(sq,2)=sqrt(se2/m);    % 计算y2的测试样本的总均方误差% --- Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton6 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global xlist ylist tx ty sq canshu errory wc ycxy={xlist,ylist,tx,ty,sq,canshu,errory,wc,yc};    % 打包要传递给子界面的数据CS(xy);                                           % 传递数据给子界面并打开子界面% --- Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton7 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global netYY(net);  % 传递数据给子界面并打开子界面% --- Executes on button press in pushbutton7.function pushbutton8_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton7 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global x y net trxy={x,y,net,tr};  % 打包要传递给子界面的数据QT(xy);           % 传递数据给子界面并打开子界面function edit1_Callback(hObject, eventdata, handles)% hObject    handle to edit1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as text%        str2double(get(hObject,'String')) returns contents of edit1 as a doubleglobal S1edit1_value=str2double(get(handles.edit1,'string'));if (edit1_value>0)&&(edit1_value==round(edit1_value))  % 判断输入的隐含层的神经元个数是否正确    S1=edit1_value;else    msgbox('输入错误,请输入正整数!','错误');  % 提示用户输入错误end;% --- Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor','white');endfunction edit2_Callback(hObject, eventdata, handles)% hObject    handle to edit2 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text%        str2double(get(hObject,'String')) returns contents of edit2 as a doubleglobal S2edit2_value=str2double(get(handles.edit2,'string'));if (edit2_value>0)&&(edit2_value==round(edit2_value))  % 判断输入的输出层的神经元个数是否正确    S2=edit2_value;else    msgbox('输入错误,请输入正整数!','错误');  % 提示用户输入错误end;% --- Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit2 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor','white');end% --- Executes on selection change in popupmenu1.function popupmenu1_Callback(hObject, eventdata, handles)% hObject    handle to popupmenu1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array%        contents{get(hObject,'Value')} returns selected item from popupmenu1global TF1popup_sel=get(handles.popupmenu1,'Value');switch popup_sel    case 1        msgbox('请选择输入层到隐含层的传递函数!','错误');  % 提示用户正确选择输入层到隐含层的传递函数    case 2        TF1='tansig';  % 设置输入层到隐含层的传递函数为tansig    case 3        TF1='logsig';  % 设置输入层到隐含层的传递函数为logsig    case 4        TF1='dtansig';  % 设置输入层到隐含层的传递函数为dtansig    case 5        TF1='dlogsig';  % 设置输入层到隐含层的传递函数为dlogsigend;% --- Executes during object creation, after setting all properties.function popupmenu1_CreateFcn(hObject, eventdata, handles)% hObject    handle to popupmenu1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor','white');end% --- Executes on selection change in popupmenu2.function popupmenu2_Callback(hObject, eventdata, handles)% hObject    handle to popupmenu2 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array%        contents{get(hObject,'Value')} returns selected item from popupmenu2global TF2popup_sel=get(handles.popupmenu2,'Value');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -