double tanhDeriv(double x) { var ex = math.exp(x); var sech = (2 * ex) / (ex * ex + 1); return sech * sech; }