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

📄 iriscloud.m

📁 matlab环境下
💻 M
字号:

function iriscloud
global Y1 Y2 Y3;
for i=1:50    
    Y1(i)=1;
    Y2(i)=1;
    Y3(i)=1;
end

n=300;
x1(1,:)=[5.1,4.9,4.7,4.6,5.0,5.4,4.6,5.0,4.4,4.9,5.4,4.8,4.8,4.3,5.8,5.7,5.4,5.1,5.7,5.1,5.4,5.1,4.6,5.1,4.8,5.0,5.0,5.2,5.2,4.7,4.8,5.4,5.2,5.5,4.9,5.0,5.5,4.9,4.4,5.1,5.0,4.5,4.4,5.0,5.1,4.8,5.1,4.6,5.3,5.0];
x1(2,:)=[3.5,3.0,3.2,3.1,3.6,3.9,3.4,3.4,2.9,3.1,3.7,3.4,3.0,3.0,4.0,4.4,3.9,3.5,3.8,3.8,3.4,3.7,3.6,3.3,3.4,3.0,3.4,3.5,3.4,3.2,3.1,3.4,4.1,4.2,3.1,3.2,3.5,3.1,3.0,3.4,3.5,2.3,3.2,3.5,3.8,3.0,3.8,3.2,3.7,3.3];
x1(3,:)=[1.4,1.4,1.3,1.5,1.4,1.7,1.4,1.5,1.4,1.5,1.5,1.6,1.4,1.1,1.2,1.5,1.3,1.4,1.7,1.5,1.7,1.5,1.0,1.7,1.9,1.6,1.6,1.5,1.4,1.6,1.6,1.5,1.5,1.4,1.5,1.2,1.3,1.5,1.3,1.5,1.3,1.3,1.3,1.6,1.9,1.4,1.6,1.4,1.5,1.4];
x1(4,:)=[0.2,0.2,0.2,0.2,0.2,0.4,0.3,0.2,0.2,0.1,0.2,0.2,0.1,0.1,0.2,0.4,0.4,0.3,0.3,0.3,0.2,0.4,0.2,0.5,0.2,0.2,0.4,0.2,0.2,0.2,0.2,0.4,0.1,0.2,0.1,0.2,0.2,0.1,0.2,0.2,0.3,0.3,0.2,0.6,0.4,0.3,0.2,0.2,0.2,0.2];
  ex1(1)=mean(x1(1,:)');en1(1)=std(x1(1,:)');
  ex1(2)=mean(x1(2,:)');en1(2)=std(x1(2,:)');
  ex1(3)=mean(x1(3,:)');en1(3)=std(x1(3,:)');
  ex1(4)=mean(x1(4,:)');en1(4)=std(x1(4,:)');
 
 
 subplot(2,2,1)
       plot3(x1(1,:),x1(3,:),x1(4,:),'Marker','*','Markersize',2,'linestyle','no','color','k')
       axis([4 8 1.1 6.7 0 2.5])
       title('植物数据','fontsize',8)
       text(ex1(1)+1,ex1(3),ex1(4)+0.3,'\leftarrowSetosa','FontSize',8)
       xlabel('萼片长度/(cm)','fontsize',8),ylabel('花瓣高度/(cm)','fontsize',8),zlabel('花瓣宽度/(cm)','fontsize',8)
       grid on
       hold on
          
    x2(1,:)=[7.0,6.4,6.9,5.5,6.5,5.7,6.3,4.9,6.6,5.2,5.0,5.9,6.0,6.1,5.6,6.7,5.6,5.8,6.2,5.6,5.9,6.1,6.3,6.1,6.4,6.6,6.8,6.7,6.0,5.7,5.5,5.5,5.8,6.0,5.4,6.0,6.7,6.3,5.6,5.5,5.5,5.5,5.8,6.0,5.4,6.0,6.7,6.3,5.6,5.5];
    x2(2,:)=[3.2,3.2,3.1,2.3,2.8,2.8,2.3,2.4,2.9,2.7,2.0,3.0,2.2,2.9,2.9,3.1,3.0,2.7,2.2,2.5,3.2,2.8,2.5,2.8,2.9,3.0,2.8,3.0,2.9,2.6,2.4,2.4,2.7,2.7,3.0,3.4,3.1,2.3,3.0,2.5,2.6,3.0,2.6,2.3,2.7,3.0,2.9,2.9,2.5,2.8];
    x2(3,:)=[4.7,4.5,4.9,4.0,4.6,4.5,4.7,3.3,4.6,3.9,3.5,4.2,4.0,4.7,3.6,4.4,4.5,4.1,4.5,3.9,4.8,4.0,4.9,4.7,4.3,4.4,4.8,5.0,4.5,3.5,3.8,3.7,3.9,5.1,4.5,4.5,4.7,4.4,4.1,4.0,4.4,4.6,4.0,3.3,4.2,4.2,4.2,4.3,3.0,4.1];
    x2(4,:)=[1.4,1.5,1.5,1.3,1.5,1.3,1.6,1.0,1.3,1.4,1.0,1.5,1.0,1.4,1.3,1.4,1.5,1.0,1.5,1.1,1.8,1.3,1.5,1.2,1.3,1.4,1.4,1.7,1.5,1.0,1.1,1.0,1.2,1.6,1.5,1.6,1.5,1.3,1.3,1.3,1.2,1.4,1.2,1.0,1.3,1.2,1.3,1.3,1.1,1.3]; 
     ex2(1)=mean(x2(1,:)');en2(1)=std(x2(1,:)');
     ex2(2)=mean(x2(2,:)');en2(2)=std(x2(2,:)');
     ex2(3)=mean(x2(3,:)');en2(3)=std(x2(3,:)');
     ex2(4)=mean(x2(4,:)');en2(4)=std(x2(4,:)');

     
     subplot(2,2,1)
       plot3(x2(1,:),x2(3,:),x2(4,:),'Marker','*','Markersize',2,'linestyle','no','color','k')
      text(ex2(1)+1,ex2(3),ex2(4),'\leftarrow Versicolour','FontSize',8)
       hold on
      x3(1,:)=[6.3,5.8,7.1,6.3,6.5,7.6,4.9,7.3,6.7,7.2,6.5,6.4,6.8,5.7,5.8,6.4,6.5,7.7,7.7,6.0,6.9,5.6,7.7,6.3,6.7,7.2,6.2,6.1,6.4,7.2,7.4,7.9,6.4,6.3,6.1,7.7,6.3,6.4,6.0,6.9,6.7,6.9,5.8,6.8,6.7,6.7,6.3,6.5,6.2,5.9];
      x3(2,:)=[3.3,2.7,3.0,2.9,3.0,3.0,2.5,2.9,2.5,3.6,3.2,2.7,3.0,2.5,2.8,3.2,3.0,3.8,2.6,2.2,3.2,2.8,2.8,2.7,3.3,3.2,2.8,3.0,2.8,3.0,2.8,3.8,2.8,2.8,2.6,3.0,3.4,3.1,3.0,3.1,3.1,3.1,2.7,3.2,3.3,3.0,2.5,3.0,3.4,3.0];
      x3(3,:)=[6.0,5.1,5.9,5.6,5.8,6.6,4.5,6.3,5.8,6.1,5.1,5.3,5.5,5.0,5.1,5.3,5.5,6.7,6.9,5.0,5.7,4.9,6.7,4.9,5.7,6.0,4.8,4.9,5.6,5.8,6.1,6.6,6.4,5.6,5.1,6.1,5.6,5.5,4.8,5.4,5.6,5.1,5.1,5.9,5.7,5.2,5.0,5.2,5.4,5.1];
      x3(4,:)=[2.5,1.9,2.1,1.8,2.2,2.1,1.7,1.8,1.8,2.5,2.0,1.9,2.1,2.0,2.4,2.3,1.8,2.2,2.3,1.5,2.3,2.0,2.0,1.8,2.1,1.8,1.8,1.8,2.1,1.6,1.9,2.0,2.2,1.5,1.4,2.3,2.4,1.8,1.8,2.1,2.4,2.3,1.9,2.3,2.5,2.3,1.9,2.0,2.3,1.8];
     ex3(1)=mean(x3(1,:)');en3(1)=std(x3(1,:)');
     ex3(2)=mean(x3(2,:)');en3(2)=std(x3(2,:)');
     ex3(3)=mean(x3(3,:)');en3(3)=std(x3(3,:)');
     ex3(4)=mean(x3(4,:)');en3(4)=std(x3(4,:)');  
     for i=1:4
         en3(i)=(max(x3(i,:))-min(x3(i,:)))/6;
         en2(i)=(max(x2(i,:))-min(x2(i,:)))/6;
         en1(i)=(max(x1(i,:))-min(x1(i,:)))/6;
     end
          
     cloud1(x1,ex1,en1,n)
     cloud2(x1,ex2,en2,n) 
     cloud3(x3,ex3,en3,n);
     jishu1=0;
     jishu2=0;
   for i=1:50
       if(Y1(i)>Y2(i))
           jishu1=jishu1+1;
       end
       if(Y1(i)>Y3(i))
           jishu2=jishu2+1;
       end
   end
   jishu1
   jishu2
     
     
     
     
     subplot(2,2,1)
     plot3(x3(1,:),x3(3,:),x3(4,:),'Marker','.','Markersize',3,'linestyle','no','color','k')
     text(ex3(1)+1,ex3(3),ex3(4),'\leftarrow Virginica','FontSize',8)
     x(1,:)=[x1(1,:) x2(1,:) x3(1,:)];
     x(2,:)=[x1(2,:) x2(2,:) x3(2,:)];
     x(3,:)=[x1(3,:) x2(3,:) x3(3,:)];
     x(4,:)=[x1(4,:) x2(4,:) x3(4,:)];
     ex(1)=mean(x(1,:));en(1)=std(x(1,:));
     ex(2)=mean(x(2,:));en(2)=std(x(2,:));
     ex(3)=mean(x(3,:));en(3)=std(x(3,:));
     ex(4)=mean(x(4,:));en(4)=std(x(4,:));
    cloud(x,ex,en,n);
    

 
