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:
**kwargs (dict) – Additional keyword arguments.
cm_mat (np.ndarray) – The numpy array.
inplace (bool) – Inplace flag.
is_triu_sym (bool) – Is triu sym flag.
cm_coo (sp.coo_matrix) – The coo matrix.
cm_df (pd.DataFrame) – The dataframe.
ratio (float) – Ratio.
min_k (int, optional) – Min k.
data1 (np.ndarray) – First data.
data2 (np.ndarray) – Second data.
op (str) – Operation.
ret_unique_ids (bool) – Return unique ids.
axis (int) – Axis.
cm_mat1 (np.ndarray) – First matrix.
cm_mat2 (np.ndarray) – Second matrix.
cm_coo1 (sp.coo_matrix) – First coo.
cm_coo2 (sp.coo_matrix) – Second coo.
alpha (float) – Alpha.
data (np.ndarray) – Data.
na_inf_val (float) – NA inf val.
col_ids_colname (str) – Col ID colname.
row_ids_colname (str) – Row ID colname.
use_pseudo (bool) – Use pseudo.
D (np.ndarray) – The Euclidean Distance Matrix.
alpha – The exponent value.
- Returns:
The contact matrix.
- Return type:
np.ndarray
Examples
- 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:
**kwargs (dict) – Additional keyword arguments.
cm_mat (np.ndarray) – The numpy array.
inplace (bool) – Inplace flag.
is_triu_sym (bool) – Is triu sym flag.
cm_coo (sp.coo_matrix) – The coo matrix.
cm_df (pd.DataFrame) – The dataframe.
ratio (float) – Ratio.
min_k (int, optional) – Min k.
data1 (np.ndarray) – First data.
data2 (np.ndarray) – Second data.
op (str) – Operation.
ret_unique_ids (bool) – Return unique ids.
axis (int) – Axis.
cm_mat1 (np.ndarray) – First matrix.
cm_mat2 (np.ndarray) – Second matrix.
cm_coo1 (sp.coo_matrix) – First coo.
cm_coo2 (sp.coo_matrix) – Second coo.
alpha (float) – Alpha.
data (np.ndarray) – Data.
na_inf_val (float) – NA inf val.
col_ids_colname (str) – Col ID colname.
row_ids_colname (str) – Row ID colname.
use_pseudo (bool) – Use pseudo.
D (torch.Tensor) – The distance matrix.
alpha – The alpha value used for the computation.
- Returns:
The computed contact matrix.
- Return type:
torch.Tensor
Examples
Authors#
Yeremia G. Adhisantoso (adhisant@tnt.uni-hannover.de)
Qwen2.5 72B - 4.25bpw
Examples
Not applicable.
- 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:
**kwargs (dict) – Additional keyword arguments.
cm_mat (np.ndarray) – The numpy array.
inplace (bool) – Inplace flag.
is_triu_sym (bool) – Is triu sym flag.
cm_coo (sp.coo_matrix) – The coo matrix.
cm_df (pd.DataFrame) – The dataframe.
ratio (float) – Ratio.
min_k (int, optional) – Min k.
data1 (np.ndarray) – First data.
data2 (np.ndarray) – Second data.
op (str) – Operation.
ret_unique_ids (bool) – Return unique ids.
axis (int) – Axis.
cm_mat1 (np.ndarray) – First matrix.
cm_mat2 (np.ndarray) – Second matrix.
cm_coo1 (sp.coo_matrix) – First coo.
cm_coo2 (sp.coo_matrix) – Second coo.
alpha (float) – Alpha.
data (np.ndarray) – Data.
na_inf_val (float) – NA inf val.
col_ids_colname (str) – Col ID colname.
row_ids_colname (str) – Row ID colname.
use_pseudo (bool) – Use pseudo.
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
Examples
Authors#
Yeremia G. Adhisantoso (adhisant@tnt.uni-hannover.de)
Qwen2.5 72B - 4.25bpw
Examples
Not applicable.
- 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.
- Parameters:
**kwargs (dict) – Additional keyword arguments.
cm_mat (np.ndarray) – The numpy array.
inplace (bool) – Inplace flag.
is_triu_sym (bool) – Is triu sym flag.
cm_coo (sp.coo_matrix) – The coo matrix.
cm_df (pd.DataFrame) – The dataframe.
ratio (float) – Ratio.
min_k (int, optional) – Min k.
data1 (np.ndarray) – First data.
data2 (np.ndarray) – Second data.
op (str) – Operation.
ret_unique_ids (bool) – Return unique ids.
axis (int) – Axis.
cm_mat1 (np.ndarray) – First matrix.
cm_mat2 (np.ndarray) – Second matrix.
cm_coo1 (sp.coo_matrix) – First coo.
cm_coo2 (sp.coo_matrix) – Second coo.
alpha (float) – Alpha.
data (np.ndarray) – Data.
na_inf_val (float) – NA inf val.
col_ids_colname (str) – Col ID colname.
row_ids_colname (str) – Row ID colname.
use_pseudo (bool) – Use pseudo.
P (np.ndarray) – The input matrix.
row_ids (List[int]) – The indices of the rows to be used.
col_ids (List[int]) – The indices of the columns to be used.
- Returns:
The Euclidean Distance Matrix.
- Return type:
np.ndarray
Examples
Authors#
Yeremia G. Adhisantoso (adhisant@tnt.uni-hannover.de)
Qwen2.5 72B - 4.25bpw
Examples
Not applicable.
- 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:
**kwargs (dict) – Additional keyword arguments.
cm_mat (np.ndarray) – The numpy array.
inplace (bool) – Inplace flag.
is_triu_sym (bool) – Is triu sym flag.
cm_coo (sp.coo_matrix) – The coo matrix.
cm_df (pd.DataFrame) – The dataframe.
ratio (float) – Ratio.
min_k (int, optional) – Min k.
data1 (np.ndarray) – First data.
data2 (np.ndarray) – Second data.
op (str) – Operation.
ret_unique_ids (bool) – Return unique ids.
axis (int) – Axis.
cm_mat1 (np.ndarray) – First matrix.
cm_mat2 (np.ndarray) – Second matrix.
cm_coo1 (sp.coo_matrix) – First coo.
cm_coo2 (sp.coo_matrix) – Second coo.
alpha (float) – Alpha.
data (np.ndarray) – Data.
na_inf_val (float) – NA inf val.
col_ids_colname (str) – Col ID colname.
row_ids_colname (str) – Row ID colname.
use_pseudo (bool) – Use pseudo.
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
Examples
Authors#
Yeremia G. Adhisantoso (adhisant@tnt.uni-hannover.de)
Qwen2.5 72B - 4.25bpw
Examples
Not applicable.
- 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:
**kwargs (dict) – Additional keyword arguments.
cm_mat (np.ndarray) – The numpy array.
inplace (bool) – Inplace flag.
is_triu_sym (bool) – Is triu sym flag.
cm_coo (sp.coo_matrix) – The coo matrix.
cm_df (pd.DataFrame) – The dataframe.
ratio (float) – Ratio.
min_k (int, optional) – Min k.
data1 (np.ndarray) – First data.
data2 (np.ndarray) – Second data.
op (str) – Operation.
ret_unique_ids (bool) – Return unique ids.
axis (int) – Axis.
cm_mat1 (np.ndarray) – First matrix.
cm_mat2 (np.ndarray) – Second matrix.
cm_coo1 (sp.coo_matrix) – First coo.
cm_coo2 (sp.coo_matrix) – Second coo.
alpha (float) – Alpha.
data (np.ndarray) – Data.
na_inf_val (float) – NA inf val.
col_ids_colname (str) – Col ID colname.
row_ids_colname (str) – Row ID colname.
use_pseudo (bool) – Use pseudo.
P_rows (np.ndarray) – The row vectors.
P_cols (np.ndarray) – The column vectors.
- Returns:
The Gram matrix.
- Return type:
np.ndarray
Examples
Authors#
Yeremia G. Adhisantoso (adhisant@tnt.uni-hannover.de)
Qwen2.5 72B - 4.25bpw
Examples
Not applicable.
- 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:
**kwargs (dict) – Additional keyword arguments.
cm_mat (np.ndarray) – The numpy array.
inplace (bool) – Inplace flag.
is_triu_sym (bool) – Is triu sym flag.
cm_coo (sp.coo_matrix) – The coo matrix.
cm_df (pd.DataFrame) – The dataframe.
ratio (float) – Ratio.
min_k (int, optional) – Min k.
data1 (np.ndarray) – First data.
data2 (np.ndarray) – Second data.
op (str) – Operation.
ret_unique_ids (bool) – Return unique ids.
axis (int) – Axis.
cm_mat1 (np.ndarray) – First matrix.
cm_mat2 (np.ndarray) – Second matrix.
cm_coo1 (sp.coo_matrix) – First coo.
cm_coo2 (sp.coo_matrix) – Second coo.
alpha (float) – Alpha.
data (np.ndarray) – Data.
na_inf_val (float) – NA inf val.
col_ids_colname (str) – Col ID colname.
row_ids_colname (str) – Row ID colname.
use_pseudo (bool) – Use pseudo.
P_rows (torch.Tensor) – The row tensor.
P_cols (torch.Tensor) – The column tensor.
- Returns:
The computed Gram matrix.
- Return type:
torch.Tensor
Examples
Authors#
Yeremia G. Adhisantoso (adhisant@tnt.uni-hannover.de)
Qwen2.5 72B - 4.25bpw
Examples
Not applicable.
- 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.
- Parameters:
**kwargs (dict) – Additional keyword arguments.
cm_mat (np.ndarray) – The numpy array.
inplace (bool) – Inplace flag.
is_triu_sym (bool) – Is triu sym flag.
cm_coo (sp.coo_matrix) – The coo matrix.
cm_df (pd.DataFrame) – The dataframe.
ratio (float) – Ratio.
min_k (int, optional) – Min k.
data1 (np.ndarray) – First data.
data2 (np.ndarray) – Second data.
op (str) – Operation.
ret_unique_ids (bool) – Return unique ids.
axis (int) – Axis.
cm_mat1 (np.ndarray) – First matrix.
cm_mat2 (np.ndarray) – Second matrix.
cm_coo1 (sp.coo_matrix) – First coo.
cm_coo2 (sp.coo_matrix) – Second coo.
alpha (float) – Alpha.
data (np.ndarray) – Data.
na_inf_val (float) – NA inf val.
col_ids_colname (str) – Col ID colname.
row_ids_colname (str) – Row ID colname.
use_pseudo (bool) – Use pseudo.
P (np.ndarray) – The input matrix.
reduction (str, optional) – The reduction method, by default ‘mean’. Supported methods are ‘mean’ and ‘sum’.
- Returns:
The reduced trace value.
- Return type:
Examples
Authors#
Yeremia G. Adhisantoso (adhisant@tnt.uni-hannover.de)
Qwen2.5 72B - 4.25bpw
Examples
Not applicable.