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

📄 anfisedit.m

📁 模糊逻辑工具箱 模糊逻辑工具箱 模糊逻辑工具箱 模糊逻辑工具箱 模糊逻辑工具箱
💻 M
📖 第 1 页 / 共 3 页
字号:
function anfisedit(action);
%ANFISEDIT anfis GUI tool.
%   The ANFIS Editor is used to create, train, and test a Sugeno fuzzy system. 
%
%   See also FUZZY, MFEDIT, RULEEDIT, RULEVIEW, SURFVIEW.

%   Kelly Liu, Dec. 96
%   Copyright (c) 1994-98 by The MathWorks, Inc.
%   $Revision: 1.21 $  $Date: 1997/12/02 22:15:53 $

if nargin<1,
   % Open up an untitled system.
   newFis=newfis('Untitled', 'sugeno');
   newFis=addvar(newFis,'input','input1',[0 1]);
   newFis=addvar(newFis,'output','output1',[0 1]);
   action=newFis;
end

if isstr(action),
   if action(1)~='#',
      % The string "action" is not a switch for this function, 
      % so it must be a disk file
      fis=readfis(action);
      if ~strcmp(fis.type, 'sugeno') | length(fis.output)>1
        disp('anfis editor only works on Sugeno systems with one output');
        return;
      else
       action='#initialize';
      end
   end
else
   % For initialization, the fis is passed in as the parameter
   fis=action;
   action='#initialize';
end;
%=======initialize anfisedit============
switch action
  case'#initialize',
    if isfield(fis, 'input')
      numInputs=length(fis.input);
    else
      numInputs=0;
    end

    if isfield(fis, 'output')
      numOutputs=length(fis.output);
    else
      numOutputs=0;
    end
    if isfield(fis, 'rule')
      numRules=length(fis.rule);
    else
      numRules=0;
    end
 
   for i=1:numInputs
      numInputMFs(i)=length(fis.input(i).mf);
   end
   totalInputMFs=sum(numInputMFs);
   fisnodenum=numInputs+2*totalInputMFs+2*numRules+2+1;
   infoStr=['Number of nodes: ' num2str(fisnodenum)];
   
   fisName=fis.name;
   nameStr=['Anfis Editor: ' fisName];
   savefis{1}=fis;
   figNumber=figure( ...
      'Name',nameStr, ...
      'Units', 'pixels', ...
      'Color', [.75 .75 .75],...
      'NumberTitle','off', ...
      'MenuBar','none', ...
      'Tag', 'anfisedit',...
      'Userdata', savefis,...
      'Visible','off');
  
   %======= create the menus standard to every GUI
   fisgui #initialize
   
   editHndl=findobj(figNumber,'Type','uimenu','Tag','editmenu');
   uimenu(editHndl,'Label','Undo', 'Tag', 'undo', 'Callback', 'popundo(gcf)',...
      'Enable','off');
   editHndl=findobj(figNumber,'Type','uimenu','Tag','openfis');
   set(editHndl,'Enable','off');
   editHndl=findobj(figNumber,'Type','uimenu','Tag','newmamdani');
   set(editHndl,'Enable','off');
   
   axes( ...
      'Units','normalized', ...
      'Position',[0.10 0.55 0.65 0.38]);
   
   %===================================    
   left=0.03;
   right=0.75;
   bottom=0.05;
   labelHt=0.03;
   spacing=0.005;
   frmBorder=0.012;
   %======Set up the anfis info Window==========
   top=0.5;    
   % First, the all the frames 
   frmPos=[0 0 1 .47];
   frmHandle=LocalBuildFrmTxt(frmPos, '', 'frame', 'mainfrm'); 
   frmPos=[.01 .115 .292 .34];
   frmHandle=LocalBuildFrmTxt(frmPos, '', 'frame', 'datafrm'); 
   midfrmwidth=.25;
   frmPos=[.315 .115 midfrmwidth .34];
   frmHandle=LocalBuildFrmTxt(frmPos, '', 'frame', 'midbtnfrm'); 
   frmPos=[.575 .115 .195 .34];
   frmHandle=LocalBuildFrmTxt(frmPos, '', 'frame', 'rightbtnfrm'); 
   frmPos=[.78 .115 .21 .34];
   frmHandle=LocalBuildFrmTxt(frmPos, '', 'frame', 'infofrm'); 
   frmPos=[.01 .0218 .62 .073];
   frmHandle=LocalBuildFrmTxt(frmPos, '', 'frame', 'statusfrm'); 
   frmPos=[.64 .0218 .35 .073];
   frmHandle=LocalBuildFrmTxt(frmPos, '', 'frame', 'statusfrm'); 

