calculate gradient w and b