Fuzzy incremental algorithm

Input: the set 𝒜 ⊂ (ℝ^n), initial center(s) cen, number of iterations K. Each additional center is obtained solving a GOP using Compile. In case when n>2,one has to adapt the minimizing function;
Output: set of partitions and values of FCH,FDB,and FXB indexes(if the original partition is known,one can also obtain the Rand and Jaccard indexes,confusion matrix and Hausdorff distance between the sets of original and calculated cluster centers).Graphical depictions of each iteration are presented only for n=2;
Submodules: FXB[], FCH[], FDB[], Hdist[], Rand[], DIRECT[], cmeans[]

FInc[A_,z_,KK_,Ind_:0]:=Module[{k,centri,m=Length[A],n=Length[A[[1]]],dom,TT=0},
					(* Initialization *)
centri=z;
PART={};IndFXB=IndFCH=IndFDB=IndFHV=IndRand=IndJaccard=IndH={};
				(* Iterative Procedure *)
Do[
Print["\nNa postojecih ",Length[centri]," centara dodaje se 1 novi"];
Clear[u,v]; 
dom=AG;
					(* Compile *)
FCompile=Compile[{{u,_Real},{v,_Real}},
Evaluate[Sum[Min[Append[Table[Norm[A[[i]]-centri[[s]]]^2,{s,Length[centri]}],Norm[A[[i]]-{u,v}]^2]],{i,m}] ]];	
F2[u_,v_]:=Apply[FCompile,{u,v}];	
						(* Non Compile 
F2[u_,v_]:=Sum[Min[Append[Table[Norm[A[[i]]-centri[[s]]]^2,{s,Length[centri]}],Norm[A[[i]]-{u,v}]^2]],{i,m}];
*)
								(* DIRECT *)
minp=DIRECT[F2,dom,DMin->10.^(-3),MaxIter->50, Eps->10^(-4)]//Timing; min=minp[[2]];(* Print["DIRECT: ",min]; *)
centriN=Append[centri,min[[1]]];
If[Ind≠0,Print["Novi optimirani centar: ",centriN]];
					(* Poziv c-means *)
t1=Timing[sol=cmeans[A,centriN,0]]; 
TT=TT+minp[[1]]+t1[[1]];
k=Length[sol[[1]]]; 
If[Ind≠0,Print["Novi c-means profinjeni centar: ",sol[[1]]]];
If[Ind≠0,Print["Fz=",Fz[A,sol[[1]],sol[[2]]],
"; Time (DIRECT+cmeans) = ",minp[[1]],"+",t1[[1]]," = ",minp[[1]]+t1[[1]]]];
fch=FCH[A,sol[[1]],sol[[2]]];IndFCH=Append[IndFCH,fch];
fdb=FDB[A,sol[[1]],sol[[2]]];IndFDB=Append[IndFDB,fdb];
fxb=FXB[A,sol[[1]],sol[[2]]];IndFXB=Append[IndFXB,fxb];
If[Ind≠0,Print["k=",Length[centriN],"; FCH=",fch,"; FDB=",fdb,"; FXB=",fxb]];
ind=RandFrigue[sol[[2]],U0]; 
Huel=Hullermeier[sol[[2]],U0]; 
HD=Hdist[centers,sol[[1]]];
If[Ind≠0,Print["{Rand, Jaccard, Hausdorff}: ",{ind,HD} ]];
IndRand=Append[IndRand,ind[[1]]];
IndJaccard=Append[IndJaccard,ind[[2]]];
IndH=Append[IndH,HD];
                                                                     (* FIGUREE *)
If[n==2,
k=Length[sol[[1]]];
slc=ListPlot[sol[[1]],PlotMarkers->{"✶",20},PlotStyle->{Orange,PointSize[.025],Opacity[.9]}];
rad=Table[Sum[mu[A,sol[[1]],i,j] Norm[sol[[1,j]]-A[[i]]]^2,{i,Length[A]}]/Length[A],{j,k}];
rad=Sqrt[rad];
sle1=Table[Graphics[{Gray,Circle[sol[[1,j]],rad[[j]]]}],{j,k}];
		(* Ovo je samo za crtanje sljedeceg centra *)
						(* Compile *)
Clear[u,v,F2]; 
FCompile=Compile[{{u,_Real},{v,_Real}},
Evaluate[Sum[Min[Append[Table[Norm[A[[i]]-centriN[[s]]]^2,{s,Length[centriN]}],Norm[A[[i]]-{u,v}]^2]],{i,m}] ]];	
F2[u_,v_]:=Apply[FCompile,{u,v}];
mini=DIRECT[F2,dom,DMin->10.^(-3),MaxIter->20, Eps->10^(-4)];
nextc=ListPlot[{mini[[1]]},PlotStyle->{Red,PointSize[.04],Opacity[.8]}];
								(*  *)
Print[Show[slA,sle1,slc,nextc,AspectRatio->Automatic,GridLines->Automatic,PlotRange->AG,ImageSize->Small]];
];			      
centri=sol[[1]];     
PART=Append[PART,{sol[[1]],sol[[2]]}]; 
,{brk,KK}];
				(* Indexes *)
If[Ind≠0,Print["Rand: ",IndRand,"\nJaccard: ",IndJaccard,"\nHausdorff: ",IndH,"\nFXB: ",IndFXB,"\nFCH: ",IndFCH,"\nIndFDB: ",IndFDB]];
Print["CPU = ",TT];
				(* Figures *)
If[Ind≠0,
slRand=ListPlot[Table[{j+1,IndRand[[j]]},{j,1,KK}],Joined->True,AxesOrigin->{1,.75Min[IndRand]},PlotLabel->"F-Rand",ImageSize->200];
slJaccard=ListPlot[Table[{j+1,IndJaccard[[j]]},{j,1,KK}],Joined->True,AxesOrigin->{1,.75Min[IndJaccard]},PlotLabel->"F-Jaccard",ImageSize->200];
slH=ListPlot[Table[{j+1,IndH[[j]]},{j,1,KK}],Joined->True,AxesOrigin->{1,.75Min[IndH]},PlotLabel->"Hausdorff",ImageSize->200];
slFXB=ListPlot[Table[{j+1,IndFXB[[j]]},{j,1,KK}],Joined->True,AxesOrigin->{1,.75Min[IndFXB]},PlotLabel->"FXB",ImageSize->200];
slFDB=ListPlot[Table[{j+1,IndFDB[[j]]},{j,1,KK}],Joined->True,AxesOrigin->{1,.75Min[IndFDB]},PlotLabel->"FDB",ImageSize->200];
slFCH=ListPlot[Table[{j+1,IndFCH[[j]]},{j,1,KK}],Joined->True,AxesOrigin->{1,.75Min[IndFCH]},PlotLabel->"FCH",ImageSize->200];
Print[Style[GraphicsGrid[{{slFXB,slFDB,slFCH},{slRand,slJaccard,slH}}]]]];	
{PART,IndRand,IndJaccard,IndH,IndFXB,IndFCH,IndFDB}
]