Mahalanobis objective functions

Input: partition Π={(Subscript[π, 1]),⃛,(Subscript[π, k])} of the weighted set 𝒜 ⊂ (ℝ^n), (in case of WFmin[] only the set 𝒜), centers (Subscript[c, 1]),⃛,(Subscript[c, k]) ∈ (ℝ^n), covariance matrices (∑_j)∈(ℝ^(n×n)), j=1⃛k;
Output: Mahalanobis objective function values: (Subscript[ℱ, M])(Π), (Subscript[\[FormalCapitalF], M])(Π);
Submodules: dM[]

MWF[PI_,c_,Scov_]:=Module[{m=Length[Flatten[PI,1]],n=Length[Scov]},
Return[Sum[PI[[j,s,1]]*dM[PI[[j,s,2]],c[[j]],Scov[[j]]],{j,Length[PI]} ,{s,Length[PI[[j]]]}] ]
];

MWFmin[PI_,c_,Scov_]:=Module[{A=Flatten[PI,1][[All,2]],m=Length[A],k=Length[c]},
Sum[Flatten[PI,1][[All,1]][[i]]Min[Table[dM[c[[j]],A[[i]],Scov[[j]]],{j,k}]],{i,m}]
]