numpy_matrix_zone_translation#

caf.toolkit.translation.numpy_matrix_zone_translation(matrix, translation, *, col_translation=None, translation_dtype=None, check_shapes=True, check_totals=True)[source]#

Efficiently translates a matrix between index systems.

Uses the given translation matrices to translate a matrix of values from one index system to another. This has been written in pure numpy operations. NOTE: The algorithm optimises for speed by expanding the translation across 3 dimensions. For large matrices this can result in MemoryError. In these cases the algorithm will fall back to a slower, more memory efficient algorithm when slow_fallback is True. translation_dtype can be set to a smaller data type, sacrificing accuracy for speed.

Parameters:
  • matrix (ndarray) – The matrix to translate. Must be square. e.g. (n_in, n_in)

  • translation (ndarray) – A matrix defining the weights to use to translate. Should be of shape (n_in, n_out), where the output matrix shape will be (n_out, n_out). A value of 0.5 in translation[0, 2] Would mean that 50% of the value in index 0 of vector should end up in index 2 of the output. When col_translation is None, this defines the translation to use for both the rows and columns. When col_translation is set, this defines the translation to use for the rows.

  • col_translation (ndarray | None) – A matrix defining the weights to use to translate the columns. Takes an input of the same format as translation. When None, translation is used as the column translation.

  • translation_dtype (dtype | None) – The numpy datatype to use to do the translation. If None, then the dtype of the matrix is used. Where such high precision isn’t needed, a more memory and time efficient data type can be used.

  • check_shapes (bool) – Whether to check that the input and translation shapes look correct. Optionally set to False if checks have been done externally to speed up runtime.

  • check_totals (bool) – Whether to check that the input and output matrices sum to the same total.

Returns:

matrix, translated into (n_out, n_out) shape via translation.

Return type:

translated_matrix

Raises:

ValueError: – Will raise an error if matrix is not a square array, or if translation does not have the same number of rows as matrix.