gunz_cm.preprocs.transforms#
Module contents#
Transformations between representations.
EDM (Euclidean Distance Matrix)
Gram Matrix
- gunz_cm.preprocs.transforms.comp_contacts(D: ndarray, alpha: float) ndarray[source]#
Compute the contact matrix from the Euclidean Distance Matrix (EDM) using the given alpha value.
Notes
The contact matrix is computed as the EDM raised to the power of 1/alpha.
- Parameters:
D (np.ndarray) – The Euclidean Distance Matrix.
alpha (float) – The exponent value.
- Returns:
The contact matrix.
- Return type:
np.ndarray
- gunz_cm.preprocs.transforms.comp_contacts_torch(D: Tensor, alpha: float) Tensor#
Compute the contact matrix from the distance matrix using the given alpha value.
Notes
The contact matrix is computed by raising the elements of the distance matrix to the power of 1/alpha.
- Parameters:
D (torch.Tensor) – The distance matrix.
alpha (float) – The alpha value used for the computation.
- Returns:
The computed contact matrix.
- Return type:
torch.Tensor
- gunz_cm.preprocs.transforms.comp_edm(P_rows: ndarray, P_cols: ndarray, G: numpy.ndarray | None = None) ndarray[source]#
Compute the Euclidean Distance Matrix (EDM) from the given row and column vectors.
Notes
The EDM is computed as the sum of the squared row and column vectors, minus twice the Gram matrix. If G is not provided, it is computed internally.
- Parameters:
P_rows (np.ndarray) – The row vectors.
P_cols (np.ndarray) – The column vectors.
G (Optional[np.ndarray], optional) – The precomputed Gram matrix, by default None.
- Returns:
The Euclidean Distance Matrix.
- Return type:
np.ndarray
- gunz_cm.preprocs.transforms.comp_edm_from_p(P: ndarray, row_ids: list[int], col_ids: list[int]) ndarray[source]#
Compute the Euclidean Distance Matrix (EDM) from the specified rows and columns of the matrix P.
Notes
The function extracts the specified rows and columns from the matrix P and computes the EDM using the comp_edm function.
- gunz_cm.preprocs.transforms.comp_edm_torch(P_rows: Tensor, P_cols: Tensor, G: torch.Tensor | None = None) Tensor#
Compute the Euclidean Distance Matrix (EDM) for the given row and column tensors.
Notes
The EDM is computed by summing the squared norms of the row and column tensors, and subtracting twice the Gram matrix. If the Gram matrix G is not provided, it is computed internally using comp_gram_mat.
- Parameters:
P_rows (torch.Tensor) – The row tensor.
P_cols (torch.Tensor) – The column tensor.
G (Optional[torch.Tensor], optional) – The precomputed Gram matrix, by default None.
- Returns:
The computed Euclidean Distance Matrix.
- Return type:
torch.Tensor
- gunz_cm.preprocs.transforms.comp_gram_mat(P_rows: ndarray, P_cols: ndarray) ndarray[source]#
Compute the Gram matrix from the given row and column vectors.
Notes
The Gram matrix is computed as the dot product of the row and column vectors.
- Parameters:
P_rows (np.ndarray) – The row vectors.
P_cols (np.ndarray) – The column vectors.
- Returns:
The Gram matrix.
- Return type:
np.ndarray
- gunz_cm.preprocs.transforms.comp_gram_mat_torch(P_rows: Tensor, P_cols: Tensor) Tensor#
Compute the Gram matrix for the given row and column tensors.
Notes
The Gram matrix is computed as the element-wise product of the row and column tensors, summed along the specified axis.
- Parameters:
P_rows (torch.Tensor) – The row tensor.
P_cols (torch.Tensor) – The column tensor.
- Returns:
The computed Gram matrix.
- Return type:
torch.Tensor
- gunz_cm.preprocs.transforms.comp_trace_P(P: ndarray, reduction: str = 'mean') float[source]#
Compute the trace of the matrix P with the specified reduction method.
Notes
The trace is computed as the sum of the squares of the elements of P. The reduction method can be ‘mean’ or ‘sum’. If an unsupported reduction method is provided, a NotImplementedError is raised.