mex for ap clustering