%GApartition.m clear all close all %Identifying the line that %divides the two class as follows. x=randn(2,50)+2; y=randn(2,50)-2; z=[x y]; plot(x(1,:),x(2,:),'r*') hold on plot(y(1,:),y(2,:),'k*') t=[ones(1,50) ones(1,50)*(-1)]; %Generate data IV=[]; nod=10; for i=1:1:nod w{i}=rand(1,2)*2-1; b(i)=rand-0.5; IV=[IV fga(w{i},z,b(i),t')]; end [A,B]=max(IV); BESTVAL=[A]; BESTSOL=[w{B} b(B)]; index=1; for iteration=1:1:100 F=[]; %Cross-over for i=1:2:2*nod r1=round(rand*(nod-1))+1; r2=round(rand*(nod-1))+1; r=rand; DATAW{i}=r*w{r1}+(1-r)*w{r2}; DATAW{i+1}=(1-r)*w{r1}+r*w{r2}; DATAb(i)=r*b(r1)+(1-r)*b(r2); DATAb(i+1)=(1-r)*b(r1)+r*b(r2); F=[F fga(DATAW{i},z,DATAb(i),t') fga(DATAW{i+1}, z,DATAb(i+1),t')] end %Selection from the generated data %Formulation of Roulette wheel F=F-min(min(F)); F=F/(sum(F)+eps); F=cumsum(F); VAL=[]; for i=1:1:nod [P,Q]=find((F-rand)>0); if(isempty(Q)==1) Q=1; end w{i}=[DATAW{Q(1)}]; b(i)=DATAb(Q(1)); VAL=[VAL fga(w{i},z,b(i),t')]; end [M,N]=max(VAL); if(BESTVAL(index)