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

📄 lnn.m

📁 线性神经网络
💻 M
字号:
function varargout = LNN(varargin)
% LNN M-file for LNN.fig
%      LNN, by itself, creates a new LNN or raises the existing
%      singleton*.
%
%      H = LNN returns the handle to a new LNN or the handle to
%      the existing singleton*.
%
%      LNN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in LNN.M with the given input arguments.
%
%      LNN('Property','Value',...) creates a new LNN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before LNN_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to LNN_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 LNN

% Last Modified by GUIDE v2.5 28-May-2006 22:44:46

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @LNN_OpeningFcn, ...
                   'gui_OutputFcn',  @LNN_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 LNN is made visible.
function LNN_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 LNN (see VARARGIN)

% Choose default command line output for LNN
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes LNN wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = LNN_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_Data_In.
function pb_Data_In_Callback(hObject, eventdata, handles)
% hObject    handle to pb_Data_In (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

[name,path]=uigetfile('*.mat','Load data set');
pathname=strcat(path,name); 
file.name=name;  file.path=path;  file.pathname=pathname;
targT=load('-mat',file.pathname);
x=1:1:length(targT.DOutput);
title('输入输出');
set(findobj('Tag','axes1'),'color',[0.753 0.753 0.753]);
plot(findobj('Tag','axes1'),x,targT.DOutput(1,:),'r+');
hold on;
plot(findobj('Tag','axes1'),x,targT.DOutput(2,:),'b+');
hold on;
plot(findobj('Tag','axes1'),x,targT.DOutput(3,:),'m+');
hold on;
plot(findobj('Tag','axes1'),x,targT.DOutput(4,:),'c+');
legend('L1','L2','L3','L4');
set(legend,'fontsize',8);

LoadData.datai=targT.DInput;
LoadData.datao=targT.DOutput;
set(findobj('Tag','EData_IN'),'String',num2str(LoadData.datai));
set(findobj('Tag','EData_OT'),'String',num2str(LoadData.datao));
set(gcf,'userdata',LoadData);

str1=sprintf('>> [name,path]=uigetfile(''*.mat'',''Load data set'');\n>> pathname=strcat(path,name);');
str2=sprintf('\n>> targT=load(''-mat'',pathname);');
str=strcat(str1,str2);
set(findobj('Tag','edit6'),'String',str);

str1='uigetfile函数可以打开文件对话框,返回所选文件的文件名和路径。然后用load函数就可以获得目标文件的内容。';
str2='由于输出向量是4*4的,为了便于比较,不同的行用不同的颜色来表示。具体的绘制过程没有显示出来。';
str=strcat(str1,str2);
set(findobj('Tag','edit5'),'String',str);

function EData_IN_Callback(hObject, eventdata, handles)
% hObject    handle to EData_IN (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 EData_IN as text
%        str2double(get(hObject,'String')) returns contents of EData_IN as a double


% --- Executes during object creation, after setting all properties.
function EData_IN_CreateFcn(hObject, eventdata, handles)
% hObject    handle to EData_IN (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



function EData_OT_Callback(hObject, eventdata, handles)
% hObject    handle to EData_OT (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 EData_OT as text
%        str2double(get(hObject,'String')) returns contents of EData_OT as a double


% --- Executes during object creation, after setting all properties.
function EData_OT_CreateFcn(hObject, eventdata, handles)
% hObject    handle to EData_OT (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 pb_Train.
function pb_Train_Callback(hObject, eventdata, handles)
% hObject    handle to pb_Train (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(gcf,'userdata');
net=newlin(minmax(user_data.datai),4,0,0.01);
net=init(net);
net.trainParam.epochs=user_data.epochs;
net.trainParam.goal=user_data.goal;
net=train(net,user_data.datai,user_data.datao);
y=sim(net,user_data.datai);
error=user_data.datao-y;
x=1:1:length(y);
hold on;
plot(findobj('Tag','axes1'),x,y(1,:),'r*');
hold on;
plot(findobj('Tag','axes1'),x,y(2,:),'b*');
hold on;
plot(findobj('Tag','axes1'),x,y(3,:),'m*');
hold on;
plot(findobj('Tag','axes1'),x,y(4,:),'c*')
for i=1:4
    error(i)=norm(error(:,i));
end;
user_data.err=error;
set(findobj('Tag','figure1'),'userdata',user_data);

str1=sprintf('>> net=newlin(minmax(P),4,0,0.01);\n>> net=init(net);\n>> net.trainParam.epochs=2000;');
str2=sprintf('\n>> net.trainParam.goal=0.0001;\n>> net=train(net,P,T);\n>> y=sim(net,user_data.datai);');
str=strcat(str1,str2);
set(findobj('Tag','edit6'),'String',str);

str1='P为输入向量,T为输出向量。通过newlin函数建立了一个新的线性神经网络,然后利用init函数将其初始化。通过'
str2='train函数训练网络之后,用sim函数对训练样本仿真。在绘图区绘制了仿真后的结果,用*表示,可以和T值对比观察.';
str=strcat(str1,str2);
set(findobj('Tag','edit5'),'String',str);

function E_Epochs_Callback(hObject, eventdata, handles)
% hObject    handle to E_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 E_Epochs as text
%        str2double(get(hObject,'String')) returns contents of E_Epochs as a double

user_data=get(gcf,'userdata');
user_data.epochs=str2double(get(hObject,'String'));
set(gcf,'userdata',user_data);

% --- Executes during object creation, after setting all properties.
function E_Epochs_CreateFcn(hObject, eventdata, handles)
% hObject    handle to E_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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
user_data=get(findobj('Tag','figure1'),'userdata');
temp=get(hObject,'String');
user_data.epochs=str2double(temp);
set(findobj('Tag','figure1'),'userdata',user_data);


function E_Goal_Callback(hObject, eventdata, handles)
% hObject    handle to E_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 E_Goal as text
%        str2double(get(hObject,'String')) returns contents of E_Goal as a double

user_data=get(gcf,'userdata');
user_data.goal=str2double(get(hObject,'String'));
set(gcf,'userdata',user_data);

% --- Executes during object creation, after setting all properties.
function E_Goal_CreateFcn(hObject, eventdata, handles)
% hObject    handle to E_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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
user_data=get(gcf,'userdata');
user_data.goal=str2double(get(hObject,'String'));
set(gcf,'userdata',user_data);

% --- Executes on button press in pb_exit.
function pb_exit_Callback(hObject, eventdata, handles)
% hObject    handle to pb_exit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

close;
SysGui;


% --- Executes on button press in pb_Char.
function pb_Char_Callback(hObject, eventdata, handles)
% hObject    handle to pb_Char (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --- Executes on button press in pb_CError.
function pb_CError_Callback(hObject, eventdata, handles)
% hObject    handle to pb_CError (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(gcf,'userdata');
title('误差曲线');
x=1:length(user_data.err);
hold off;
plot(x,user_data.err);

str=sprintf('>> error=y-T\n>> for i=1:4\n>>   error(i)=norm(error(:,i));\n>> end;\n>> x=1:length(error);\n>> hold off;\n>> plot(x,user_data.err);');
set(findobj('Tag','edit6'),'String',str);

str='从仿真结果和目标向量计算出误差,并由此画出误差曲线';
set(findobj('Tag','edit5'),'String',str);

% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes1
axis([0 5 0 5]);
grid on;





function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (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 edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (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


⌨️ 快捷键说明

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