G03BCF computes Procrustes rotations in which an orthogonal rotation is found so that a transformed matrix best matches a target matrix.
SUBROUTINE G03BCF ( |
STAND, PSCALE, N, M, X, LDX, Y, LDY, YHAT, R, LDR, ALPHA, RSS, RES, WK, IFAIL) |
INTEGER |
N, M, LDX, LDY, LDR, IFAIL |
REAL (KIND=nag_wp) |
X(LDX,M), Y(LDY,M), YHAT(LDY,M), R(LDR,M), ALPHA, RSS, RES(N), WK(M*M+7*M) |
CHARACTER(1) |
STAND, PSCALE |
|
First the two sets of points are translated so that their centroids are at the origin to give
and
, i.e., the matrices will have zero column means. Then the rotation of the translated
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:
where
and
are orthogonal matrices and
is a diagonal matrix. The matrix of rotations,
, is computed as:
After rotation, a scaling or dilation factor,
, may be estimated by least squares. Thus, the final set of points that best match
is given by:
Before rotation, both sets of points may be normalized to have unit sums of squares or the
matrix may be normalized to have the same sum of squares as the
matrix. After rotation, the results may be translated to the original
centroid.
- 1: STAND – CHARACTER(1)Input
On entry: indicates if translation/normalization is required.
- There is no translation or normalization.
- There is translation to the origin (i.e., to zero).
- There is translation to origin and then to the centroid after rotation.
- There is unit normalization.
- There is translation and normalization (i.e., there is standardization).
- There is translation and normalization to scale, then translation to the centroid after rotation (i.e., they are matched).
Constraint:
, , , , or .
- 2: PSCALE – CHARACTER(1)Input
On entry: indicates if least squares scaling is to be applied after rotation.
- Scaling is applied.
- No scaling is applied.
Constraint:
or .
- 3: N – INTEGERInput
On entry: , the number of points.
Constraint:
.
- 4: M – INTEGERInput
On entry: , the number of dimensions.
Constraint:
.
- 5: X(LDX,M) – REAL (KIND=nag_wp) arrayInput/Output
On entry: , the matrix to be rotated.
On exit: if
,
X will be unchanged.
If
,
,
or
,
X will be translated to have zero column means.
If
or
,
X will be scaled to have unit sum of squares.
If
,
X will be scaled to have the same sum of squares as
Y.
- 6: LDX – INTEGERInput
On entry: the first dimension of the array
X as declared in the (sub)program from which G03BCF is called.
Constraint:
.
- 7: Y(LDY,M) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the target matrix, .
On exit: if
,
Y will be unchanged.
If
or
,
Y will be translated to have zero column means.
If
or
,
Y will be scaled to have unit sum of squares.
If
or
,
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: LDY – INTEGERInput
On entry: the first dimension of the arrays
Y and
YHAT as declared in the (sub)program from which G03BCF is called.
Constraint:
.
- 9: YHAT(LDY,M) – REAL (KIND=nag_wp) arrayOutput
On exit: the fitted matrix, .
- 10: R(LDR,M) – REAL (KIND=nag_wp) arrayOutput
On exit: the matrix of rotations,
, see
Section 8.
- 11: LDR – INTEGERInput
On entry: the first dimension of the array
R as declared in the (sub)program from which G03BCF is called.
Constraint:
.
- 12: ALPHA – REAL (KIND=nag_wp)Output
On exit: if
the scaling factor,
; otherwise
ALPHA is not set.
On exit: the residual sum of squares.
- 14: RES(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the residuals,
, for .
- 15: WK() – REAL (KIND=nag_wp) arrayWorkspace
- 16: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
The accuracy of the calculation of the rotation matrix largely depends upon the singular value decomposition. See the
F08 Chapter Introduction for further details.
Note that if the matrix
is not of full rank, then the matrix of rotations,
, may not be unique even if there is a unique solution in terms of the rotated matrix,
. The matrix
may also include reflections as well as pure rotations, see
Krzanowski (1990).
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 , , and scaling is applied after rotation. The target matrix and fitted matrix are printed along with additional information.