%======load data===============
   left=.02;
   labelPos=[.05+left .42 .15 .042];    
   lableHndl=LocalBuildFrmTxt(labelPos, '   Load data', 'text', 'lable2');
   width=.13;
   height=.04;
   left1=left+.14;
   width1=.13;
   height1=.04;
   labelPos=[left .38 .1 .042];    
   lableHndl=LocalBuildFrmTxt(labelPos, 'Type:', 'text', 'lable2');
   labelPos=[left1 .38 .1 .042];    
   lableHndl=LocalBuildFrmTxt(labelPos, 'From:', 'text', 'lable2');
   labelPos=[left .33 width height];    
   mcwPos=[left1 .30 width1 height1];
   lableHandle=LocalBuildUi(labelPos, 'radio', 'anfisedit #radioloadtype', 'Training', 'dattype');
   set(lableHandle, 'Max', 1, 'Value', 1);
   % Then the editable text field
   
   mcwHndl=LocalBuildUi(mcwPos, 'radio', 'anfisedit #radioloadfrom', 'disk', 'trndatin');
   set(mcwHndl, 'Max', 1, 'Value', 1);
   labelPos=[left .28 width height];    
   mcwPos=[left1 .23 width1 height1];
   lableHandle=LocalBuildUi(labelPos,  'radio', 'anfisedit #radioloadtype', 'Testing','dattype');
   set(lableHandle, 'Max', 1, 'Min', 0);
   % Then the editable text field
   
   mcwHndl=LocalBuildUi(mcwPos, 'radio', 'anfisedit #radioloadfrom', 'worksp.', 'trndatin');

   labelPos=[left .23 width height];    
   lableHandle=LocalBuildUi(labelPos,  'radio', 'anfisedit #radioloadtype', 'Checking','dattype');
   set(lableHandle, 'Max', 1, 'Min', 0);

   labelPos=[left .18 width height];    
   lableHandle=LocalBuildUi(labelPos,  'radio', 'anfisedit #radioloadtype', 'Demo','dattype');
   set(lableHandle, 'Max', 1, 'Min', 0);

