I am implementing a paper which recovers full-3d body pose from images.
It represents individual body parts as 7D vectors containing first the absolute 3D location [x y z] and then the unit quaternion values describing that parts rotation [qx qy qz qw].
Conditional relationships between body-parts are represented by Mixture-Of-Gaussian models. For instance a component of the MoG between the torso and head might contain the means [0, 0.4, 0, 0, 0, 0, 1] suggesting that the head is +0.4 on the y axis and has the same rotation with respect to the torso.
So if we have a candidate torso with the position [5 7 3] the head's 3D position can be estimated by the propagated MoG components, the mean from our example would be propagated to become [5, 7.4, 3].
However this does not take into account the torso's rotation. If the torso is bending to the side the head will no longer be +0.4 directly on the 'y' axis, both the means and the covariance matrix must be rotated with the parent sample.
The equations to do so are given in the paper in Appendix A. Link to image of equations and example of problem.
The equation to transform the means applies a standard transformation matrix (calculated from the parent quaternion) to the 3D position elements and then a 'Grassman product' to the quaternion values. I am not familiar with the Grassman product but I assume it is applying the parent rotation to the child quaternion and experimentally seems to give the correct results.
However the equation for calculating the new covariance matrix is given as the inverse of the inverse of the original covariance * the rotation matrix (see the image link above). However this often gives invalid results (non-symmetric and negative values on the main diagonal). Note that in matlab I have attempted solving this using inv(RXi/cov_mat) as it is supposed to be more numerically stable.
I have found an alternative equation to rotate a covariance matrix which seems to work for the 3D position components but not for the quaternion elements (RXi * cov_mat * RXi^T).
What is causing the resultant covariance matrix to be invalid?