Added np.clip for sigmoid to prevent overflow