A Neural Network Based on First Principles