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
评论0