Mahalanobis  simplified silhouette with criterion  for optimal Mahalanobis partitions

Input: partition Π={(Subscript[π, 1]),⃛,(Subscript[π, k])} of the weighted set 𝒜 ⊂ (ℝ^n), centers (Subscript[c, 1]),⃛,(Subscript[c, k]) ∈ (ℝ^n), covariance matrices (∑_j)∈(ℝ^(n×n)), j=1⃛k;
Output: MSSWC index for the partition Π;
Submodules: dM[]

Clear[MSWC]
MSWC[PI_,z_,Scov_]:=Module[{k=Length[PI],alfe,bete,w,s},
w=Table[Total[PI[[i,All,1]]],{i,k}];
alfe=Table[Sum[PI[[i,s,1]]*dM[PI[[i,j,2]],PI[[i,s,2]],Scov[[i]]],{s,Length[PI[[i]]]}]/w[[i]],{i,k},{j,Length[PI[[i]]]}];
bete=Table[Min[Table[Sum[PI[[q,s,1]]*dM[PI[[i,j,2]],PI[[q,s,2]],Scov[[q]]],{s,Length[PI[[q]]]}]/w[[q]],{q,Delete[Range[k],i]}]],{i,k},{j,Length[PI[[i]]]}];
s=Table[(bete[[i,j]]-alfe[[i,j]])/Max[alfe[[i,j]],bete[[i,j]]],{i,k},{j,Length[PI[[i]]]}];
Return[N[Mean[Flatten[s]]]];
]