?? elman.asv
字號(hào):
function varargout = Elman(varargin)
% ELMAN M-file for Elman.fig
% ELMAN, by itself, creates a new ELMAN or raises the existing
% singleton*.
%
% H = ELMAN returns the handle to a new ELMAN or the handle to
% the existing singleton*.
%
% ELMAN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ELMAN.M with the given input arguments.
%
% ELMAN('Property','Value',...) creates a new ELMAN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Elman_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Elman_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help Elman
% Last Modified by GUIDE v2.5 26-May-2006 21:30:34
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Elman_OpeningFcn, ...
'gui_OutputFcn', @Elman_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 Elman is made visible.
function Elman_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 Elman (see VARARGIN)
% Choose default command line output for Elman
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Elman wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Elman_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 PB_T.
function PB_T_Callback(hObject, eventdata, handles)
% hObject handle to PB_T (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
user_data=get(findobj('Tag','PB_T'),'userdata');
switch user_data.chose
case 1
set(findobj('Tag','PB_T'),'String','Next>>');
t=1:20;
p1=sin(t);
p2=sin(t)*2;
set(findobj('Tag','axes2'),'NextPlot','add');
plot(findobj('Tag','axes2'),t,p1,'r');
hold on;
plot(findobj('Tag','axes2'),t,p2,'b');
hold on;
str1=sprintf('>> t=1:20;\n>> p1=sin(t);\n>> p2=sin(t)*2;\n>> plot(findobj(''Tag'',''axes1''),t,p1,''r'');');
str2=sprintf('\n>> hold on;\n>> plot(findobj(''Tag'',''axes1''),t,p2,''b'');\n>> hold on;');
str=strcat(str1,str2);
set(findobj('Tag','edit1'),'String',str);
str='代碼定義了兩個(gè)正弦波信號(hào)p1和p2作為Elman網(wǎng)絡(luò)的輸入,其中p1的幅值為1,p2的幅值為2。信號(hào)波形繪制在繪圖區(qū)';
set(findobj('Tag','edit2'),'String',str);
set(findobj('Tag','text1'),'String','網(wǎng)絡(luò)的設(shè)計(jì)');
user_data.chose=user_data.chose+1;
user_data.p1=p1;
user_data.p2=p2;
set(findobj('Tag','PB_T'),'userdata',user_data);
set(findobj('Tag','text2'),'String','step1');
case 2
t1=ones(1,20);
t2=ones(1,20)*2;
str=sprintf('>> t1=ones(1,20);\n>> t2=ones(1,20)*2;');
set(findobj('Tag','edit1'),'String',str);
str='代碼產(chǎn)生兩組向量t1和t2作為Elman網(wǎng)絡(luò)的目標(biāo)輸出向量';
set(findobj('Tag','edit2'),'String',str);
user_data.chose=user_data.chose+1;
user_data.t1=t1;
user_data.t2=t2;
set(findobj('Tag','PB_T'),'userdata',user_data);
set(findobj('Tag','text2'),'String','step2');
case 3
p1=user_data.p1;
p2=user_data.p2;
t1=user_data.t1;
t2=user_data.t2;
p=[p1 p2 p1 p2];
t=[t1 t2 t1 t2];
Pseq=con2seq(p);
Tseq=con2seq(t);
str=sprintf('>> p=[p1 p2 p1 p2];\n>> t=[t1 t2 t1 t2];\n>> Pseq=con2seq(p);\n>> Tseq=con2seq(t);');
set(findobj('Tag','edit1'),'String',str);
str='p1和p2聯(lián)合起來(lái)建立一個(gè)新的輸入向量序列p;t1和t2也可以以同樣的方式聯(lián)合起來(lái)建立一個(gè)新的目標(biāo)向量t。并利用函數(shù)con2seq將其轉(zhuǎn)換為序列形式';
set(findobj('Tag','edit2'),'String',str);
user_data.chose=user_data.chose+1;
user_data.Pseq=Pseq;
user_data.Tseq=Tseq;
user_data.p=p;
user_data.t=t;
set(findobj('Tag','PB_T'),'userdata',user_data);
set(findobj('Tag','text2'),'String','step3');
case 4
R=1;
S2=1;
S1=10;
net=newelm([-2 2],[S1,S2],{'tansig','purelin'});
str=sprintf('>> R=1;\n>> S2=1;\n>> S1=10;\n>> net=newelm([-2 2],[S1,S2],{''trasig'',''purelin''}');
set(findobj('Tag','edit1'),'String',str);
str='R為輸入元素的數(shù)目,S2為網(wǎng)絡(luò)輸出神經(jīng)元的數(shù)目,S1是網(wǎng)絡(luò)中間層的神經(jīng)元數(shù)目,newelm函數(shù)用來(lái)設(shè)計(jì)一個(gè)Elman神經(jīng)網(wǎng)絡(luò)';
set(findobj('Tag','edit2'),'String',str);
user_data.chose=user_data.chose+1;
user_data.net=net;
set(findobj('Tag','PB_T'),'userdata',user_data);
set(findobj('Tag','text2'),'String','step4');
case 5
Pseq=user_data.Pseq;
Tseq=user_data.Tseq;
net=user_data.net;
set(findobj('Tag','text1'),'String','網(wǎng)絡(luò)訓(xùn)練');
str=sprintf('>> net.trainParam.epochs=500;\n>> net=trian(net,Pseq,Tseq);');
set(findobj('Tag','edit1'),'String',str);
str='網(wǎng)絡(luò)的訓(xùn)練步數(shù)設(shè)定為500次,trian函數(shù)用來(lái)訓(xùn)練網(wǎng)絡(luò)';
set(findobj('Tag','edit2'),'String',str);
net.trainParam.epochs=300;
net=train(net,Pseq,Tseq);
user_data.chose=user_data.chose+1;
user_data.net=net;
set(findobj('Tag','PB_T'),'userdata',user_data);
set(findobj('Tag','text2'),'String','step5');
case 6
Pseq=user_data.Pseq;
net=user_data.net;
Tseq=user_data.Tseq
set(findobj('Tag','text1'),'String','網(wǎng)絡(luò)測(cè)試');
str=sprintf('>> y=sim(net,Pseq);\n>> t5=1:80;\n>> plot(findobj(''Tag'',''axes1''),t5,cat(2,y{:}),t5,cat(2,Tseq{:}),''b--'');');
set(findobj('Tag','edit1'),'String',str);
str='利用訓(xùn)練數(shù)據(jù)對(duì)網(wǎng)絡(luò)進(jìn)行測(cè)試';
set(findobj('Tag','edit2'),'String',str);
y=sim(net,Pseq);
t5=1:80;
% h=subplot('position',[17.0 16.077 80.2 23.154]);
% set(findobj('Tag','axes1'),'NextPlot','replace');
% set(findobj('Tag','axes1'),'NextPlot','add');
h=findobj('Tag','axes1');
plot(h,t5,cat(2,y{:}),t5,cat(2,Tseq{:}),'b--');
user_data.chose=user_data.chose+1;
user_data.net=net;
set(findobj('Tag','PB_T'),'userdata',user_data);
set(findobj('Tag','text2'),'String','step6');
case 7
p3=sin(1:20)*1.6;
t3=ones(1,20)*1.6;
p4=sin(1:20)*1.2;
t4=ones(1,20)*1.2;
pg=[p3 p4 p3 p4];
tg=[t3 t4 t3 t4];
pgseq=con2seq(pg);
str1=sprintf('>> p3=sin(1:20)*1.6;\n>> t3=ones(1,20)*1.6;\n>> p4=sin(1:20)*1.2;\n>> t4=ones(1,20)*1.2;');
str2=sprintf('\n>> pg=[p3 p4 p3 p4];\n>> tg=[t3 t4 t3 t4];\n>> pgseq=con2seq(pg);');
str=strcat(str1,str2);
set(findobj('Tag','edit1'),'String',str);
str='用和訓(xùn)練樣本相似的方法建立新的測(cè)試樣本';
set(findobj('Tag','edit2'),'String',str);
user_data.tg=tg;
user_data.pgseq=pgseq;
user_data.chose=user_data.chose+1;
set(hObject,'userdata',user_data);
set(findobj('Tag','text1'),'String','step 7');
case 8
pgseq=user_data.pgseq;
tg=user_data.tg;
net=user_data.net;
t5=1:80;
a=sim(net,pgseq);
% h=subplot('position',[17.0 16.077 80.2 23.154]);
h=findobj('Tag','axes1')
% set(h,'NextPlot','replace');
% set(findobj('Tag','axes1'),'NextPlot','add');
plot(h,t5,cat(2,a{:}),t5,tg,'b--');
str=sprintf('>> a=sim(net,pgseq);\n>> plot(findobj(''Tag'',''axes1''),t5,cat(2,a{:}),t5,tg,''b--'');');
set(findobj('Tag','edit1'),'String',str);
str='將測(cè)試輸入樣本提供給網(wǎng)絡(luò),利用仿真函數(shù)sim產(chǎn)生網(wǎng)絡(luò)輸出,并與測(cè)試目標(biāo)樣本相比較,觀察網(wǎng)絡(luò)的性能';
set(findobj('Tag','edit2'),'String',str);
set(hObject,'String','End');
user_data.chose=user_data.chose+1;
set(hObject,'userdata',user_data);
set(findobj('Tag','text2'),'String','step 8');
case 9
set(hObject,'String','Start')
set(findobj('Tag','edit2'),'String','請(qǐng)按‘開(kāi)始‘按鈕啟動(dòng)演示');
str1='Elman神經(jīng)網(wǎng)絡(luò)是Elman于1990年提出的,該模型在前饋網(wǎng)絡(luò)的隱含層增加一個(gè)承接層,作為一步延時(shí)算子,'
str2='達(dá)到記憶的目的,從而使系統(tǒng)具有適應(yīng)時(shí)變特性的能力,能直接反映動(dòng)態(tài)過(guò)程的特性';
str=strcat(str1,str2);
set(findobj('Tag','edit1'),'String',str)
set(findobj('Tag','text1'),'String','開(kāi)始');
set(findobj('Tag','text2'),'String','step 0');
temp_data.chose=1;
set(hObject,'userdata',temp_data);
reset(findobj('Tag','figure1'));
end
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 double
% --- 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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes during object creation, after setting all properties.
function PB_T_CreateFcn(hObject, eventdata, handles)
% hObject handle to PB_T (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
user_data.chose=1;
set(findobj('Tag','PB_T'),'userdata',user_data);
function 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 double
% --- 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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;
SysGui;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -