make this script immediately replaceable once the generic function sgd and batch apply