How learning unfolds in the brain: toward an optimization view