%   set(mcwHndl, 'Max', 1);
   mcwPos=[left .13 .13 height]; 
  %=======The Open Training set button==============
   delHndl=LocalBuildUi(mcwPos, 'pushbutton', 'anfisedit #opentrn', 'Load Data...', 'opentrn');
   mcwPos=[left+.14 .13 .13 height]; 
   delHndl=LocalBuildUi(mcwPos, 'pushbutton', 'anfisedit #cleardata', 'Clear Data', 'opentrn');
   
   
   %========Set up the Status Window ==================     
   
   % Then the status text field
   mcwPos=[0.02 0.04 0.55 0.040];
   mcwHndl=LocalBuildUi(mcwPos, 'text', '', '', 'status');
   %==========set genfis area============================
   % The text label
   labelPos=[.34 .42 .18 .042];      
   lableHndl=LocalBuildFrmTxt(labelPos, '   Generate FIS', 'text', 'lable2');
   left=.33;
   width=.225;
   height=.04;
   labelPos=[left .35  width height];    
   lableHandle=LocalBuildUi(labelPos, 'radio', 'anfisedit #radiogenfis', 'Load from disk', 'genfis');
   labelPos=[left .30  width height];    
   lableHandle=LocalBuildUi(labelPos, 'radio', 'anfisedit #radiogenfis', 'Load from worksp.', 'genfis');
   labelPos=[left .25  width height];    
   lableHandle=LocalBuildUi(labelPos, 'radio', 'anfisedit #radiogenfis', 'Grid partition', 'genfis');
   set(lableHandle, 'Max', 1, 'Value', 1);
   labelPos=[left .20  width height];    
   lableHandle=LocalBuildUi(labelPos, 'radio', 'anfisedit #radiogenfis', 'Sub. clustering', 'genfis');
   % Then the editable text field
   labelPos=[left .13  width height];    
   
   mcwHndl=LocalBuildUi(labelPos, 'pushbutton', 'anfisedit #genfis', 'Generate FIS ...', 'genfisbtn');
 

   %====================================
   % Information for anfis
   left=0.80;
   btnWid=0.15;
   top=.55;
   frmBorder=0.02;
   frmPos=[left-frmBorder .5 btnWid+2*frmBorder .46];
   frmHandle=LocalBuildFrmTxt(frmPos, '', 'frame', '');
   labelPos=[left .95 .15 .030];    
   lableHndl=LocalBuildFrmTxt(labelPos, '  ANFIS Info.', 'text', 'lable2');
   % Then the info text field
   mcwPos=[left .65 .15 .24]; 
   textHndl=LocalBuildFrmTxt(mcwPos, infoStr, 'text', 'Comments');
   mcwPos=[left .57 .15 .04]; 
   delHndl=LocalBuildUi(mcwPos, 'pushbutton', 'anfisedit #plotstruc', 'Structure', 'plotstrc');
   set(delHndl, 'Backgroundcolor', [0.75 0.75 0.75], 'HorizontalAlignment', 'center'); 
   mcwPos=[left .52 .15 .04]; 
   delHndl=LocalBuildUi(mcwPos, 'pushbutton', 'cla', 'Clear Plot', '');
   set(delHndl, 'HorizontalAlignment', 'center');
    
   %=========The Train fis=============
   labelPos=[.6 .42 .14 .042];    
   lableHndl=LocalBuildFrmTxt(labelPos, '   Train FIS', 'text', 'lable2');
   frmBorder=0.02;
   btnHt=0.03;
   yPos=top+.31;
   left=.595;
   width=.16;
   height=.04;
   labelPos=[left .39  width height];    
   lableHandle=LocalBuildFrmTxt(labelPos, 'Optim. Method:','text', '');
   labelPos=[left .35  width height];    
   lableHandle=LocalBuildUi(labelPos, 'popupmenu', '', {'backpropa', 'hybrid'}, 'trnmethod');
   set(lableHandle, 'value', 2);
   labelPos=[left .295  width height];    
   lableHandle=LocalBuildFrmTxt(labelPos, 'Error Tolerance:','text', '');
   labelPos=[left .26  width height];    
   lableHandle=LocalBuildUi(labelPos, 'edit', 'anfisedit #errorlim', '0', 'errlim');
   set(lableHandle, 'backgroundcolor', 'white');
   labelPos=[left .22  width height];    
   lableHandle=LocalBuildFrmTxt(labelPos,'Epochs:',  'text','');
   set(lableHandle, 'Max', 1, 'Value', 1);
   labelPos=[left .19  width height];    
   lableHandle=LocalBuildUi(labelPos, 'edit', 'anfisedit #reset', '3', 'epoch');
   set(lableHandle, 'backgroundcolor', 'white', 'Max', 1);
   % Then the editable text field

   labelPos=[left .13  width height];    
   
   mcwHndl=LocalBuildUi(labelPos, 'pushbutton', 'anfisedit #start', 'Train Now', 'startbtn');
   %=========The test fis=============
   labelPos=[.82 .42 .14 .042];    
   lableHndl=LocalBuildFrmTxt(labelPos, '   Test FIS', 'text', 'lable2');
   frmBorder=0.02;
   left=.79;
   width=.19;
   height=.04;
   labelPos=[left .34  width height];    
   lableHandle=LocalBuildFrmTxt(labelPos, 'Plot against:', 'text', '');
   labelPos=[left .30  width height];    
   lableHandle=LocalBuildUi(labelPos, 'radio', 'anfisedit #radiotest', 'Training data', 'test');
   set(lableHandle, 'Max', 1, 'Value', 1);
   labelPos=[left .25  width height];    
   lableHandle=LocalBuildUi(labelPos, 'radio', 'anfisedit #radiotest', 'Testing data', 'test');
   labelPos=[left .2  width height];    
   set(lableHandle, 'Max', 1, 'Value', 0);
   lableHandle=LocalBuildUi(labelPos, 'radio', 'anfisedit #radiotest', 'Checking data', 'test');
   set(lableHandle, 'Max', 1, 'Value', 0);
   labelPos=[left .205  width height];    
   % Then the editable text field
   labelPos=[left .13  width height];    
   
   mcwHndl=LocalBuildUi(labelPos, 'pushbutton', 'anfisedit #test', 'Test Now', 'testbtn');
 
   %=======The Close button=============
   closeHndl=LocalBuildBtns('pushbutton', 0, 'Close', 'fisgui #close', 'close');
   helpHndl=LocalBuildBtns('pushbutton', 0, 'Close', 'anfisedit #help', 'help');
   pos=get(helpHndl, 'Position');
   pos(1)=pos(1)-.17;
   set(helpHndl, 'Position', pos, 'String', 'Help');
   %====================================
   % The MENUBAR items
   % First create the menus standard to every GUI
   % Now uncover the figure
   set(figNumber,'Visible','on');

   LocalEnableBtns(fis(1));   
   textHndl=findobj(gcf, 'Tag', 'Comments');
   %textstr=get(textHndl, 'String');
   if isfield(fis, 'input') & isfield(fis, 'output')
     textstr={['# of inputs: ' num2str(length(fis(1).input))],  ['# of outputs: ' ...
            num2str(length(fis(1).output))], [ '# of input mfs: '], [ num2str(getfis(fis(1), 'inmfs'))]};
   end
   set(textHndl, 'String', textstr);
