procrustes.utils

Utility Module.

procrustes.utils.compute_error(a: numpy.ndarray, b: numpy.ndarray, t: numpy.ndarray, s: Optional[numpy.ndarray] = None) float[source]

Return the one- or two-sided Procrustes (squared Frobenius norm) error.

The double-sided Procrustes error is defined as

\[\|\mathbf{S}\mathbf{A}\mathbf{T} - \mathbf{B}\|_{F}^2 = \text{Tr}\left[ \left(\mathbf{S}\mathbf{A}\mathbf{T} - \mathbf{B}\right)^\dagger \left(\mathbf{S}\mathbf{A}\mathbf{T} - \mathbf{B}\right)\right]\]

when \(\mathbf{S}\) is the identity matrix \(\mathbf{I}\), this is called the one-sided Procrustes error.

Parameters
  • a (ndarray) -- The 2D-array \(\mathbf{A}_{m \times n}\) which is going to be transformed.

  • b (ndarray) -- The 2D-array \(\mathbf{B}_{m \times n}\) representing the reference matrix.

  • t (ndarray) -- The 2D-array \(\mathbf{T}_{n \times n}\) representing the right-hand-side transformation matrix.

  • s (ndarray, optional) -- The 2D-array \(\mathbf{S}_{m \times m}\) representing the left-hand-side transformation matrix. If set to None, the one-sided Procrustes error is computed.

Returns

error -- The squared Frobenius norm of difference between the transformed array, \(\mathbf{S} \mathbf{A}\mathbf{T}\), and the reference array, \(\mathbf{B}\).

Return type

float

procrustes.utils.setup_input_arrays(array_a: numpy.ndarray, array_b: numpy.ndarray, remove_zero_col: bool, remove_zero_row: bool, pad: bool, translate: bool, scale: bool, check_finite: bool, weight: Optional[numpy.ndarray] = None) Tuple[numpy.ndarray, numpy.ndarray][source]

Check and process array inputs for the Procrustes transformation routines.

Usually, the precursor step before all Procrustes methods.

Parameters
  • array_a (npdarray) -- The 2D array \(A\) being transformed.

  • array_b (npdarray) -- The 2D reference array \(B\).

  • remove_zero_col (bool) -- If True, zero columns (values less than 1e-8) on the right side will be removed.

  • remove_zero_row (bool) -- If True, zero rows (values less than 1e-8) on the bottom will be removed.

  • pad (bool) -- Add zero rows (at the bottom) and/or columns (to the right-hand side) of matrices \(\mathbf{A}\) and \(\mathbf{B}\) so that they have the same shape.

  • translate (bool) -- If true, then translate both arrays \(A, B\) to the origin, ie columns of the arrays will have mean zero.

  • scale -- If True, both arrays are normalized to one with respect to the Frobenius norm, ie \(Tr(A^T A) = 1\).

  • check_finite (bool) -- If true, then checks if both arrays \(A, B\) are numpy arrays and two-dimensional.

  • weight (A list of ndarray or ndarray) -- A list of the weight arrays or one numpy array. When only on numpy array provided, it is assumed that the two arrays \(A\) and \(B\) share the same weight matrix.

Returns

Returns the padded arrays, in that they have the same matrix dimensions.

Return type

(ndarray, ndarray)

class procrustes.utils.ProcrustesResult[source]

Represents the Procrustes analysis result.

error

The Procrustes (squared Frobenius norm) error.

Type

float

new_a

The translated/scaled numpy ndarray \(\mathbf{A}\).

Type

ndarray

new_b

The translated/scaled numpy ndarray \(\mathbf{B}\).

Type

ndarray

t

The 2D-array \(\mathbf{T}\) representing the right-hand-side transformation matrix.

Type

ndarray

s

The 2D-array \(\mathbf{S}\) representing the left-hand-side transformation matrix. If set to None, the one-sided Procrustes was performed.

Type

ndarray

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(k[,d])

If key is not found, d is returned if given, otherwise KeyError is raised

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()