added writes to each loop in functions
Merge pull request #386 from micheldumontier/sgd

added writes to each loop in functions