bundles / scipy latest / scipy / linalg / _procrustes / orthogonal_procrustes
function
scipy.linalg._procrustes:orthogonal_procrustes
source: /scipy/linalg/_procrustes.py :14
Signature
def orthogonal_procrustes ( A , B , check_finite = True ) Summary
Compute the matrix solution of the orthogonal (or unitary) Procrustes problem.
Extended Summary
Given matrices A and B of the same shape, find an orthogonal (or unitary in the case of complex input) matrix R that most closely maps A to B using the algorithm given in [1].
The documentation is written assuming array arguments are of specified "core" shapes. However, array argument(s) of this function may have additional "batch" dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see linalg_batch for details. Note that calls with zero-size batches are unsupported and will raise a ValueError.
Parameters
A: (M, N) array_likeMatrix to be mapped.
B: (M, N) array_likeTarget matrix.
check_finite: bool, optionalWhether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.
Returns
R: (N, N) ndarrayThe matrix solution of the orthogonal Procrustes problem. Minimizes the Frobenius norm of
(A @ R) - B, subject toR.conj().T @ R = I.scale: floatSum of the singular values of
A.conj().T @ B.
Raises
: ValueErrorIf the input array shapes don't match or if check_finite is True and the arrays contain Inf or NaN.
Notes
Note that unlike higher level Procrustes analyses of spatial data, this function only uses orthogonal transformations like rotations and reflections, and it does not use scaling or translation.
Array API Standard Support
orthogonal_procrustes has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ✅ JAX ⚠️ no JIT ⚠️ no JIT Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
import numpy as np from scipy.linalg import orthogonal_procrustes A = np.array([[ 2, 0, 1], [-2, 0, 0]])✓
R, sca = orthogonal_procrustes(A, np.fliplr(A))
✓R sca✗
shape = (4, 4) rng = np.random.default_rng(589234981235) A = rng.random(shape) + rng.random(shape)*1j Q = rng.random(shape) + rng.random(shape)*1j Q, _ = np.linalg.qr(Q) B = A @ Q✓
R, _ = orthogonal_procrustes(A, B) np.allclose(R, Q)✓
Aliases
-
scipy.linalg.orthogonal_procrustes