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

📄 identga.m

📁 基于GA(遗传算法)的ARX模型参数辨识
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = identga(varargin)
%
% Author: Wesam ELSHAMY
% wesamelshamy@ieee.org
% Electrical Engineering Dept., Cairo University, Egypt


% IDENTGA M-file for identga.fig
%      IDENTGA, by itself, creates a new IDENTGA or raises the existing
%      singleton*.
%
%      H = IDENTGA returns the handle to a new IDENTGA or the handle to
%      the existing singleton*.
%
%      IDENTGA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IDENTGA.M with the given input arguments.
%
%      IDENTGA('Property','Value',...) creates a new IDENTGA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before identga_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to identga_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 text27 to modify the response to help identga

% Last Modified by GUIDE v2.5 16-Apr-2006 13:51:47

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

% Choose default command line output for identga
handles.output = hObject;
handles.error_tolerance = 0.4;
handles.population_size = 100;
handles.mutation_rate = 0.9;
handles.no_of_generations = 100;
sisodata;
% Update handles structure
guidata(hObject, handles);

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


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

% ----- Get parameters from GUI -----
if get(handles.estimate, 'value') == get(handles.estimate, 'max');
% try
o = evalin('base', get(handles.out, 'string'));
i = evalin('base', get(handles.in, 'string'));
na = str2double(get(handles.Na,'string'));
nb = str2double(get(handles.Nb,'string'));
nk = str2double(get(handles.Nk,'string'));
handles.real_output = o;
guidata(hObject, handles);

% ----- Estimate the model using GA and view parameters in GUI -----
[A_parameters_GA B_parameters_GA] = arx2(o, i, na, nb, nk, handles.error_tolerance, handles.population_size, handles.mutation_rate, handles.no_of_generations); % model evaluation using GA
delay_zeros = zeros(1, nk);
set(handles.Aga, 'string', num2str([1 A_parameters_GA])); 
set(handles.Bga, 'string', num2str([delay_zeros B_parameters_GA])); 
GA_model = idpoly([1 A_parameters_GA], [delay_zeros B_parameters_GA]);
handles.GA_model_output = sim(GA_model, i); % simulating the GA model output
guidata(hObject, handles);

% ----- Estimate the model using Least Square and vew parameter in GUI -----
least_model = arx(iddata(o, i), [na nb nk]); % model evaluatin using Least Square
set(handles.Aleast, 'string', num2str(least_model.a));
set(handles.Bleast, 'string', num2str(least_model.b));
handles.least_model_output = sim(least_model, i); % simulating the Least Square model output
guidata(hObject, handles);

% ----- Evaluate the models errors -----
set(handles.GA_error, 'string', num2str(modelerror([1 A_parameters_GA], [delay_zeros B_parameters_GA])));
set(handles.Least_error, 'string', num2str(modelerror(least_model.a, least_model.b)));

plot_output(handles);
set(handles.estimate, 'value', get(handles.estimate, 'min'));
% catch
%     errordlg('Not enough data: Enter model orders and I/O data then hit Estimate','Data missing','on');
% end
end

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


% --- Executes during object creation, after setting all properties.
function Nb_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Nb (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 Nk_Callback(hObject, eventdata, handles)
% hObject    handle to Nk (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 Nk as text27
%        str2double(get(hObject,'String')) returns contents of Nk as a double


% --- Executes during object creation, after setting all properties.
function Nk_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Nk (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 out_Callback(hObject, eventdata, handles)
% hObject    handle to out (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 out as text27
%        str2double(get(hObject,'String')) returns contents of out as a double


% --- Executes during object creation, after setting all properties.
function out_CreateFcn(hObject, eventdata, handles)
% hObject    handle to out (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 Na_Callback(hObject, eventdata, handles)
% hObject    handle to Na (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 Na as text27
%        str2double(get(hObject,'String')) returns contents of Na as a double


% --- Executes during object creation, after setting all properties.
function Na_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Na (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 Aga_Callback(hObject, eventdata, handles)
% hObject    handle to Aga (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 Aga as text27
%        str2double(get(hObject,'String')) returns contents of Aga as a double


% --- Executes during object creation, after setting all properties.
function Aga_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Aga (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 Bga_Callback(hObject, eventdata, handles)
% hObject    handle to Bga (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 Bga as text27
%        str2double(get(hObject,'String')) returns contents of Bga as a double


% --- Executes during object creation, after setting all properties.
function Bga_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Bga (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 in_Callback(hObject, eventdata, handles)
% hObject    handle to in (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

⌨️ 快捷键说明

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