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

📄 findcluster.m

📁 模糊逻辑工具箱 模糊逻辑工具箱 模糊逻辑工具箱 模糊逻辑工具箱 模糊逻辑工具箱
💻 M
📖 第 1 页 / 共 2 页
字号:
function findcluster(action);
% FINDCLUSTER  is a cluster interface.
%   The FINDCLUSTER let you use two clustering algorithms interactively.
%   It is containts subtractive clustering and fuzzy c-means clustering.
%   FINDCLUSTER is a GUI tool which implements fcm and subcluster
%   along with all of their options on a user interface. Data is entered using 
%   the Load Data button, and Save will save the cluster center.
%   This tool works on multi-dimensional data sets, but only displays on two
%   dimensions. Use the pulldown tabs under X-axis and Y-axis to select which 
%   data dimension you want to view.                              
%
%    See also SUBCLUST FCM 

%   Kelly Liu, Feb. 97
%   Copyright (c) 1994-98 by The MathWorks, Inc.
%   $Revision: 1.6 $  $Date: 1997/12/01 21:44:52 $

filename='';
if nargin<1,
    action='initialize';
else
   if ~strcmp(action(1), '#') 
    filename=action;
    action='initialize';
   else
    action=action(2:end);
   end;
end;

switch action
 case 'initialize',
    figNumber=figure( ...
         'Name','Clustering', ...
         'NumberTitle','off');          %, ...
%         'HandleVisibility','callback');
   axHndl=axes( ...
        'Units','normalized', ...
        'Position',[0.10 0.25 0.65 0.7],...
        'Tag', 'mainaxes');
   set(get(axHndl, 'Xlabel'), 'String', 'X');
   set(get(axHndl, 'Ylabel'), 'String', 'Y');
%    rotate3d on;

    %===================================    
    right=0.75;
    bottom=0.05;
    labelHt=0.03;
    spacing=0.005;
    frmBorder=0.012;

   %====================================
    % Information for all buttons    
    left=0.80;
    btnWid=0.15;
    top=.5;

    %=========The Panel frame============
    frmBorder=0.02;
    yPos=0.05-frmBorder;
    frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
    frmHandle=LocalBuildFrmTxt(frmPos, '', 'frame', '');

    %=========The Slide frame=============
    frmBorder=0.02;
    btnHt=0.05;
    yPos=top+.4;
 
    %=========The display dimesion============
     btnPos=[.11 .095 .1 .05];
     dimsHndl=LocalBuildUi(btnPos, 'text', '',...
                           'X-axis', 'dimXLabel');
     set(dimsHndl, 'BackGroundColor', [.8 .8 .8]);

     btnPos=[.46 .095 .1 .05];
     dimsHndl=LocalBuildUi(btnPos, 'text','',...
                           'Y-axis', 'dimYLabel');
     set(dimsHndl, 'BackGroundColor', [.8 .8 .8]);
%     btnPos=[.5 .14 .1 .05];
%     dimsHndl=LocalBuildUi(btnPos, 'text', '',...
%                           'Z axes', 'dimZLabel');
%     set(dimsHndl, 'BackGroundColor', [.7 .7 .7]);
    
     btnPos=[.2 .1 .15 .05];
     dimsHndl=LocalBuildUi(btnPos, 'popupmenu', 'findcluster #dispdim', 'data_1', 'dimX');
     btnPos=[.55 .1 .15 .05];
     dimsHndl=LocalBuildUi(btnPos, 'popupmenu', 'findcluster #dispdim', 'data_1', 'dimY');