function f=cloud(x,ex,en,n)
for j=1:4
    for i=1:n 
      xx(j,i)=normrnd(ex(j),en(j)); 
     end
end
 for i=1:n
      lishu(i)=exp(-0.5*(xx(1,i)-ex(1))^2/en(1)^2-0.5*(xx(2,i)-ex(2))^2/en(2)^2-0.5*(xx(3,i)-ex(3))^2/en(3)^2-0.5*(xx(4,i)-ex(4))^2/en(4)^2);
 end
 subplot(2,2,4)
    plot3(xx(1,:),xx(4,:),lishu','Marker','.','Markersize',3,'linestyle','no','color','k')
    title('基云','fontsize',8)
    xlabel('萼片长度/cm','fontsize',8),ylabel('花瓣宽度/cm','fontsize',8),zlabel('隶属度','fontsize',8)
 hold on
  success=0;
  
[a,b]=size(x);
     for i=1:b
         for j=1:a
              y(j,i)=exp(-0.5*(x(j,i)-ex(j))^2/en(j)^2);
          end
      end
          
           
 function f=cloud3(x,ex,en,n)
 global Y3;
for j=1:4
    for i=1:n
      xx(j,i)=normrnd(ex(j),en(j)); 
    end
end
 for i=1:n
     lishu(i)=exp(-0.5*(xx(1,i)-ex(1))^2/en(1)^2-0.5*(xx(2,i)-ex(2))^2/en(2)^2-0.5*(xx(3,i)-ex(3))^2/en(3)^2-0.5*(xx(4,i)-ex(4))^2/en(4)^2);
 end
 subplot(2,2,3)
 plot3(xx(1,:),xx(4,:),lishu','Marker','.','Markersize',3,'linestyle','no','color','k')
 text(ex(1),ex(4),0.8,'\leftarrowVirginica','FontSize',8)
 axis([0 8 0 3 0 1])
 hold on
  success3=0;
[a,b]=size(x);
     for i=1:b
         Y3(i)=1;
          for j=1:a
          y(j,i)=exp(-0.5*(x(j,i)-ex(j))^2/en(j)^2);
          end
          Y3(i)=Y3(i)*y(j,i);
      end
      
           
           
 function f=cloud2(x,ex,en,n)
 global Y2;
   for j=1:4
    for i=1:n
      xx(j,i)=normrnd(ex(j),en(j)); 
    end
end
 for i=1:n
     lishu(i)=exp(-0.5*(xx(1,i)-ex(1))^2/en(1)^2-0.5*(xx(2,i)-ex(2))^2/en(2)^2-0.5*(xx(3,i)-ex(3))^2/en(3)^2-0.5*(xx(4,i)-ex(4))^2/en(4)^2);
 end
 subplot(2,2,3)
 plot3(xx(1,:),xx(4,:),lishu','Marker','.','Markersize',2,'linestyle','no','color','k')
  text(ex(1),ex(4),0.8,'\leftarrowVersicolour','FontSize',8)
 hold on
  success2=0;
[a,b]=size(x);
     for i=1:b
         Y2(i)=1;
          for j=1:a
              y(j,i)=exp(-0.5*(x(j,i)-ex(j))^2/en(j)^2);
          end
         Y2(i)=Y2(i)*y(j,i);
       end
           
          
           
   
function f=cloud1(x,ex,en,n)
global Y1;
for j=1:4
    for i=1:n
      xx(j,i)=normrnd(ex(j),en(j)); 
    end
end
 for i=1:n
     lishu(i)=exp(-0.5*(xx(1,i)-ex(1))^2/en(1)^2-0.5*(xx(2,i)-ex(2))^2/en(2)^2-0.5*(xx(3,i)-ex(3))^2/en(3)^2-0.5*(xx(4,i)-ex(4))^2/en(4)^2);
 end
 subplot(2,2,3)
 plot3(xx(1,:),xx(4,:),lishu','Marker','.','Markersize',3,'linestyle','no','color','k')
 %title('植物三个分解云','fontsize',8) 
 text(ex(1),ex(4),0.8,'\leftarrowSetosa','FontSize',8)
  xlabel('萼片长度/cm','fontsize',8),ylabel('花瓣宽度/cm','fontsize',8),zlabel('隶属度','fontsize',8)
  axis([0 8 0 2.5 0 1])
 hold on
 
  
[a,b]=size(x);
     for i=1:b
         Y1(i)=1;
          for j=1:a
              y(j,i)=exp(-0.5*(x(j,i)-ex(j))^2/en(j)^2);
          end
          Y1(i)=Y1(i)*y(j,i);
      end
          
      
      
%success=0;
%PopSize=20;
%MaxIt=70;
%iter=1;
%fevals=0; %function evaluation'counter 
%maxw=1.2;  %maximum interia weight's value
%minw=0.1;  %minimum interia weight's value
%c1=0.5;
%c2=0.5;
%inertdec=(maxw-minw)/MaxIt; % weight decrease by same value, search change function of weight
%w=maxw;
%f='gold';
%dim=4;

%ErrGoal=1e-4;
%initializing swarm and velocity
%for i=1:4
%popul(i,:)=rand(1,PopSize)*(max(i)-min(i))+min(i);
%end
%vel=rand(dim,PopSize);

%evaluation initial population
%for i=1:PopSize
     %x1=popul(1,i); %popul is 2D array,2D particle population
     %x2=popul(2,i);  
     %x3=popul(3,i);
     %x4=popul(4,i);
     %fpopul(i)=feval(f,x1,x2,x3,x4);%fpopul is 1D array,function values of 4D particle population
     %fevals=fevals+1;
     %ppopul(:,i,iter)=popul(:,i);
     %end
%bestpos=popul; % positions of  initial particle
%fbestpos=fpopul;% func values of initial particle
%ppopul(:,:,iter)=ppopul;
% finding best particle in initial 
%[fbestpart(iter),g]=min(fpopul);% min value of population and index.
%lastbpf=fbestpart(iter);% current values of optimal particle

%swarm evolution loop 
%while(iter<MaxIt)
%    iter=iter+1;
    % update the value of inertia weight w
%    if(iter<=MaxIt)
%        w=maxw-(iter-1)*inertdec;
%    end
%    %velocity update
%    for i=1:PopSize
%        A(:,i)=bestpos(:,g);% optical position of each particle is g.
%    end    
%        R1=rand(dim,PopSize);
%        R2=rand(dim,PopSize);
%       vel=w*vel+c1*R1.*(bestpos-popul)+c2*R2.*(A-popul);%local optical is bestpos,global optical is A.
%        %swarm update
%        popul=popul+vel;     
%        %evaluate the new swarm
%        for i=1:PopSize
%            x1=popul(1,i);
%            x2=popul(2,i);
%            x3=popul(3,i);
%            x4=popul(4,i);
%            fpopul(iter,i)=feval(f,x1,x2,x3,x4);
%            fevals=fevals+1;
%        end
%        ppopul(:,:,iter)=popul+vel;
        %update the best position for each particle
%        for i=1:PopSize 
%          if(fpopul(iter,i)<fbestpos(i))
%           fbestpos(i)=fpopul(iter,i);
%            bestpos(:,i)=popul(:,i);
%        end
%        end
              
        % updateing index g
 %       [fbestpart(iter),g]=min(fbestpos);
        %checking stoping criterion
 %      if (abs(fbestpart(iter)-fbestpart(iter-1))<=ErrGoal)&(abs(fpopul(iter,1)-fpopul(iter-1,1))<=ErrGoal)
 %          break;
 %      end
 %   end
    
    %swarm evoluation loop
    % output arguments 
 %   xmin=popul(:,g)
 %   fxmin=fbestpos(g)
 %   bestpos
 %   subplot(1,2,2)
 %   plot3(bestpos(1,:),bestpos(2,:),fbestpos,'b.')
 %   grid on
 %   xx1(:,1)=ppopul(1,1,:);
 %   yy1(:,1)=ppopul(2,1,:)
 %   for i=1:iter
 %       text(xx1(i,1),yy1(i,1),fpopul(i,1),['\leftarrow(',num2str(i),')'],'FontSize',6.0)
       % text(xx1(i,1),yy1(i,1),fpopul(i,1),'\leftarrow')
       %   end
    %plot3(xx1,yy1,fpopul(:,1),'b-')
  %  iter
  %  fevals
   % ppopul(:,:,10)
   % ppopul(:,:,20)
  

%function sum=gold(x1,x2,x3,x4)
%sum=0;
 
% for i=1:50
%     sum=sum+(x11(i)-x1)^2+(x12(i)-x2)^2+(x13(i)-x3)^2+(x14(i)-x4)^2;
% end
     

⌨️ 快捷键说明

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