nag_mv_procustes (g03bcc) (PDF version)
g03 Chapter Contents
g03 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_mv_procustes (g03bcc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_mv_procustes (g03bcc) computes Procrustes rotations in which an orthogonal rotation is found so that a transformed matrix best matches a target matrix.

2  Specification

#include <nag.h>
#include <nagg03.h>
void  nag_mv_procustes (Nag_TransNorm stand, Nag_RotationScale pscale, Integer n, Integer m, double x[], Integer tdx, double y[], Integer tdy, double yhat[], double r[], Integer tdr, double *alpha, double *rss, double res[], NagError *fail)

3  Description

Let X  and Y  be n  by m  matrices. They can be considered as representing sets of n  points in an m -dimensional space. The X  matrix may be a matrix of loadings from say factor or canonical variate analysis, and the Y  matrix may be a postulated pattern matrix or the loadings from a different sample. The problem is to relate the two sets of points without disturbing the relationships between the points in each set. This can be achieved by translating, rotating and scaling the sets of points. The Y  matrix is considered as the target matrix and the X  matrix is rotated to match that matrix.
First the two sets of points are translated so that their centroids are at the origin to give X c  and Y c , i.e., the matrices will have zero column means. Then the rotation of the translated X c  matrix which minimizes the sum of squared distances between corresponding points in the two sets is found. This is computed from the singular value decomposition of the matrix:
XcT Y c = UDVT ,
where U  and V  are orthogonal matrices and D  is a diagonal matrix. The matrix of rotations, R , is computed as:
R = UVT .
After rotation, a scaling or dilation factor, α , may be estimated by least squares. Thus, the final set of points that best match Y c  is given by:
Y ^ c = α X c R .
Before rotation, both sets of points may be normalized to have unit sums of squares or the X  matrix may be normalized to have the same sum of squares as the Y  matrix. After rotation, the results may be translated to the original Y  centroid.
The i th residual, r i , is given by the distance between the point given in the i th row of Y  and the point given in the i th row of Y ^ . The residual sum of squares is also computed.

4  References

Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
Lawley D N and Maxwell A E (1971) Factor Analysis as a Statistical Method (2nd Edition) Butterworths

5  Arguments

1:     standNag_TransNormInput
On entry: indicates if translation/normalization is required.
stand=Nag_NoTransNorm
No translation or normalization.
stand=Nag_Orig
Translation to the origin.
stand=Nag_OrigCentroid
Translation to the origin and then to the Y  centroid after rotation.
stand=Nag_Norm
Unit normalization.
stand=Nag_OrigNorm
Translation and normalization.
stand=Nag_OrigNormCentroid
Translation and normalization to Y  scale, then translation to the Y  centroid after rotation.
Constraint: stand=Nag_NoTransNorm, Nag_Orig, Nag_OrigCentroid, Nag_Norm, Nag_OrigNorm or Nag_OrigNormCentroid.
2:     pscaleNag_RotationScaleInput
On entry: indicates if least squares scaling is applied after rotation.
pscale=Nag_LsqScale
Scaling is to be applied.
pscale=Nag_NotLsqScale
No scaling is applied.
Constraint: pscale=Nag_LsqScale or Nag_NotLsqScale.
3:     nIntegerInput
On entry: the number of points, n .
Constraint: n1 .
4:     mIntegerInput
On entry: the number of dimensions, m .
Constraints:
  • m1 ;
  • mn .
5:     x[n×tdx]doubleInput/Output
Note: the i,jth element of the matrix X is stored in x[i-1×tdx+j-1].
On entry: the matrix to be rotated, X .
On exit: if stand=Nag_NoTransNorm, x will be unchanged.
If stand=Nag_Orig, Nag_OrigCentroid, Nag_OrigNorm or Nag_OrigNormCentroid, x will be translated to have zero column means.
If stand=Nag_Norm or Nag_OrigNorm, x will be scaled to have unit sum of squares.
If stand=Nag_OrigNormCentroid, x will be scaled to have the same sum of squares as y.
6:     tdxIntegerInput
On entry: the stride separating matrix column elements in the array x.
Constraint: tdxm .
7:     y[n×tdy]doubleInput/Output
Note: the i,jth element of the matrix Y is stored in y[i-1×tdy+j-1].
On entry: the target matrix, Y .
On exit: if stand=Nag_NoTransNorm, then y will be unchanged.
If stand=Nag_Orig or Nag_OrigNorm, then y will be translated to have zero column means.
If stand=Nag_Norm or Nag_OrigNorm, then y will be scaled to have unit sum of squares.
If stand=Nag_OrigCentroid or Nag_OrigNormCentroid, then y will be translated and then after rotation, translated back. The output y should be the same as the input y except for rounding errors.
8:     tdyIntegerInput
On entry: the stride separating matrix column elements in the arrays y, yhat.
Constraint: tdym .
9:     yhat[n×tdy]doubleOutput
Note: the i,jth element of the matrix is stored in yhat[i-1×tdy+j-1].
On exit: the fitted matrix, Y ^ .
10:   r[m×tdr]doubleOutput
Note: the i,jth element of the matrix R is stored in r[i-1×tdr+j-1].
On exit: the matrix of rotations, R , see Section 9.
11:   tdrIntegerInput
On entry: the stride separating matrix column elements in the array r.
Constraint: tdrm .
12:   alphadouble *Output
On exit: if pscale=Nag_LsqScale the scaling factor, α ; otherwise alpha is not set.
13:   rssdouble *Output
On exit: the residual sum of squares.
14:   res[n]doubleOutput
On exit: the residuals, r i , for i=1,2,,n.
15:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_2_INT_ARG_GT
On entry, m=value  while n=value . These arguments must satisfy mn .
NE_2_INT_ARG_LT
On entry, tdr=value  while m=value . These arguments must satisfy tdrm .
On entry, tdx=value  while m=value . These arguments must satisfy tdxm .
On entry, tdy=value  while m=value . These arguments must satisfy tdym .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BAD_PARAM
On entry, argument pscale had an illegal value.
On entry, argument stand had an illegal value.
NE_INT_ARG_LT
On entry, m=value.
Constraint: m1.
On entry, n=value.
Constraint: n1.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_LSQ_SCAL_ZERO_PTS
The fitted matrix Y ^ ,  contains only zero-points when least squares scaling is applied.
NE_NORM_ZERO_PTS
On entry, either x or y contains only zero-points (possibly after translation) when normalization is to be applied.
NE_SVD_NOT_CONV
The singular value decomposition has failed to converge. This is an unlikely error exit.

7  Accuracy

The accuracy of the calculation of the rotation matrix largely depends upon the singular value decomposition. See the f08 Chapter Introduction for further details.

8  Parallelism and Performance

Not applicable.

9  Further Comments

Note that if the matrix XcT Y  is not of full rank, then the matrix of rotations, R , may not be unique even if there is a unique solution in terms of the rotated matrix, Y ^ c . The matrix R  may also include reflections as well as pure rotations, see Krzanowski (1990).
If the column dimensions of the X  and Y  matrices are not equal, the smaller of the two should be supplemented by columns of zeros. Adding a column of zeros to both X  and Y  will have the effect of allowing reflections as well as rotations.

10  Example

Three points representing the vertices of a triangle in two dimensions are input. The points are translated and rotated to match the triangle given by (0,0),(1,0),(0,2) and scaling is applied after rotation. The target matrix and fitted matrix are printed along with additional information.

10.1  Program Text

Program Text (g03bcce.c)

10.2  Program Data

Program Data (g03bcce.d)

10.3  Program Results

Program Results (g03bcce.r)


nag_mv_procustes (g03bcc) (PDF version)
g03 Chapter Contents
g03 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2014