Circuit design in biology and machine learning. II. Anomaly detection