net: changed get-cost-and-gradient to return a function to simplify params
net: implemented change to get-cost-and-gradient