Simplified silhouette with criterion for optimal LS partition

(* 
Input: partition Π of the set 𝒜 ⊂ (ℝ^n);
Output: SSWC index of the partition Π;
Submodules: none needed 
*)

Clear[SSWC]
SSWC[PI_]:=Module[{k=Length[PI],a,b,dd,w},
set=Flatten[PI,1];m=Length[set];
a=b=Table[0,{i,m}];
w=set[[All,1]];A=set[[All,2]];
z=Table[Mean[WeightedData[PI[[j,All,2]],PI[[j,All,1]]]],{j,Length[PI]}];
Do[
dd=Sort[Table[w[[i]] Norm[A[[i]]-z[[j]]]^2,{j,k}]];
a[[i]]=dd[[1]];b[[i]]=dd[[2]];
,{i,m}];
Sum[(b[[i]]-a[[i]])/Max[{a[[i]],b[[i]]}],{i,m}]/m
]