n-Dimensional rotation matrix generation algorithm
High-dimensional spaces frequently occur in mathematics and the sciences, for example, N-dimensional feature space, which presents input signals of a neural network or a collection of N-dimensional parameters for multidimensional data analysis. Rotation is one of the rigid transformations in geometrical space that preserves the length of vectors and can be presented using matrix operations like Y = M.X, where X and Y are input and output vectors respectively, and M is the rotation matrix.
Definition of the task
Let's say that we have two n-dimensional vectors X and Y, having the same dimension, X, Y RN. We want to obtain a rotation matrix M that satisfies the equation
where has the same norm as X and the same direction as Y, i.e. (,).
Algorithms for generation of n-dimensional rotation matrix
Descriptions of three algorithms for the generation of an n-dimensional rotation matrix, which rotates a given n-dimensional vector X to the direction of a given n-dimensional vector Y, are given below.
Using rotation in coordinate plane of basis, defined by given vectors
One of the possibilities to generate rotation matrix M is to change the basis and to create a matrix that rotates vector X in the coordinate plane in which lie the two given vectors. This algorithm includes the following sequence of operations:
- Obtain two orthogonal vectors in the plane in which lie the two given vectors using the Gramm-Schmidt procedure.
- Enlarge this 2-dimensional basis to an N-dimensional basis B2, in which given vectors X, Y are transformed to и .
- Create a Givens matrix for , which performs rotation of in coordinate plane , to the direction of vector .
- Obtain rotation matrix M as where is the transformation matrix from the initial basis B to the constructed basis B2.
Using Householder reflection
Another way to generate a rotation matrix M is to use Householder reflection. If X and Y are vectors with the same norm, there exists an orthogonal symmetric matrix P such that where and . Matrix P is a matrix of reflection (not a rotation) because det P = –1 (which gives the name to the method). That’s why to obtain a matrix of rotation M, for which det M = 1, two subsequent reflections have to be performed. The matrix of rotation can be obtained as a multiplication of two matrices of reflection and as .
Using rotation of given vectors to the direction of one of coordinate axes
The third way to generate a rotation matrix M is to use rotation of given vectors to the direction of one of the coordinate axes (i.e. axis ). This algorithm (named NRMG algorithm) includes the following sequence of operations:
- Obtain rotation matrix , which rotates given vector to the direction of axis .
- Obtain rotation matrix , which rotates given vector to the direction of axis .
- Obtain rotation matrix , as a multiplication of by the inverse matrix of given as:
As it can be seen in the description above, the base operation of the NRMG algorithm is rotation of an n-dimensional vector to the direction of one of the coordinate axes (i.e. axis ).
Rotation of n-dimensional vector to the direction of axis
Rotation of a given n-dimensional vector to the direction of one of the coordinate axes (i.e. axis x1) can be performed by n − 1 subsequent rotations in coordinate planes (xn−k, xn−k+1), k = 1,…,n − 1 using multiplications by Givens matrices , where coefficients S = sin(θn−k) and C = cos(θn−k) are calculated as follows:
After every rotation, we get a vector that is orthogonal to the coordinate axis xn−k+1 in the current coordinate plane (xn−k, xn−k+1). Thus subsequent rotations in coordinate planes (xn−k, xn−k+1), k = 1,…,n − 1 give a vector that is orthogonal to all coordinate axes except x1. Rotation matrix is obtained as a multiplication of Givens matrices as follows:
The length of given vector X and angles of rotation θ1 , ... , θn−1 in the equation above are in reality coordinates of vector X, presented in hyperspherical coordinate system as XS = [rX, −θ1 , ... , −θn−1 ]T. Angles of rotation are included with a negative sign, because rotation of a given vector to the direction of the coordinate axis x1 calculates angles from the vector to the coordinate axes, while presentation of the vector in hyperspherical coordinate system calculates opposite direction angles – from axes to vector.
The advantage of using Givens rotations for rotation of an n-dimensional vector to the direction of one of the coordinate axes is that rotations in coordinate planes can easily be parallelised. This way the number of subsequent rotations in coordinate planes (i.e. the number of matrix multiplications) can be reduced to regardless of the fact that the total number of rotations in coordinate planes will remain equal to .
Notes
The time complexity of the algorithms described above depends on the "density" of given vectors X and Y. Like for the task of QR decomposition, for "dense" vectors Householder Reflection can be the most efficient, while for vectors that have many zero elements, the NRMG algorithm (which uses Givens rotations) can be more efficient than the other two.
References
- H.G. Golub, J.M. Ortega, 1993, Scientific Computing and Introduction with Parallel Computing, Academic Press, Inc., San Diego
- G. A. Korn, T.M. Korn, 1961, Mathematical Handbook for Scientists and Engineers (1st ed.), New York: McGraw-Hill. pp. 55–79.
- H. Friedberg, A. Insel, L. Spence, 1997, Linear Algebra (3rd ed), Prentice Hall.
- M. Cosnard, Y. Robert. Complexity of parallel QR factorization. J. ACM 33, 4 (August 1986), 712–723. DOI=10.1145/6490.214102, 1986
- A. H. Sameh, D. J. Kuck. On Stable Parallel Linear System Solvers. J. ACM 25, 1 (January 1978), 81–91. DOI= http://dx.doi.org/10.1145/322047.322054, 1978
- N. J. Higham, 1996, Accuracy and Stability of Numerical Algorithms, SIAM, Philadelfia
- G. W.Steward, 1976, The economical storage of plane rotations, Numer. Math, 25, 2 1976, 137–139
- N. K. Bose, 1985, Multidimensional Systems Theory: Progress, Directions, and Open Problems. D.Reidel Publishing Co., Dordrecht, The Netherland
- A. S. Householder, 1958, “Unitary triangularization of a nonsimetric matrix”, J. ACM 5, 339–342, 1958
- E. Anderson, 2000, “Discontinuous Plane Rotations and the Symmetric Eigenvalue Problem” LAPACK Working Note 150, University of Tennessee, UT-CS-00-454, December 4, 2000. page 2
- Zhelezov O. I. N-dimensional Rotation Matrix Generation Algorithm, American Journal of Computational and Applied Mathematics, Vol. 7 No. 2, 2017, pp. 51–57. doi: 10.5923/j.ajcam.20170702.04.
This article "N-Dimensional rotation matrix generation algorithm" is from Wikipedia. The list of its authors can be seen in its historical. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.
