Made cost function (and deriv) a parameter, and saner initialization for weights