%     btnPos=[.6 .14 .1 .05];
%     dimsHndl=LocalBuildUi(btnPos, 'popup', 'findcluster #dispdim', 'x1', 'dimZ');
     btnPos=[.1 .02 .65 .07];
     dimsHndl=LocalBuildFrmTxt(btnPos, '', 'frame', '');
     btnPos=[.11 .03 .63 .05];
     dimsHndl=LocalBuildUi(btnPos, 'text', '', 'ready', 'status');
     set(dimsHndl, 'BackgroundColor', [.8 .8 .8]);
    %======The start button=============
    delHndl=LocalBuildBtns( 'Pushbutton', 10,'Start', 'findcluster #start', 'start');
    set(delHndl, 'Enable', 'off');
    
    %=======The Open button==============
    addHndl=LocalBuildBtns( 'Pushbutton', 1, 'Load Data...', 'findcluster #open', 'open');
    
    %======The Method=============
    btnPos=[left yPos-.05 btnWid btnHt];
    dimDHndl=LocalBuildBtns('text', 2, 'Methods', '', 'methodlabel');
    set(dimDHndl, 'BackgroundColor', [.5 .5 .5]);
    delHndl=LocalBuildBtns( 'PopupMenu', 2.5, {'subtractiv', 'fcm'}, 'findcluster #method', 'method');

    %=======The # of cluster/influence==============
       
    dimDHndl=LocalBuildBtns('text', 3.5, 'Cluster Num.', '', 'clstrNumlabel');
    dimDHndl=LocalBuildBtns('text', 3.5, 'Influence Range', '', 'sbtrparam');
   
    addHndl=LocalBuildBtns( 'edit', 4., '2', 'findcluster #setclstrnum', 'setclstrnum');
    saveHndl=LocalBuildBtns( 'edit', 4., '.5', 'findcluster #setparam', 'influence');
    %=======The param button==============
    dimDHndl=LocalBuildBtns('text', 5, 'Max Iteration#', '', 'clstrNumlabel');
    dimDHndl=LocalBuildBtns('text', 5, 'Squash', '', 'sbtrparam');

    saveHndl=LocalBuildBtns( 'edit', 5.5, '100', 'findcluster #setparam', 'maxitera');
    saveHndl=LocalBuildBtns( 'edit', 5.5, '1.25', 'findcluster #setparam', 'squash');

    dimDHndl=LocalBuildBtns('text', 6.5, 'Min. Improvement', '', 'clstrNumlabel');
    dimDHndl=LocalBuildBtns('text', 6.5, 'Accept Ratio', '', 'sbtrparam');

    saveHndl=LocalBuildBtns( 'edit', 7, '1e-5', 'findcluster #setparam', 'minimprove');
    saveHndl=LocalBuildBtns( 'edit', 7, '.5', 'findcluster #setparam', 'accept');

    dimDHndl=LocalBuildBtns('text', 8, 'Exponent', '', 'clstrNumlabel');
    dimDHndl=LocalBuildBtns('text', 8, 'Reject Ratio', '', 'sbtrparam');

    saveHndl=LocalBuildBtns( 'edit', 8.5, '2.0', 'findcluster #setparam', 'exponent');
    saveHndl=LocalBuildBtns( 'edit', 8.5, '.15', 'findcluster #setparam', 'reject');

    %=======The Save button==============
    saveHndl=LocalBuildBtns( 'Pushbutton', 11, 'Save Center...', 'findcluster #save', 'save');
    set(saveHndl, 'Enable', 'off');
    %=======The clear button==============
    Hndl=LocalBuildBtns( 'Pushbutton', 12, 'Clear Plot', 'cla', 'cla');
        
    %=======The Info button==============
    infoHndl=LocalBuildBtns( 'Pushbutton', 0, 'Info', 'findcluster #info', 'info');

    %=======The Close button=============
    closeHndl=LocalBuildBtns( 'Pushbutton', 0, 'Close', 'close(gcf)', 'close');
    TextHndl=uicontrol('Style', 'text', 'Unit', 'normal',...
                      'Visible', 'off',...
                      'Position', [0 0 .1 .020], 'Tag', 'strcparam');

    % Now uncover the figure
    param.dataDim=1;
    param.dispList=[];
    param.data=[];
    param.center=[];
    param.centerplotH=[];
    param.inputparam={'.5', '1.25', '.5', '.15'};
    LocalButtonControl;
    set(figNumber, 'Userdata', param);
    set(figNumber,'Visible','on');
    if ~isempty(filename)
       localloadfile(filename, param);
    end
%========display dimesions
case 'dispdim',
   cla
   dimHndl=findobj(gcf, 'Type', 'uicontrol', 'Tag', 'dimX');
   x=get(dimHndl, 'Value');
   dimHndl=findobj(gcf, 'Type', 'uicontrol', 'Tag', 'dimY');
   y=get(dimHndl, 'Value');
