Inference for Clustering and Anomaly Detection