- 阅读权限
- 255
- 威望
- 7 级
- 论坛币
- -234475 个
- 通用积分
- 124.1424
- 学术水平
- 3783 点
- 热心指数
- 3819 点
- 信用等级
- 3454 点
- 经验
- 150417 点
- 帖子
- 7616
- 精华
- 32
- 在线时间
- 1327 小时
- 注册时间
- 2013-2-3
- 最后登录
- 2022-2-24
|
一个神经网络Gui源代码分享
一个MATLAB的BP神经网络Gui源代码分享,大家自己研究研究
- function varargout = bp_demo(varargin)
- % BP_DEMO M-file for bp_demo.fig
- % BP_DEMO, by itself, creates a new BP_DEMO or raises the existing
- % singleton*.
- %
- % H = BP_DEMO returns the handle to a new BP_DEMO or the handle to
- % the existing singleton*.
- %
- % BP_DEMO('CALLBACK',hObject,eventData,handles,...) calls the local
- % function named CALLBACK in BP_DEMO.M with the given input arguments.
- %
- % BP_DEMO('Property','Value',...) creates a new BP_DEMO or raises the
- % existing singleton*. Starting from the left, property value pairs are
- % applied to the GUI before bp_demo_OpeningFcn gets called. An
- % unrecognized property name or invalid value makes property application
- % stop. All inputs are passed to bp_demo_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 bp_demo
- % Last Modified by GUIDE v2.5 09-Jan-2010 19:18:03
- % Begin initialization code - DO NOT EDIT
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @bp_demo_OpeningFcn, ...
- 'gui_OutputFcn', @bp_demo_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 bp_demo is made visible.
- function bp_demo_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 bp_demo (see VARARGIN)
- % Choose default command line output for bp_demo
- handles.output = hObject;
- % Update handles structure
- guidata(hObject, handles);
- % UIWAIT makes bp_demo wait for user response (see UIRESUME)
- % uiwait(handles.figure1);
- % --- Outputs from this function are returned to the command line.
- function varargout = bp_demo_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;
- function t_sim_Callback(hObject, eventdata, handles)
- % hObject handle to t_sim (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 t_sim as text
- % str2double(get(hObject,'String')) returns contents of t_sim as a double
- % --- Executes during object creation, after setting all properties.
- function t_sim_CreateFcn(hObject, eventdata, handles)
- % hObject handle to t_sim (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 button press in train_button.
- function train_button_Callback(hObject, eventdata, handles)
- % hObject handle to train_button (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- warning off
- global net P_train T_train N Epochs Show Goal Lr fcn_hidden fcn_output fcn_learn
- % default value
- N=10;
- Epochs=1000;
- Show=10;
- Goal=1e-3;
- Lr=0.01;
- fcn_hidden='tansig';
- fcn_output='purelin';
- fcn_learn='trainlm';
- % create neural network
- net=newff(minmax(P_train),[N size(T_train,1)],{fcn_hidden,fcn_output},fcn_learn);
- net.trainParam.epochs=Epochs;
- net.trainParam.show=Show;
- net.trainParam.goal=Goal;
- net.trainParam.lr=Lr;
- net.trainParam.showwindow=0;
- [net,tr]=train(net,P_train,T_train);
- % show waitbar
- perf=tr.perf;
- perf_t=abs(perf(2:end)-perf(1))/(perf(1)-perf(end));
- h=waitbar(0,'please wait.......');
- for i=1:length(perf_t)
- waitbar(perf_t(i));
- end
- close(h);
- % --- Executes on button press in sim_button.
- function sim_button_Callback(hObject, eventdata, handles)
- % hObject handle to sim_button (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global net P_test T_test mint maxt T_sim
- % simulation
- cla(handles.axes1);
- T_sim=sim(net,P_test);
- axes(handles.axes1);
- plot(1:size(T_test,2),T_test,'b-o');
- hold on;
- if get(handles.normalize_radiobutton,'value')==1
- T_sim=postmnmx(T_sim,mint,maxt);
- plot(1:size(T_sim,2),T_sim,'r-*');
- legend(handles.axes1,'真实值','仿真值')
- title('归一化')
- else
- plot(1:size(T_sim,2),T_sim,'k-^');
- legend(handles.axes1,'真实值','仿真值')
- title('未归一化')
- end
- set(handles.t_sim,'enable','on','string',num2str(T_sim));
- grid on;
- % --- Executes on button press in save_button.
- function save_button_Callback(hObject, eventdata, handles)
- % hObject handle to save_button (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global net
- [filename,pathname]=uiputfile('*.mat','save data as');
- file=strcat(pathname,filename);
- save(file,'net');
- % --- Executes on button press in close_button.
- function close_button_Callback(hObject, eventdata, handles)
- % hObject handle to close_button (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- close;
- function t_test_Callback(hObject, eventdata, handles)
- % hObject handle to t_test (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 t_test as text
- % str2double(get(hObject,'String')) returns contents of t_test as a double
- global T_test
- T_test=str2num(get(hObject,'string'));
- % --- Executes during object creation, after setting all properties.
- function t_test_CreateFcn(hObject, eventdata, handles)
- % hObject handle to t_test (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
- function p_test_Callback(hObject, eventdata, handles)
- % hObject handle to p_test (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 p_test as text
- % str2double(get(hObject,'String')) returns contents of p_test as a double
- global P_test
- P_test=str2num(get(hObject,'string'));
- % --- Executes during object creation, after setting all properties.
- function p_test_CreateFcn(hObject, eventdata, handles)
- % hObject handle to p_test (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
- function epochs_Callback(hObject, eventdata, handles)
- % hObject handle to epochs (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 epochs as text
- % str2double(get(hObject,'String')) returns contents of epochs as a double
- global Epochs
- epochs=get(handles.epochs,'string');
- Epochs=str2num(epochs);
- flag=~isequal(Epochs,round(Epochs));
- if Epochs<=0 || flag
- warndlg('最大训练次数必须是正整数','Input Error');
- else
- if Epochs<=5
- warndlg('最大训练次数太小容易导致欠拟合问题','Input Warning');
- end
- end
- % --- Executes during object creation, after setting all properties.
- function epochs_CreateFcn(hObject, eventdata, handles)
- % hObject handle to epochs (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
- function show_Callback(hObject, eventdata, handles)
- % hObject handle to show (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 show as text
- % str2double(get(hObject,'String')) returns contents of show as a double
- global Show
- show=get(handles.show,'string');
- Show=str2num(show);
- flag=~isequal(Show,round(Show));
- if Show<=0 || flag
- warndlg('最大训练次数必须是正整数','Input Error');
- end
- % --- Executes during object creation, after setting all properties.
- function show_CreateFcn(hObject, eventdata, handles)
- % hObject handle to show (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
- function goal_Callback(hObject, eventdata, handles)
- % hObject handle to goal (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 goal as text
- % str2double(get(hObject,'String')) returns contents of goal as a double
- global Goal
- goal=get(handles.goal,'string');
- Goal=str2num(goal);
- if Goal <0
- warndlg('训练目标必须是正数','Input Error');
- else
- if Goal >1
- warndlg('训练目标设置太大容易导致欠拟合问题','Input Warning');
- elseif Goal <1e-10
- warndlg('训练目标设置太小容易导致过拟合问题','Input Warning');
- end
- end
- % --- Executes during object creation, after setting all properties.
- function goal_CreateFcn(hObject, eventdata, handles)
- % hObject handle to goal (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
- function lr_Callback(hObject, eventdata, handles)
- % hObject handle to lr (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 lr as text
- % str2double(get(hObject,'String')) returns contents of lr as a double
- global Lr
- lr=get(handles.lr,'string');
- Lr=str2num(lr);
- if Lr<0 || Lr>1
- warndlg('学习率建议设在0-1之间','Input Warning');
- end
- % --- Executes during object creation, after setting all properties.
- function lr_CreateFcn(hObject, eventdata, handles)
- % hObject handle to lr (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
- function number_hidden_Callback(hObject, eventdata, handles)
- % hObject handle to number_hidden (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 number_hidden as text
- % str2double(get(hObject,'String')) returns contents of number_hidden as a double
- global N
- n=get(handles.number_hidden,'string');
- N=str2num(n);
- flag=~isequal(N,round(N));
- if N<=0 || flag
- warndlg('隐含层神经元个数必须是正整数','Input Error');
- else
- if N<=2
- warndlg('隐含层神经元个数太小容易导致欠拟合问题','Input Warning');
- elseif N>=50
- warndlg('隐含层神经元个数太大容易导致过拟合问题','Input Warning');
- end
- end
- % --- Executes during object creation, after setting all properties.
- function number_hidden_CreateFcn(hObject, eventdata, handles)
- % hObject handle to number_hidden (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
- function fcn_hidden_Callback(hObject, eventdata, handles)
- % hObject handle to fcn_hidden (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 fcn_hidden as text
- % str2double(get(hObject,'String')) returns contents of fcn_hidden as a double
- global fcn_hidden
- h_hidden=get(handles.hiddenfcn_popupmenu,'string');
- fcn_hidden=h_hidden{get(handles.hiddenfcn_popupmenu,'value')};
- % --- Executes during object creation, after setting all properties.
- function fcn_hidden_CreateFcn(hObject, eventdata, handles)
- % hObject handle to fcn_hidden (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
- function fcn_output_Callback(hObject, eventdata, handles)
- % hObject handle to fcn_output (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 fcn_output as text
- % str2double(get(hObject,'String')) returns contents of fcn_output as a double
- global fcn_output
- h_output=get(handles.outputfcn_popupmenu,'string');
- fcn_output=h_output{get(handles.outputfcn_popupmenu,'value')};
- % --- Executes during object creation, after setting all properties.
- function fcn_output_CreateFcn(hObject, eventdata, handles)
- % hObject handle to fcn_output (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
- function fcn_learn_Callback(hObject, eventdata, handles)
- % hObject handle to fcn_learn (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 fcn_learn as text
- % str2double(get(hObject,'String')) returns contents of fcn_learn as a double
- global fcn_learn
- h_learn=get(handles.fcn_learn_popupmenu,'string');
- fcn_learn=h_learn{get(handles.fcn_learn_popupmenu,'value')};
- % --- Executes during object creation, after setting all properties.
- function fcn_learn_CreateFcn(hObject, eventdata, handles)
- % hObject handle to fcn_learn (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
- function p_train_Callback(hObject, eventdata, handles)
- % hObject handle to p_train (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 p_train as text
- % str2double(get(hObject,'String')) returns contents of p_train as a double
- global P_train str
- P_train=str2num(get(hObject,'string'));
- str=P_train;
- % --- Executes during object creation, after setting all properties.
- function p_train_CreateFcn(hObject, eventdata, handles)
- % hObject handle to p_train (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
- function t_train_Callback(hObject, eventdata, handles)
- % hObject handle to t_train (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 t_train as text
- % str2double(get(hObject,'String')) returns contents of t_train as a double
- global T_train
- T_train=str2num(get(hObject,'string'));
- % --- Executes during object creation, after setting all properties.
- function t_train_CreateFcn(hObject, eventdata, handles)
- % hObject handle to t_train (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 button press in checkbox1.
- function checkbox1_Callback(hObject, eventdata, handles)
- % hObject handle to checkbox1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hint: get(hObject,'Value') returns toggle state of checkbox1
- global P_train T_train P_test T_test a data
- if get(handles.checkbox1,'value')==1
- [filename,pathname,filterindex]=uigetfile({'*.xls';'*.txt';'*.csv';'*.mat'},'select data-file');
- str=[pathname filename];
- switch filterindex
- case 1
- data=xlsread(str);
- case 2
- data=load(str);
- case 3
- data=csvread(str);
- case 4
- data=importdata(str);
- end
- if isstruct(data)
- P_train=data.P_train;
- T_train=data.T_train;
- P_test=data.P_test;
- T_test=data.T_test;
- set(handles.p_train,'enable','off','string',[num2str(size(P_train,1)) '行' num2str(size(P_train,2)) '列']);
- set(handles.t_train,'enable','off','string',[num2str(size(T_train,1)) '行' num2str(size(T_train,2)) '列']);
- set(handles.p_test,'enable','off','string',[num2str(size(P_test,1)) '行' num2str(size(P_test,2)) '列']);
- set(handles.t_test,'enable','off','string',[num2str(size(T_test,1)) '行' num2str(size(T_test,2)) '列']);
- set(handles.normalize_radiobutton,'enable','off');
- set(handles.nonormalize_radiobutton,'enable','off');
- set(handles.slider1,'enable','off');
- set(handles.train_button,'enable','off');
- set(handles.number_hidden,'enable','off');
- set(handles.hiddenfcn_popupmenu,'enable','off');
- set(handles.outputfcn_popupmenu,'enable','off');
- set(handles.fcn_learn_popupmenu,'enable','off');
- set(handles.epochs,'enable','off');
- set(handles.show,'enable','off');
- set(handles.goal,'enable','off');
- set(handles.lr,'enable','off');
- else
- a=randperm(size(data,2));
- s_v=get(handles.slider1,'value');
- P_train=data(1:10,a(1:round(size(data,2)*s_v)));
- T_train=data(11,a(1:round(size(data,2)*s_v)));
- P_test=data(1:10,a(round(size(data,2)*s_v)+1:end));
- T_test=data(11,a(round(size(data,2)*s_v)+1:end));
- set(handles.p_train,'enable','off','string',[num2str(size(P_train,1)) '行' num2str(size(P_train,2)) '列']);
- set(handles.t_train,'enable','off','string',[num2str(size(T_train,1)) '行' num2str(size(T_train,2)) '列']);
- set(handles.p_test,'enable','off','string',[num2str(size(P_test,1)) '行' num2str(size(P_test,2)) '列']);
- set(handles.t_test,'enable','off','string',[num2str(size(T_test,1)) '行' num2str(size(T_test,2)) '列']);
- set(handles.slider1,'enable','on');
- set(handles.normalize_radiobutton,'enable','on');
- set(handles.nonormalize_radiobutton,'enable','on');
- end
- else
- p_train=get(handles.p_train,'string');
- P_train=str2num(p_train);
- t_train=get(handles.t_train,'string');
- T_train=str2num(t_train);
- set(handles.slider1,'enable','off');
- set(handles.p_train,'enable','on','string',' ');
- set(handles.t_train,'enable','on','string',' ');
- set(handles.p_test,'enable','on','string',' ');
- set(handles.t_test,'enable','on','string',' ');
- set(handles.t_sim,'enable','on','string',' ');
- set(handles.TextClear_Menu,'enable','on');
- set(handles.Text1Save_ConMenu,'enable','on');
- set(handles.Text1Clear_ConMenu,'enable','on');
- set(handles.normalize_radiobutton,'enable','on');
- set(handles.nonormalize_radiobutton,'enable','on');
- set(handles.train_button,'enable','on');
- set(handles.number_hidden,'enable','on');
- set(handles.hiddenfcn_popupmenu,'enable','on');
- set(handles.outputfcn_popupmenu,'enable','on');
- set(handles.fcn_learn_popupmenu,'enable','on');
- set(handles.epochs,'enable','on');
- set(handles.show,'enable','on');
- set(handles.goal,'enable','on');
- set(handles.lr,'enable','on');
- end
- % --- Executes on selection change in hiddenfcn_popupmenu.
- function hiddenfcn_popupmenu_Callback(hObject, eventdata, handles)
- % hObject handle to hiddenfcn_popupmenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % global fcn_hidden
- % h_hidden=get(hObject,'string');
- % fcn_hidden=h_hidden{get(hObject,'value')};
- % Hints: contents = get(hObject,'String') returns hiddenfcn_popupmenu contents as cell array
- % contents{get(hObject,'Value')} returns selected item from hiddenfcn_popupmenu
- % --- Executes during object creation, after setting all properties.
- function hiddenfcn_popupmenu_CreateFcn(hObject, eventdata, handles)
- % hObject handle to hiddenfcn_popupmenu (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 outputfcn_popupmenu.
- function outputfcn_popupmenu_Callback(hObject, eventdata, handles)
- % hObject handle to outputfcn_popupmenu (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 outputfcn_popupmenu contents as cell array
- % contents{get(hObject,'Value')} returns selected item from outputfcn_popupmenu
- % global fcn_output
- % h_output=get(hObject,'string');
- % fcn_output=h_output{get(hObject,'value')};
- % --- Executes during object creation, after setting all properties.
- function outputfcn_popupmenu_CreateFcn(hObject, eventdata, handles)
- % hObject handle to outputfcn_popupmenu (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 fcn_learn_popupmenu.
- function fcn_learn_popupmenu_Callback(hObject, eventdata, handles)
- % hObject handle to fcn_learn_popupmenu (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 fcn_learn_popupmenu contents as cell array
- % contents{get(hObject,'Value')} returns selected item from fcn_learn_popupmenu
- % global fcn_learn
- % h_learn=get(hObject,'string');
- % fcn_learn=h_learn{get(hObject,'value')};
- % --- Executes during object creation, after setting all properties.
- function fcn_learn_popupmenu_CreateFcn(hObject, eventdata, handles)
- % hObject handle to fcn_learn_popupmenu (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 slider movement.
- function slider1_Callback(hObject, eventdata, handles)
- % hObject handle to slider1 (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,'Value') returns position of slider
- % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
- global data P_train T_train P_test T_test a
- slider_value=get(hObject,'value');
- if slider_value<=0.1
- warndlg('警告:训练集数据太少,建议设置为全部数据的60%-80%','Training Set Warning');
- end
- P_train=data(1:10,a(1:round(size(data,2)*slider_value)));
- T_train=data(11,a(1:round(size(data,2)*slider_value)));
- P_test=data(1:10,a(round(size(data,2)*slider_value)+1:end));
- T_test=data(11,a(round(size(data,2)*slider_value)+1:end));
- set(handles.p_train,'string',[num2str(size(P_train,1)) '行' num2str(size(P_train,2)) '列'],'enable','off');
- set(handles.t_train,'string',[num2str(size(T_train,1)) '行' num2str(size(T_train,2)) '列'],'enable','off');
- set(handles.p_test,'string',[num2str(size(P_test,1)) '行' num2str(size(P_test,2)) '列'],'enable','off');
- set(handles.t_test,'string',[num2str(size(T_test,1)) '行' num2str(size(T_test,2)) '列'],'enable','off');
- % --- Executes during object creation, after setting all properties.
- function slider1_CreateFcn(hObject, eventdata, handles)
- % hObject handle to slider1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: slider controls usually have a light gray background.
- if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor',[.9 .9 .9]);
- end
- % --- Executes on button press in normalize_radiobutton.
- function normalize_radiobutton_Callback(hObject, eventdata, handles)
- % hObject handle to normalize_radiobutton (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hint: get(hObject,'Value') returns toggle state of normalize_radiobutton
- global P_train T_train P_test mint maxt data a
- if get(hObject,'value')==1
- set(handles.nonormalize_radiobutton,'value',0);
- [P_train,minp,maxp,T_train,mint,maxt]=premnmx(P_train,T_train);
- P_test=tramnmx(P_test,minp,maxp);
- else
- set(handles.nonormalize_radiobutton,'value',1);
- if get(handles.checkbox1,'value')==1
- slider_value=get(handles.slider1,'value');
- P_train=data(1:10,a(1:round(size(data,2)*slider_value)));
- T_train=data(11,a(1:round(size(data,2)*slider_value)));
- P_test=data(1:10,a(round(size(data,2)*slider_value)+1:end));
- else
- P_train=str2num(get(handles.p_train,'string'));
- T_train=str2num(get(handles.t_train,'string'));
- P_test=str2num(get(handles.p_test,'string'));
- end
- end
- % --- Executes on button press in nonormalize_radiobutton.
- function nonormalize_radiobutton_Callback(hObject, eventdata, handles)
- % hObject handle to nonormalize_radiobutton (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hint: get(hObject,'Value') returns toggle state of nonormalize_radiobutton
- global P_train T_train P_test mint maxt data a
- if get(hObject,'value')==1
- set(handles.normalize_radiobutton,'value',0);
- if get(handles.checkbox1,'value')==1
- slider_value=get(handles.slider1,'value');
- P_train=data(1:10,a(1:round(size(data,2)*slider_value)));
- T_train=data(11,a(1:round(size(data,2)*slider_value)));
- P_test=data(1:10,a(round(size(data,2)*slider_value)+1:end));
- else
- P_train=str2num(get(handles.p_train,'string'));
- T_train=str2num(get(handles.t_train,'string'));
- P_test=str2num(get(handles.p_test,'string'));
- end
- else
- set(handles.normalize_radiobutton,'value',1);
- [P_train,minp,maxp,T_train,mint,maxt]=premnmx(P_train,T_train);
- P_test=tramnmx(P_test,minp,maxp);
- end
- % --------------------------------------------------------------------
- function File_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to File_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % --------------------------------------------------------------------
- function Edit_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to Edit_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- if get(handles.checkbox1,'value')==1
- set(handles.TextClear_Menu,'enable','off');
- end
- % --------------------------------------------------------------------
- function Untitled_9_Callback(hObject, eventdata, handles)
- % hObject handle to Untitled_9 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % --------------------------------------------------------------------
- function Help_Callback(hObject, eventdata, handles)
- % hObject handle to Help (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- open('readme.txt');
- % --------------------------------------------------------------------
- function About_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to About_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- About;
- % --------------------------------------------------------------------
- function FigureCopy_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to FigureCopy_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- new_f_handle=figure('visible','off');
- new_axes=copyobj(handles.axes1,new_f_handle);
- set(new_axes,'units','default','position','default');
- [filename,pathname]=uiputfile('*.jpg','save picture as');
- file=strcat(pathname,filename);
- print(new_f_handle,'-djpeg',file);
- delete(new_f_handle);
- % --------------------------------------------------------------------
- function DataImport_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to DataImport_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global P_train T_train P_test T_test a data
- set(handles.checkbox1,'value',1);
- [filename,pathname,filterindex]=uigetfile({'*.xls';'*.txt';'*.csv';'*.mat'},'select data-file');
- str=[pathname filename];
- switch filterindex
- case 1
- data=xlsread(str);
- case 2
- data=load(str);
- case 3
- data=csvread(str);
- case 4
- data=importdata(str);
- end
- if isstruct(data)
- P_train=data.P_train;
- T_train=data.T_train;
- P_test=data.P_test;
- T_test=data.T_test;
- set(handles.p_train,'enable','off','string',[num2str(size(P_train,1)) '行' num2str(size(P_train,2)) '列']);
- set(handles.t_train,'enable','off','string',[num2str(size(T_train,1)) '行' num2str(size(T_train,2)) '列']);
- set(handles.p_test,'enable','off','string',[num2str(size(P_test,1)) '行' num2str(size(P_test,2)) '列']);
- set(handles.t_test,'enable','off','string',[num2str(size(T_test,1)) '行' num2str(size(T_test,2)) '列']);
- set(handles.normalize_radiobutton,'enable','off');
- set(handles.nonormalize_radiobutton,'enable','off');
- set(handles.slider1,'enable','off');
- set(handles.train_button,'enable','off');
- set(handles.number_hidden,'enable','off');
- set(handles.hiddenfcn_popupmenu,'enable','off');
- set(handles.outputfcn_popupmenu,'enable','off');
- set(handles.fcn_learn_popupmenu,'enable','off');
- set(handles.epochs,'enable','off');
- set(handles.show,'enable','off');
- set(handles.goal,'enable','off');
- set(handles.lr,'enable','off');
- else
- a=randperm(size(data,2));
- s_v=get(handles.slider1,'value');
- P_train=data(1:10,a(1:round(size(data,2)*s_v)));
- T_train=data(11,a(1:round(size(data,2)*s_v)));
- P_test=data(1:10,a(round(size(data,2)*s_v)+1:end));
- T_test=data(11,a(round(size(data,2)*s_v)+1:end));
- set(handles.p_train,'enable','off','string',[num2str(size(P_train,1)) '行' num2str(size(P_train,2)) '列']);
- set(handles.t_train,'enable','off','string',[num2str(size(T_train,1)) '行' num2str(size(T_train,2)) '列']);
- set(handles.p_test,'enable','off','string',[num2str(size(P_test,1)) '行' num2str(size(P_test,2)) '列']);
- set(handles.t_test,'enable','off','string',[num2str(size(T_test,1)) '行' num2str(size(T_test,2)) '列']);
- set(handles.slider1,'enable','on');
- set(handles.normalize_radiobutton,'enable','on');
- set(handles.nonormalize_radiobutton,'enable','on');
- end
- % --------------------------------------------------------------------
- function DataExport_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to DataExport_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global P_train T_train P_test T_test T_sim
- [filename,pathname]=uiputfile('*.mat','save data as');
- file=strcat(pathname,filename);
- save(file,'P_train','T_train','P_test','T_test','T_sim');
- % --------------------------------------------------------------------
- function Exit_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to Exit_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- close;
- % --------------------------------------------------------------------
- function TextClear_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to TextClear_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- set(handles.p_train,'string',' ');
- set(handles.t_train,'string',' ');
- set(handles.p_test,'string',' ');
- set(handles.t_test,'string',' ');
- set(handles.t_sim,'string',' ');
- % --------------------------------------------------------------------
- function FigureClear_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to FigureClear_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- cla(handles.axes1);
- % --------------------------------------------------------------------
- function NetImport_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to NetImport_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global net
- [filename,pathname,filterindex]=uigetfile('*.mat','select net-file');
- str=[pathname filename];
- net=importdata(str);
- % --------------------------------------------------------------------
- function NetworkExport_Menu_Callback(hObject, eventdata, handles)
- % hObject handle to NetworkExport_Menu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global net
- [filename,pathname]=uiputfile('*.mat','save data as');
- file=strcat(pathname,filename);
- save(file,'net');
- % --------------------------------------------------------------------
- function FigureCopy_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to FigureCopy_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- new_f_handle=figure('visible','off');
- new_axes=copyobj(handles.axes1,new_f_handle);
- set(new_axes,'units','default','position','default');
- [filename,pathname]=uiputfile('*.jpg','save picture as');
- file=strcat(pathname,filename);
- print(new_f_handle,'-djpeg',file);
- delete(new_f_handle);
- % --------------------------------------------------------------------
- function FigureClear_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to FigureClear_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- cla(handles.axes1);
- % --------------------------------------------------------------------
- function Text1Save_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text1Save_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- [filename,pathname]=uiputfile('*.mat','save data as');
- file=strcat(pathname,filename);
- p_train=str2num(get(handles.p_train,'string'));
- save(file,'p_train');
- % --------------------------------------------------------------------
- function Text1Clear_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text1Clear_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- set(handles.p_train,'string',' ');
- % --------------------------------------------------------------------
- function FigureCopy_ConuMenu_Callback(hObject, eventdata, handles)
- % hObject handle to FigureCopy_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % --------------------------------------------------------------------
- function Figure_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Figure_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % --------------------------------------------------------------------
- function Text1_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text1_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- if get(handles.checkbox1,'value')==1
- set(handles.Text1Save_ConMenu,'enable','off');
- set(handles.Text1Clear_ConMenu,'enable','off');
- end
- % --------------------------------------------------------------------
- function Text5Save_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text5Save_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- [filename,pathname]=uiputfile('*.mat','save data as');
- file=strcat(pathname,filename);
- t_sim=str2num(get(handles.t_sim,'string'));
- save(file,'t_sim');
- % --------------------------------------------------------------------
- function Text5Clear_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text5Clear_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- set(handles.t_sim,'string',' ');
- % --------------------------------------------------------------------
- function Text4Save_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text4Save_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- [filename,pathname]=uiputfile('*.mat','save data as');
- file=strcat(pathname,filename);
- t_test=str2num(get(handles.t_test,'string'));
- save(file,'t_test');
- % --------------------------------------------------------------------
- function Text4Clear_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text4Clear_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- set(handles.t_test,'string',' ');
- % --------------------------------------------------------------------
- function Text3Save_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text3Save_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- [filename,pathname]=uiputfile('*.mat','save data as');
- file=strcat(pathname,filename);
- p_test=str2num(get(handles.p_test,'string'));
- save(file,'p_test');
- % --------------------------------------------------------------------
- function Text3Clear_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text3Clear_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- set(handles.p_test,'string',' ')
- % --------------------------------------------------------------------
- function Text2Save_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text2Save_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- [filename,pathname]=uiputfile('*.mat','save data as');
- file=strcat(pathname,filename);
- t_train=str2num(get(handles.t_train,'string'));
- save(file,'t_train');
- % --------------------------------------------------------------------
- function Text2Clear_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text2Clear_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- set(handles.t_train,'string',' ');
- % --------------------------------------------------------------------
- function Text2_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text2_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- if get(handles.checkbox1,'value')==1
- set(handles.Text2Save_ConMenu,'enable','off');
- set(handles.Text2Clear_ConMenu,'enable','off');
- end
- % --------------------------------------------------------------------
- function Text3_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text3_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- if get(handles.checkbox1,'value')==1
- set(handles.Text3Save_ConMenu,'enable','off');
- set(handles.Text3Clear_ConMenu,'enable','off');
- end
- % --------------------------------------------------------------------
- function Text4_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text4_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- if get(handles.checkbox1,'value')==1
- set(handles.Text4Save_ConMenu,'enable','off');
- set(handles.Text4Clear_ConMenu,'enable','off');
- end
- % --------------------------------------------------------------------
- function Text5_ConMenu_Callback(hObject, eventdata, handles)
- % hObject handle to Text5_ConMenu (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
复制代码
|
-
总评分: 经验 + 100
学术水平 + 5
热心指数 + 5
信用等级 + 5
查看全部评分
|