📄 em_gui.m
字号:
function varargout = EM_gui(varargin)% EM_GUI Application M-file for EM_gui.fig% FIG = EM_GUI launch EM_gui GUI.% EM_GUI('callback_name', ...) invoke the named callback.% Last Modified by GUIDE v2.5 13-Feb-2005 19:28:34if nargin == 0 % LAUNCH GUI clc; fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); handles.fun_types = {'Gam' 'InvGauss' 'LogNorm'}; set(handles.popupmenu_mod_type,'String',handles.fun_types); handles.n_mix = 1; set(handles.edit_n_mix,'String',handles.n_mix); set(handles.popupmenu_mod_num,'String', 'Module1'); handles.mod_type = {handles.fun_types(1)}; set(handles.popupmenu_mod_type,'Value',1); handles.mod_type = handles.fun_types(1); handles.removable = []; handles.isi_R = []; handles.EM_exflag = 0; handles.EM_opts.MAXIT = 1000; handles.EM_opts.PERCSTOP = 1e-6; handles.EM_opts.DOPLOT = 0; handles.EM_opts.DISP_STEPS = 0; handles.figs = [fig]; guidata(fig, handles); if nargout > 0 varargout{1} = fig; endelseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try if (nargout) [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard else feval(varargin{:}); % FEVAL switchyard end catch disp(lasterr); endend% --------------------------------------------------------------------function varargout = pushbutton_Start_Callback(h, eventdata, handles, varargin) if ~isempty(handles.isi_R) handles.rnd_state = 2; rand('state', handles.rnd_state); randn('state', handles.rnd_state + 1); curr_fig = figure; handles.figs = [handles.figs curr_fig]; plot(handles.EM_opts.FIG_BIN_CTRS(1:end-1), handles.f_exp); drawnow;box off;set(gca,'TickDir','out'); [handles.init_pars, handles.init_weights, clust_pars, clust_flag] = ... EM_Initialize(handles.isi_R, handles.mod_type, curr_fig); if clust_flag>0 handles.EM_opts.USECENS = 0; if isfinite(handles.T_cens) & ... ((get(handles.checkbox_usecensoring,'Value') == get(handles.checkbox_usecensoring,'Max'))) handles.EM_opts.USECENS = 1; end [handles.final_weights, handles.final_pars, handles.EM_exflag] = ... EM_algorithm(handles.isi_R, handles.isi_T, ... handles.mod_type, handles.init_pars, handles.init_weights, handles.EM_opts, curr_fig); % guidata(h, handles); else disp('KMEANS could not initialize parameters. Try again or reduce number of components.'); end guidata(h, handles); end% --------------------------------------------------------------------function varargout = edit_n_mix_Callback(h, eventdata, handles, varargin)value = str2double(get(h,'string')); if value>=1 handles.n_mix = round(value); set(h,'String', handles.n_mix); lista_mod_num = cell(handles.n_mix,1); handles.mod_type = cell(handles.n_mix,1); for ii =1:handles.n_mix lista_mod_num{ii} = strcat('Module ',num2str(ii)); handles.mod_type{ii} = 'Gam'; end set(handles.popupmenu_mod_num,'String', lista_mod_num); set(handles.popupmenu_mod_num,'Value', 1); set(handles.popupmenu_mod_type,'Value', 1); else set(h,'String', handles.n_mix); end guidata(h, handles); % --------------------------------------------------------------------function varargout = popupmenu_mod_num_Callback(h, eventdata, handles, varargin)index_selected = get(h,'Value');current_type = handles.mod_type{index_selected};I = strmatch(current_type, handles.fun_types, 'exact');set(handles.popupmenu_mod_type, 'Value', I); guidata(h, handles); % --------------------------------------------------------------------function varargout = popupmenu_mod_type_Callback(h, eventdata, handles, varargin)current_module = get(handles.popupmenu_mod_num,'Value');index_selected = get(h,'Value');handles.mod_type(current_module) = handles.fun_types(index_selected);guidata(h, handles); % --------------------------------------------------------------------function varargout = pushbutton_KStest_Callback(h, eventdata, handles, varargin)if handles.EM_exflag>0 kstest_fig_hnd = figure; handles.figs = [handles.figs kstest_fig_hnd]; [H_KS, P, KSSTAT] = EM_KStest(handles.isi_R, handles.mod_type, ... handles.final_weights, handles.final_pars, handles.rnd_state, kstest_fig_hnd); guidata(h, handles); end% --------------------------------------------------------------------function varargout = checkbox_usecensoring_Callback(h, eventdata, handles, varargin)% --------------------------------------------------------------------function File_menu_Callback(hObject, eventdata, handles)% hObject handle to Untitled_1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function Load_dataset_menu_Callback(h, eventdata, handles, varargin)% hObject handle to Untitled_2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)[dataset_filename, dataset_pathname] = uigetfile( {'*.mat;*.dat;*.txt'}, 'Pick a data file'); if dataset_filename~=0 handles.full_filename = strcat(dataset_pathname, dataset_filename); [handles.isi_R, handles.isi_T, handles.T_cens] = EM_load(handles.full_filename); set(handles.text_T_cens,'String', handles.T_cens); handles.figs = [handles.figs figure]; N_R = length(handles.isi_R); handles.EM_opts.FIG_BIN_SIZE = 1; edges = eps:handles.EM_opts.FIG_BIN_SIZE:max(handles.isi_R); [freq, handles.EM_opts.FIG_BIN_CTRS] = hist(handles.isi_R, edges); handles.EM_opts.FIG_NBINS = length(handles.EM_opts.FIG_BIN_CTRS); h_real = plot(handles.EM_opts.FIG_BIN_CTRS(1:end-1), freq(1:end-1)/N_R); handles.EM_opts.FIG_YMAX = 1.2*max(freq(1:end-1)/N_R); drawnow;box off;set(gca,'TickDir','out'); handles.f_exp = freq(1:end-1)/N_R; handles.EM_exflag = 0; guidata(h, handles); end% --------------------------------------------------------------------function Save_results_menu_Callback(h, eventdata, handles, varargin)% hObject handle to Untitled_2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)if handles.EM_exflag>0 results.full_filename = handles.full_filename; results.mix_model = handles.mod_type; results.init_weights = handles.init_weights; results.init_pars = handles.init_pars; results.final_weights = handles.final_weights; results.final_pars = handles.final_pars; results.used_censoring_correction = handles.EM_opts.USECENS; [results_filename, results_pathname] = uiputfile( {'*.mat'}, 'Save results as'); if results_filename~=0 full_results_filename = strcat(results_pathname,results_filename); save(full_results_filename,'results'); end end%----------------------------------------------------------function Exit_menu_Callback(h, eventdata, handles, varargin)button = questdlg('Ready to quit?', ... 'Exit Dialog','Yes','No','No');switch button case 'Yes', open_figs = handles.figs(ishandle(handles.figs)); close(open_figs); case 'No', quit cancel;end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -