Test-Example~9.4:  4 clusters in R^3

Submodules: WKMeans[], WF[], WG[], Rand[], Hdist[];
Output: data set, optimal partition, Rand and Jaccard index, confusion matrix;

(* In this case if Inc[] algorithm is used in Compile it needs to be adjust the funkciju F (3 variables) *)
SeedRandom[1213];
c={{2.5,3,2},{2,8.5,4},{5,6,4},{8,5,6}};
var=1.; broj=100;  n=Length[c[[1]]];
podaci=Table[RandomVariate[MultinormalDistribution[ci,var IdentityMatrix[3]],broj],{ci,c}];
pod=Flatten[podaci,1]; 
m=Length[pod];
w=Table[1,{i,m}];
Dimensions[pod]
						(* DATA *)
A=Flatten[podaci,1];
AG=Table[{Min[A[[All,i]]]-.5,Max[A[[All,i]]]+.5},{i,n}];
m=Length[A];
w=Table[1,{i,m}]; 
slc=ListPointPlot3D[c,PlotStyle->{Black,PointSize[.04],Opacity[.8]},PlotRange->AG,ViewPoint->{1.3,-2.4,2.},ImageSize->Small];
slpod1=Show[ListPointPlot3D[podaci,PlotStyle->{PointSize[.012]}],slc,AspectRatio->Automatic,GridLines->Automatic,PlotRange->AG,ImageSize->Small]
slA=ListPointPlot3D[A,PlotRange->AG,PlotStyle->{PointSize[.012]},ViewPoint->{1.3,-2.4,2.},ImageSize->Small]
slA=ListPointPlot3D[A,PlotRange->AG,PlotStyle->{PointSize[.012]},ViewPoint->{-2.3,1.4,1},ImageSize->Small]
z0={{3,3,3},{3,5,3},{5,5,5},{9,3,5}};k=Length[z0];
						(* k-means *)
time=Timing[sol=WKMeans[w,A,z0]];
Print["F= ",WF[sol[[1]]],   ";  G= ",WG[sol[[1]]],"; CPU=",time[[1]]]
							(* Figures *)
Print["k-means reconstruction for selected centers z0: ",z0]
slc=ListPointPlot3D[sol[[2]], ViewPoint->{1.3,-2.4,2.},PlotStyle->{Gray,PointSize[.04],Opacity[.7]}];
slPI=ListPlot[Table[sol[[1,j,All,2]],{j,k}],PlotStyle->Table[Hue[j/k],{j,k}]];
PI1=Table[Union[sol[[1,j,All,2]]],{j,Length[sol[[1]]]}];
sl3=Show[slc,slA,AspectRatio->Automatic,GridLines->Automatic,PlotRange->AG];
Print[GraphicsGrid[{{slpod1,sl3}},ImageSize->Medium]];
tab=Table[sol[[1,j,All,2]],{j,Length[sol[[1]]]}];
ind=Rand[podaci,tab];
Print["Hausdorff dist. = ",Hdist[sol[[2]],c]]
Print["{Rand, Jaccard} index = ",{ind[[1]],ind[[2]]}]
Print["Confusion matrix S= ",ind[[3]]//MatrixForm]