guif.m

来自「神经网络的工具箱, 神经网络的工具箱,」· M 代码 · 共 2,017 行 · 第 1/4 页

M
2,017
字号
function guif(cmd)%GUIF Netpack GUI Callbacks.if (nargin == 0)   cmd = 'init';end%==================================================================% Initialize%% GUIF('init')%==================================================================if strcmp(cmd, 'init')fig = graphics_snn('init');stdout_in.string = {''};auf(fig, 'stdout', stdout_in); welcome.next.enable = 'off';auf(fig, 'welcome', welcome);import.filename = '';import.inputstext.enable = 'off';import.inputsedit.string = '';import.inputsedit.enable = 'off';import.outputstext.enable = 'off';import.outputsedit.string = '';import.outputsedit.enable = 'off';import.weights.value = 0;import.weights.enable = 'off';import.next.enable = 'off';import.ok.enable = 'off';auf(fig, 'import', import);scaling.pop.value = 1; auf(fig, 'scaling', scaling);arch.nlayers = 1;arch.nunits = [1];%arch.transferfunctions = ...%                    { 'purelin'; ...%                      'tansig'; ...%		      'hardlim'; ...%		      'hardlims'; ...%		      'logsig'; ...%		      'poslin'; ...%		      'radbas'; ...%		      'satlin'; ...%		      'satlins'; ...%		      'tribas'; ...%		      'exptf_snn' };arch.transferfunctions = ...                    { 'lintf_snn'; ...		      'tansigtf_snn';		      'exptf_snn'; ...		      'logsigtf_snn'; ...		      'radbastf_snn' }; arch.transfervalues = [2 1];arch.ok.enable = 'on';arch.next.enable = 'off';auf(fig, 'arch', arch);parameters.outputpop.value = 1; parameters.errorfunctions = ...                   { 'se_snn'; ...		     'relerr_snn'; ...		     'loglikelihood_snn'; ...		     'crossentropy_snn'; ...		     'crosslogistic_snn'};parameters.algorithms = ...                    { 'trainlm_snn'; ...		      'traincgp_snn'; ...		      'traingd_snn'};parameters.algvalue = 1;parameters.mumax = 1e10;parameters.muinc = 10;parameters.mudec = 0.1;parameters.tol = 1e-7;parameters.lr = 0.001;parameters.epochs = 1000;parameters.sucfail = 10;parameters.totfail = 20;parameters.time = inf;parameters.next.enable = 'off';auf(fig, 'parameters', parameters);ensemble.nensemble = 1;ensemble.next.enable = 'off';ensemble.samplemethod = ...                   { 'train_bootstrap_snn'; ...		     'train_halfout_snn' };ensemble.samplevalue = 1;ensemble.ok.enable = 'off';ensemble.next.enable = 'off';auf(fig, 'ensemble', ensemble);remove.next.enable = 'off';auf(fig, 'remove', remove);average.methodpoptext = {'Balancing';'Bagging';'Bumping';'Cranking'};average.method = [1];   % 1 = balancing, 2 = bagging, 3 = bumping, 4 = crankingaverage.bootn = 10;average.cranks = 1;auf(fig, 'average', average);intervals.elevel = 0.32;intervals.ok.enable = 'off';intervals.next.enable = 'off';auf(fig, 'intervals', intervals);prediction.ok.enable = 'off';prediction.next.enable = 'off';auf(fig, 'prediction', prediction);relevance.ok.enable = 'off';relevance.next.enable = 'off';auf(fig, 'relevance', relevance);graphics_snn('welcome');%==================================================================% New %% GUIF('new')%==================================================================elseif strcmp(cmd, 'new')guif('init');%==================================================================% Save %% GUIF('save')%==================================================================elseif strcmp(cmd, 'save')filename = get(gcbf, 'FileName');if filename   hgsave(gcbf, filename);   set(gcbf, 'name', ['NetPack - ' filename] , 'numbertitle', 'off');else   guif('saveas');end%==================================================================% Save as%% GUIF('saveas')%==================================================================elseif strcmp(cmd, 'saveas')filename = get(gcbf, 'FileName');if filename   [filename, pathname] = uiputfile(filename, 'Save As');else   [filename, pathname] = uiputfile('*.snn', 'Save As');endif filename   if isempty(find(filename == '.'))      filename = [filename '.snn'];   end   filename = [pathname filename];   set(gcbf, 'FileName', filename);   hgsave(gcbf, filename);   set(gcbf, 'name', ['SNN - ' filename] , 'numbertitle', 'off');end%==================================================================% Load %% GUIF('load')%==================================================================elseif strcmp(cmd, 'load')fig = gcbf;[filename, pathname] = uigetfile('*.snn', 'Load training session'); if filename                                                 filename = [pathname filename];   load_session_snn(filename, fig);   graphics_snn(getfield(get(fig, 'UserData'), 'screen'));end%==================================================================% Extract %% GUIF('extract')%==================================================================elseif strcmp(cmd, 'extract')new_figure = figure;old_axis = get(gcbf, 'CurrentAxes');new_axis = copyobj(old_axis, new_figure);set(new_axis, 'Units', 'normal');set(new_axis, 'Position', [0.13 0.11 0.775 0.8150]);%==================================================================% Close %% GUIF('close')%==================================================================elseif strcmp(cmd, 'close')Hall = findobj(gcbf);delete(Hall);%==================================================================% Help %% GUIF('help')%==================================================================elseif strcmp(cmd, 'help')popup_message_snn('Sorry, no help available.');%==================================================================%==================================================================% WELCOME_OK %% GUIF('wc_ok')%==================================================================elseif strcmp(cmd, 'wc_ok')au('welcome.next.enable', 'on');graphics_snn('import');%==================================================================% WELCOME_HELP %% GUIF('wc_help')%==================================================================elseif strcmp(cmd, 'wc_help')popup_message_snn('Sorry, no help available.');%==================================================================% WELCOME_NEXT %% GUIF('wc_next')%==================================================================elseif strcmp(cmd, 'wc_next')guif('wc_ok');%==================================================================%==================================================================% IMPORT_EDIT1 %% GUIF('import_edit1')%==================================================================elseif strcmp(cmd, 'import_edit1')filename = get(gcbo, 'String');au('import.filename', filename);stdout_snn('Loading file...');[readdata, err, msg] = read_data_snn(filename);if (err)    stdout_snn(msg);end;if (err < 1)   [MU, MN] = size(readdata);   au('readdata', readdata);   au('scale', cell(MN, 1));   au('MU', MU);   au('MN', MN);   au('import.inputstext.enable',  'on' , ...      'import.inputsedit.enable',  'on' , ...      'import.outputstext.enable', 'on' , ...      'import.outputsedit.enable', 'on' , ...      'import.weights.enable',     'on' , ...      'import.ok.enable',          'on' , ...      'import.next.enable',        'off');   graphics_snn('import');   stdout_snn('Loaded file %s containing %d patterns with %d values.\n', filename, MU, MN);end%==================================================================% IMPORT_BROWSE %% GUIF('import_browse')%==================================================================elseif strcmp(cmd, 'import_browse')[filename, pathname] = uigetfile('*.asc', 'Select training datafile'); drawnow;if (filename ~= 0)                                                 if (~strcmp(pathname, pwd))                                            filename = [pathname filename];   end   au('import.filename', filename);    stdout_snn('Loading file...');   [readdata, err, msg] = read_data_snn(filename);   if (err)        stdout_snn(msg);   end;   if (err < 1)      [MU, MN] = size(readdata);      au('readdata', readdata);      au('scale', cell(MN, 1));      au('MU', MU);      au('MN', MN);      au('import.inputstext.enable',  'on' , ...         'import.inputsedit.enable',  'on' , ...         'import.outputstext.enable', 'on' , ...         'import.outputsedit.enable', 'on' , ...         'import.weights.enable',     'on' , ...         'import.ok.enable',          'on' , ...         'import.next.enable',        'off');      graphics_snn('import');      stdout_snn('Loaded file %s containing %d patterns with %d values.\n', filename, MU, MN);   end   graphics_snn('import');end%==================================================================% IMPORT_INPUTSEDIT %% GUIF('import_inputsedit')%==================================================================elseif strcmp(cmd, 'import_inputsedit')inputsstring = get(gcbo, 'String');inputs = str2num(inputsstring);inputnames = cell(inputs, 1);for i = 1:inputs    inputnames{i} = ['input ' num2str(i)];endau('arch.inputnames', inputnames);au('import.inputsedit.string', inputsstring);%==================================================================% IMPORT_OUTPUTSEDIT %% GUIF('import_outputsedit')%==================================================================elseif strcmp(cmd, 'import_outputsedit')outputsstring = get(gcbo, 'String');outputs = str2num(outputsstring);outputnames = cell(outputs, 1);errorpop.values = zeros(outputs, 1);errorweight = zeros(outputs, 1);for i = 1:outputs    outputnames{i} = ['output ' num2str(i)];    errorpop.values(i) = 1;    errorweight(i) = 1;endau('arch.outputnames', outputnames);au('import.outputsedit.string', outputsstring);au('parameters.errorpop', errorpop);au('parameters.errorweight', errorweight);%==================================================================% IMPORT_CHECK %% GUIF('import_check')%==================================================================elseif strcmp(cmd, 'import_check')au('import.weights.value', get(gcbo, 'Value'));%==================================================================% IMPORT_OK %% GUIF('import_ok')%==================================================================elseif strcmp(cmd, 'import_ok')import = gu('import'); inputs = str2num(import.inputsedit.string);outputs = str2num(import.outputsedit.string);weight = import.weights.value;values = inputs + outputs + weight;MN = gu('MN');if (values > MN)   if (weight)     stdout_snn('ERROR: #inputs + #outputs + 1 > #values in datafile\n')   else     stdout_snn('ERROR: #inputs + #outputs > #values in datafile\n')   end   graphics_snn('import');else   if (values < MN)      stdout_snn('WARNING: not all values in datafile are used\n');   end   au('import.next.enable', 'on');   readdata = gu('readdata');   data.P = readdata(:, 1:inputs)';   data.T = readdata(:, (inputs+1):(inputs+outputs))';   if (weight)      data.gmu = readdata(:,(inputs+outputs+1))';   end   if find(isnan(data.T))      data.useT = ones(size(data.T));      data.useT(find(isnan(data.T))) = 0;   end   au('data', data);   analysis = analyze_data_snn(readdata(:, 1:inputs)');   au('analysis', analysis);   ninputs = size(data.P,1);   Ppredict = zeros(ninputs,1);   k = 1;   while (k <= ninputs)       grsize = prod(size(analysis(k).group));        if (grsize > 1)	  if strcmp(analysis(k).type, 'continuous')  %cycles.             Ppredict(k) = 1;	     Ppredict(k+1) = 0;	     k = k + 2;	  else	     Ppredict(k) = analysis(k).max;	     for j = 1:(grsize-1)                 Ppredict(k+j) = analysis(k+j).min;             end	     k = k + grsize;	  end       else          Ppredict(k) = analysis(k).min;	  k = k + 1;       end   end   au('prediction.P', Ppredict);   au('scaling.next.enable', 'off');   graphics_snn('scaling');end%==================================================================% IMPORT_PREVIOUS %% GUIF('import_previous')%==================================================================elseif strcmp(cmd, 'import_previous')graphics_snn('welcome');%==================================================================% IMPORT_HELP %% GUIF('import_help')%==================================================================elseif strcmp(cmd, 'import_help')popup_message_snn('Sorry, no help available.');%==================================================================% IMPORT_NEXT %% GUIF('import_next')%==================================================================elseif strcmp(cmd, 'import_next')graphics_snn('scaling');%==================================================================% SCALING_POP %% GUIF('scaling_pop')%==================================================================elseif strcmp(cmd, 'scaling_pop')au('scaling.pop.value', get(gcbo, 'Value'));graphics_snn('scaling');%==================================================================% SCALING_MEANZERO %% GUIF('scaling_meanzero')%==================================================================elseif strcmp(cmd, 'scaling_meanzero')readdata = gu('readdata');no = gu('scaling.pop.value');scale = gu('scale');sc = scale{no};x = readdata(:, no);  if (isempty(sc))

⌨️ 快捷键说明

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