A loss framework for calibrated anomaly detection