GKc-means algorithm

Input: data set 𝒜 ⊂ (ℝ^n), centers (Subscript[z, 1]),⃛,(Subscript[z, k]) ∈ (ℝ^n);
Output: centers (Subscript[c, 1]),⃛,(Subscript[c, k]) ∈ (ℝ^n), membership matrix U, covariance matrices (∑_j)∈(ℝ^(n×n)), j=1⃛k number of iterations;
Submodules: dM[], muGK[], MFz[]

GKcmeans[A_,z_,Ind_]:=Module[{m=Length[A],k=Length[z],n=Length[A[[1]]],eps=0.005,It=20},  
If[Ind≠0,slA=ListPlot[A]];
					(* Initial approximation *)
kk=1;
cen=z//N; 
Scov=ScovN=Table[IdentityMatrix[n],{j,k}]; 
U1=Table[muGK[A,cen,Scov,i,j],{i,m},{j,k}];  
If[n==2,slcen=ListPlot[cen,PlotStyle->{Red,PointSize[.04],Opacity[.7]}];
sl2=Show[slA,slcen];
Print[GraphicsGrid[{{sl0,sl2}},ImageSize->Medium]]];
F1=  MFz[A,cen,U1,Scov];
						(* While loop *)
While[
cenN=Table[Sum[A[[i]]muGK[A,cen,Scov,i,j]^q ,{i,m}]/Sum[muGK[A,cen,Scov,i,j]^q,{i,m}],{j,k}];
If[Ind≠0,slcen=ListPlot[cenN,PlotStyle->{Red,PointSize[.04],Opacity[.7]}];
sl1=sl2; sl2=Show[slA,slcen];
Print[GraphicsGrid[{{sl1,sl2}},ImageSize->Medium]]];
Do[ScovN[[j]]=Sum[muGK[A,cenN,Scov,i,j]^q*KroneckerProduct[(A[[i]]-cenN[[j]]),(A[[i]]-cenN[[j]])],{i,m}]/Sum[muGK[A,cenN,Scov,i,j]^q,{i,m}]
,{j,k}];
U2=Table[muGK[A,cenN,ScovN,i,j],{i,m},{j,k}]; DelU=U2-U1;
F2=  MFz[A,cenN,U2,ScovN];delF=(F1-F2)/F2;
U1=U2;F1=F2;
If[Ind≠0,Print["It-",kk,": centri=",cenN,"\n||Del U||=",Norm[DelU],"; delF = ",delF ]];
Abs[delF]>eps&& kk<It,
kk=kk+1; cen=cenN; Scov=ScovN;
 ];
{cen,U2,Scov,kk}]