Walk me through a time when you built a machine learning model from scratch - not using high-level frameworks like Keras or scikit-learn, but implementing the core algorithms yourself. What was the mathematical foundation, how did you implement backpropagation, and what optimization challenges did you face?