Compute squared error cost function