case '#update',
   %==========updata anfis information==========================
   figNumber=watchon;
   oldfis=get(figNumber,'UserData');
   fis=oldfis{1};
   % Clear the current variable plots and redisplay
   textHndl=findobj(gcf, 'Tag', 'Comments');
   %textstr=get(textHndl, 'String');
   textstr={['# of inputs: ' num2str(length(fis.input))], ['# of outputs: ' ...
            num2str(length(fis.output))],  ['# of input mfs: '], [ num2str(getfis(fis(1), 'inmfs'))]};
   set(textHndl, 'String', textstr);
   LocalEnableBtns(fis(1));
   if length(fis)<=1
      undomenu=findobj(figNumber, 'Tag', 'undo');
      set(undomenu, 'Enable', 'off');
   end
   watchoff;
   %========start/stop training==============
case '#start',
   oldfis=get(gcf, 'UserData');
   fis=oldfis{1};
   chkvector=[];
   if ~isfield(fis, 'trndata')| isempty(fis.trndata(1))
      msgbox('no training data yet');
   elseif isempty(fis.input(1).mf)
      msgbox('No membership functions! Use mf editor or genfis button to generate membership functions');
   elseif ~isfield(fis, 'rule') | isempty(fis.rule)
      msgbox('No rules yet! Use rule editor or genfis button to generate rules.');
   else
      if isfield(fis, 'chkdata')
         testdata=fis.chkdata;
      else
         testdata=[];
      end
      EpochHndl=findobj(gcf, 'Tag', 'epoch');
      numEpochs=str2num(get(EpochHndl, 'String'));
      if isempty(numEpochs)
         numEpochs=0;
      end
      txtHndl=findobj(gcf, 'Tag', 'status');
      stopHndl=findobj(gcf, 'Tag', 'startbtn');
      stopflag=get(stopHndl, 'String');
      fismat1=fis;
      errHndl=[];
      if strcmp(stopflag, 'Train Now')
         %=========init plot for training==========
         cla;
         set(stopHndl, 'String', 'Stop');
         errHndl=findobj(gcf, 'Tag', 'errline');
         chkHndl=findobj(gcf, 'Tag', 'chkline');
         errLimHndl=findobj(gcf, 'Tag', 'errlim');
         methodHndl=findobj(gcf, 'Tag', 'trnmethod');
         method=get(methodHndl, 'value');
         errlim=str2num(get(errLimHndl, 'String'));
         xlabelHndl=get(gca, 'XLabel');
         ylabelHndl=get(gca, 'YLabel');
         set(xlabelHndl, 'String', 'Epochs');
         set(ylabelHndl, 'String', 'Error');
         if isempty(errlim)
            errlim=0;
         end
         if isempty(errHndl)|length(get(errHndl, 'Xdata'))~=numEpochs
            if length(get(errHndl, 'Xdata'))~=numEpochs
               delete(errHndl)
            end
            errHndl=line([1:numEpochs], [1:numEpochs], 'linestyle', 'none',...
               'marker', '*', 'Tag', 'errline');
         end
         if isfield(fis, 'chkdata') & ~isempty(fis.chkdata) & (isempty(chkHndl)|length(get(chkHndl, 'Xdata'))~=numEpochs)
            if length(get(chkHndl, 'Xdata'))~=numEpochs
               delete(chkHndl)
            end
            chkHndl=line([1:numEpochs], [1:numEpochs], 'linestyle', 'none',...
                'marker', '.', 'MarkerSize', 10, 'Tag', 'chkline');
            chkvector=zeros(numEpochs,1);
         end
         errvector=zeros(numEpochs,1);
         %========start training=============
         testHndl=findobj(gcbf, 'Tag', 'testbtn');
         set(testHndl, 'Enable', 'off');
         for i=1:numEpochs
            [fismat1, trn_err, stepSize, fismat2, chk_err]=anfis(fis.trndata, fismat1, 2, NaN, testdata, method-1);
            if ~isempty(chkHndl)

⌨️ 快捷键说明

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