Dunn index for optimal LS partition

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

Clear[VD]
VD[PI_]:=Module[{z,DD,diam},
z=Table[Mean[WeightedData[PI[[j,All,2]],PI[[j,All,1]]]],{j,Length[PI]}];
DD=Table[If[i≠j,Min[Table[Norm[PI[[i,p,2]]-PI[[j,q,2]]],{p,Length[PI[[i]]]},{q,Length[PI[[j]]]}]],Infinity],{i,Length[PI]},{j,Length[PI]}];
diam=Table[Max[Table[Norm[PI[[i,p,2]]-PI[[i,q,2]]],{p,Length[PI[[i]]]},{q,Length[PI[[i]]]}]],{i,Length[PI]}];
Min[DD/Max[diam]]
]