%   dimHndl=findobj(gcf, 'Type', 'uicontrol', 'Tag', 'dimZ');
%   z=get(dimHndl, 'Value');

   dispList=[x, y];              %, z];
   LocalPlotdata(dispList);
%=======select subtractive or fcm======
case 'method',
   LocalButtonControl;
%=======start clustering========
case 'start',
   param=get(gcbf, 'Userdata');
   stopHndl=findobj(gcbf, 'Tag', 'start');
   statusHndl=findobj(gcbf, 'Tag', 'status');

   stopflag=get(stopHndl, 'String');
   if strcmp(stopflag, 'Stop')
     set(stopHndl, 'String', 'Start');
   else
     set(stopHndl, 'String', 'Stop');

     medHndl=findobj(gcbf, 'Type', 'uicontrol', 'Tag', 'method');
     n=get(medHndl, 'value');
     %=========subtractive
     if n==1
      radiHndl=findobj(gcbf, 'Tag', 'influence');
      squaHndl=findobj(gcbf, 'Tag', 'squash');
      accpHndl=findobj(gcbf, 'Tag', 'accept');
      rejeHndl=findobj(gcbf, 'Tag', 'reject');

      inputparam=get(radiHndl, 'String');
      radioList=str2num(inputparam);
      if ~isempty(radioList)
         if length(radioList) < size(param.data, 2)
            radioList(end+1:size(param.data, 2))=radioList(end);
         elseif length(radioList) > size(param.data, 2)
            radioList(size(param.data, 2)+1, end) = [];
         end
      end     
      squafactor=get(squaHndl, 'String');
      acceptfact=get(accpHndl, 'String');
      rejectfact=get(rejeHndl, 'String');
      set(statusHndl, 'String', 'processing clustering...');
      [center, sigmas]=subclust(param.data, radioList, [],...
                                [str2num(squafactor), str2num(acceptfact), str2num(rejectfact), 0]);
      set(statusHndl, 'String', 'ready');
   %=========fcm=============
   else
      paramHndl=findobj(gcbf, 'Tag', 'setclstrnum');
      maxiHndl=findobj(gcbf, 'Tag', 'maxitera');
      miniHndl=findobj(gcbf, 'Tag', 'minimprove');
      expoHndl=findobj(gcbf, 'Tag', 'exponent');
      options=[str2num(get(expoHndl, 'String')), str2num(get(maxiHndl, 'String')),...
              str2num(get(miniHndl, 'String')), 0];
      cluster_n=str2num(get(paramHndl, 'String'));
      data_n = size(param.data, 1);
      in_n = size(param.data, 2);

      expo = options(1);		% Exponent for U
      max_iter = options(2);		% Max. iteration
      min_impro = options(3);		% Min. improvement
      display = options(4);		% Display info or not

      obj_fcn = zeros(max_iter, 1);	% Array for objective function

      U = initfcm(cluster_n, data_n);			% Initial fuzzy partition
if ~isempty(param.centerplotH)
set(param.centerplotH, 'Xdata', [],...
                                 'Ydata', [],...
                                 'Zdata', []);      % Main loop
 drawnow
end
      for i = 1:max_iter,
	[U, center, obj_fcn(i)] = stepfcm(param.data, U, cluster_n, expo);
        if strcmp(get(stopHndl, 'String'), 'Start')
            break;
        end

        set(statusHndl, 'String',...
             ['Iteration count = ' num2str(i) ' obj. fcn = ' num2str(obj_fcn(i))]);
        if isempty(param.centerplotH)
          param.center=center;
          set(gcbf, 'UserData', param);
          findcluster #dispdim
          param=get(gcbf, 'Userdata');

        else
          set(param.centerplotH, 'Xdata', center(:,param.dispList(1)),...
                                 'Ydata', center(:,param.dispList(2)));         
%                                 'Zdata', center(:,param.dispList(3)));
          drawnow
         
        end
	% check termination condition
	if i > 1,
		if abs(obj_fcn(i) - obj_fcn(i-1)) < min_impro, break; end,

⌨️ 快捷键说明

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