📄 create_da_model.m
字号:
function varargout = create_da_model(varargin)
% CREATE_DA_MODEL create model for modified discriminant analysis
% Batch mode using: DaModel=create_da_model(X,'auto',first_win_length,second_win_length,df);
% GUI-mode using: DaModel=create_da_model(X,'manual',first_win_length,second_win_length,df);
% Parameters not needed to be specified.
%
% first_win_length,second_win_length - length of time intervals, measured
% in sample points;
% df - discriminant function
% X - vector of time series
% mode - 'manual' (GUI) or 'auto' (no-GUI)
% example: DaModelInfo=create_da_model(X,'auto',30,30,'c1*x1+c3*x3+c22*x2^2');
%
% Last Modified by GUIDE v2.5 18-Sep-2003 21:02:02
% last modified 4.02.05
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @create_da_model_OpeningFcn, ...
'gui_OutputFcn', @create_da_model_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 create_da_model is made visible.
function create_da_model_OpeningFcn(hObject, eventdata, handles, varargin)
% hObject handle to figure
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to create_da_model (see VARARGIN)
% Choose default command line output for create_da_model
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes create_da_model wait for user response (see UIRESUME)
% uiwait(handles.create_da_model);
global cdamGLOBALS
if isempty(varargin)
error('Not enougth input parameters');
else
if isa(varargin{1},'struct')
cdamGLOBALS.x=varargin{1};
else
cdamGLOBALS.x.data=varargin{1};
[x,y]=size(varargin{1});
for i=1:y
cdamGLOBALS.x.name{i}=['crd_' num2str(i)];
end
cdamGLOBALS.x.time=(1:x)';
end
end
if length(varargin)<2
cdamGLOBALS.mode='manual';
else
cdamGLOBALS.mode=varargin{2};
end
if length(varargin)<3
cdamGLOBALS.win1=10;
else
cdamGLOBALS.win1=varargin{3};
end
if length(varargin)<4
cdamGLOBALS.win2=10;
else
cdamGLOBALS.win2=varargin{4};
end
if length(varargin)<5
cdamGLOBALS.df='';
else
cdamGLOBALS.df=varargin{5};
end
plot(cdamGLOBALS.x.time,cdamGLOBALS.x.data(:,1));
show_lin_model(handles);
handles.line1_x_d=[];
handles.line1_x_u=[];
handles.line1_y_l=[];
handles.line1_y_r=[];
handles.line2_x_d=[];
handles.line2_x_u=[];
handles.line2_y_l=[];
handles.line2_y_r=[];
guidata(hObject, handles);
draw_windows(cdamGLOBALS.win1,cdamGLOBALS.win2,cdamGLOBALS.win1,cdamGLOBALS.x.time,handles);
set(handles.edit_win1_len,'string',num2str(cdamGLOBALS.win1));
set(handles.edit_win2_len,'string',num2str(cdamGLOBALS.win2));
STR=[];
STR_listbox=[];
for i=1:length(cdamGLOBALS.x.name)
STR=[STR '|' cdamGLOBALS.x.name{i}];
STR_listbox{i}=['''x' num2str(i) ''' is ' cdamGLOBALS.x.name{i}];
end
set(handles.popup_menu,'string',STR);
set(handles.listbox,'string',STR_listbox)
if ~isempty(cdamGLOBALS.df)
set(handles.edit_df,'string',cdamGLOBALS.df);
end
% --- Outputs from this function are returned to the command line.
function varargout = create_da_model_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
global cdamGLOBALS
if strcmp(cdamGLOBALS.mode,'auto')
compute_button_Callback(handles.compute_button, [], handles);
varargout{1} =cdamGLOBALS.modelinfo;
else
uiwait;
try
varargout{1} =cdamGLOBALS.modelinfo;
catch
end
end
try
close(handles.create_da_model);
catch
end
% --- Executes during object creation, after setting all properties.
function edit_win1_len_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_win1_len (see GCBO)
% 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 edit_win_len_Callback(hObject, eventdata, handles)
% hObject handle to edit_win1_len (see GCBO)
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_win1_len as text
% str2double(get(hObject,'String')) returns contents of edit_win1_len as a double
global cdamGLOBALS
win1=str2num(get(handles.edit_win1_len,'string'));
win2=str2num(get(handles.edit_win2_len,'string'));
if (win1+win2)<=length(cdamGLOBALS.x.data(:,1));
draw_windows(win1,win2,win1,cdamGLOBALS.x.time,handles);
else
h=errordlg('Summary windows length too long','Error');
set(h,'windowstyle','modal');
waitfor(h);
win=2;
set([handles.edit_win1_len handles.edit_win2_len],'string',num2str(win));
draw_windows(win,win,win,cdamGLOBALS.x.time,handles);
end
% --- Executes during object creation, after setting all properties.
function edit_win2_len_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_win2_len (see GCBO)
% handles empty - handles not created until after all CreateFcns called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in lin_model_button.
function lin_model_button_Callback(hObject, eventdata, handles)
% hObject handle to lin_model_button (see GCBO)
set(hObject,'value',1);
set([handles.quadric_model_button handles.cubic_model_button],'value',0);
show_lin_model(handles);
% --- Executes on button press in quadric_model_button.
function quadric_model_button_Callback(hObject, eventdata, handles)
% hObject handle to quadric_model_button (see GCBO)
set(hObject,'value',1);
set([handles.lin_model_button handles.cubic_model_button],'value',0);
show_quadric_model(handles);
% --- Executes on button press in cubic_model_button.
function cubic_model_button_Callback(hObject, eventdata, handles)
% hObject handle to cubic_model_button (see GCBO)
set(hObject,'value',1);
set([handles.quadric_model_button handles.lin_model_button],'value',0);
show_cubic_model(handles);
% --- Executes during object creation, after setting all properties.
function edit_df_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_df (see GCBO)
% handles empty - handles not created until after all CreateFcns called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit_df_Callback(hObject, eventdata, handles)
% hObject handle to edit_df (see GCBO)
% --- Executes on button press in close_button.
function close_button_Callback(hObject, eventdata, handles)
% hObject handle to close_button (see GCBO)
close(handles.create_da_model);
% --- Executes on button press in compute_button.
function compute_button_Callback(hObject, eventdata, handles)
% hObject handle to compute_button (see GCBO)
global cdamGLOBALS
modelinfo.df=get(handles.edit_df,'string');
modelinfo.win1=str2num(get(handles.edit_win1_len,'string'));
modelinfo.win2=str2num(get(handles.edit_win2_len,'string'));
[coeff_names,funcs]=da_df_parser(modelinfo.df);
modelinfo.coeffs=coeff_names;
modelinfo.funcs=funcs;
modelinfo.X=cdamGLOBALS.x;
modelinfo.mode=cdamGLOBALS.mode;
da=da_algorithm(modelinfo);
cdamGLOBALS.modelinfo=da;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function str=show_lin_model(handles);
global cdamGLOBALS
crdNo=length(cdamGLOBALS.x.name);
str=[];
for i=1:crdNo
if isempty(str)
str=[str sprintf('c%d*x%d',i,i)];
else
str=[str '+' sprintf('c%d*x%d',i,i)];
end
end
set(handles.edit_df,'string',str);
set(handles.popup_menu,'value',1);
function str=show_quadric_model(handles);
global cdamGLOBALS
str=show_lin_model(handles);
crdNo=length(cdamGLOBALS.x.name);
for i=1:crdNo
str=[str '+' sprintf('c%d%d*x%d^2',i,i,i)];
end
for i=1:crdNo
for j=i+1:crdNo
str=[str '+' sprintf('c%d%d*x%d*x%d',i,j,i,j)];
end
end
set(handles.edit_df,'string',str);
set(handles.popup_menu,'value',1);
function show_cubic_model(handles);
global cdamGLOBALS
str=show_quadric_model(handles);
crdNo=length(cdamGLOBALS.x.name);
for i=1:crdNo
str=[str '+' sprintf('c%d%d%d*x%d^3',i,i,i,i)];
end
for i=1:crdNo
for j=1:crdNo
if i~=j
str=[str '+' sprintf('c%d%d%d*x%d^2*x%d',i,i,j,i,j)];
end
end
end
for i=1:crdNo
for j=i+1:crdNo
for k=j+1:crdNo
str=[str '+' sprintf('c%d%d%d*x%d*x%d*x%d',i,j,k,i,j,k)];
end
end
end
set(handles.edit_df,'string',str);
set(handles.popup_menu,'value',1);
function draw_windows(win1,win2,common_point,X,handles);
delete([handles.line1_x_d; handles.line1_x_u; handles.line1_y_l; handles.line1_y_r;...
handles.line2_x_d; handles.line2_x_u; handles.line2_y_l; handles.line2_y_r;]);
line1_x=[X(common_point-win1+1) X(common_point)];
line2_x=[X(common_point+1) X(common_point+win2)];
Ylim=get(handles.axes,'ylim');
handles.line1_x_d=line(line1_x,Ylim(1)*ones(2,1),'Color','r','LineWidth',2);
handles.line1_x_u=line(line1_x,Ylim(2)*ones(2,1),'Color','r','LineWidth',2);
handles.line1_y_l=line([line1_x(1) line1_x(1)],Ylim,'Color','r','LineWidth',2);
handles.line1_y_r=line([line1_x(2) line1_x(2)],Ylim,'Color','r','LineWidth',2);
handles.line2_x_d=line(line2_x,Ylim(1)*ones(2,1),'Color','r','LineWidth',2);
handles.line2_x_u=line(line2_x,Ylim(2)*ones(2,1),'Color','r','LineWidth',2);
handles.line2_y_l=line([line2_x(1) line2_x(1)],Ylim,'Color','r','LineWidth',2);
handles.line2_y_r=line([line2_x(2) line2_x(2)],Ylim,'Color','r','LineWidth',2);
guidata(handles.create_da_model,handles);
% --- Executes during object creation, after setting all properties.
function popup_menu_CreateFcn(hObject, eventdata, handles)
% hObject handle to popup_menu (see GCBO)
% 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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in popup_menu.
function popup_menu_Callback(hObject, eventdata, handles)
% hObject handle to popup_menu (see GCBO)
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popup_menu contents as cell array
% contents{get(hObject,'Value')} returns selected item from popup_menu
selection=get(hObject,'Value');
if selection==1
return
end
Unique_crd_num=selection-1;
S=['x' num2str(Unique_crd_num)];
[coeff_names,funcs]=da_df_parser(get(handles.edit_df,'string'));
L=length(funcs);
for i=L:-1:1
str=funcs{i};
Ix=regexp(str,[S '\W']);
Ix2=regexp(str,['\W' S]);
if (isempty(Ix))&(isempty(Ix2))
continue
end
funcs{i}=[];
coeff_names{i}=[];
end
df=[];
for i=1:L
if ~isempty(funcs{i})
df=[df coeff_names{i} '*' kill_points(funcs{i}) '+'];
end
end
df=df(1:end-1);
set(handles.edit_df,'string',df);
function s=kill_points(str);
s=[];
for i=1:length(str)
if (str(i)=='.')
if isempty(str2num(str(i-1)))|isempty(str2num(str(i+1)))
continue
end
end
s=[s str(i)];
end
% --- Executes during object creation, after setting all properties.
function listbox_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox (see GCBO)
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 selection change in listbox.
function listbox_Callback(hObject, eventdata, handles)
% hObject handle to listbox (see GCBO)
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns listbox contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -