What about quaternions?
A 3 valued so3 lie algebra vector is however always a valid 3D rotation, no matter what the values are. That makes it an ideal parameterization of the optimization problem.
The mapping from so3 lie algebra to SO3 lie group (which could be represented as a rotation matrix or quaternion) is a smooth differentiable function, which allows us to compute the jacobian we need for the gradient in the optimization.