probinet.utils.matrix_operations#
This module contains functions that perform matrix operations, such as the Khatri-Rao product.
Functions
|
Compute the mean lambda0_ij for all entries. |
|
Given a matrix, it returns the same matrix normalized by row. |
|
Compute the Khatri-Rao product (sparse version). |
|
Compute the Khatri-Rao product (sparse version) with the assumption of assortativity. |
Compute the transpose of a matrix. |
|
Given M tensor, it returns its transpose: for each dimension a, compute the transpose ij->ji. |
- probinet.utils.matrix_operations.Exp_ija_matrix(u: ndarray, v: ndarray, w: ndarray) ndarray [source]#
Compute the mean lambda0_ij for all entries.
- Parameters:
u (ndarray) – Out-going membership matrix.
v (ndarray) – In-coming membership matrix.
w (ndarray) – Affinity matrix.
- Returns:
M – Mean lambda0_ij for all entries.
- Return type:
ndarray
- probinet.utils.matrix_operations.normalize_nonzero_membership(u: ndarray, axis: int | None = 1) ndarray [source]#
Given a matrix, it returns the same matrix normalized by row.
- Parameters:
u (ndarray) – Numpy Matrix.
axis (Optional[int]) – Axis along which the matrix should be normalized.
- Return type:
The matrix normalized by row.
- probinet.utils.matrix_operations.sp_uttkrp(vals: ndarray, subs: Tuple[ndarray], m: int, u: ndarray, v: ndarray, w: ndarray, temporal: bool = True) ndarray [source]#
Compute the Khatri-Rao product (sparse version).
- Parameters:
vals (ndarray) – Values of the non-zero entries.
subs (tuple) – Indices of elements that are non-zero. It is a n-tuple of array-likes and the length of tuple n must be equal to the dimension of tensor.
m (int) – Mode in which the Khatri-Rao product of the membership matrix is multiplied with the tensor: if 1 it works with the matrix u; if 2 it works with v.
u (ndarray) – Out-going membership matrix.
v (ndarray) – In-coming membership matrix.
w (ndarray) – Affinity tensor.
temporal (bool) – Flag to determine if the function should behave in a temporal manner.
- Returns:
out – Matrix which is the result of the matrix product of the unfolding of the tensor and the Khatri-Rao product of the membership matrix.
- Return type:
ndarray
- probinet.utils.matrix_operations.sp_uttkrp_assortative(vals: ndarray, subs: Tuple[ndarray], m: int, u: ndarray, v: ndarray, w: ndarray, temporal: bool = False) ndarray [source]#
Compute the Khatri-Rao product (sparse version) with the assumption of assortativity.
- Parameters:
vals (ndarray) – Values of the non-zero entries.
subs (tuple) – Indices of elements that are non-zero. It is a n-tuple of array-likes and the length of tuple n must be equal to the dimension of tensor.
m (int) – Mode in which the Khatri-Rao product of the membership matrix is multiplied with the tensor: if 1 it works with the matrix u; if 2 it works with v.
u (ndarray) – Out-going membership matrix.
v (ndarray) – In-coming membership matrix.
w (ndarray) – Affinity tensor.
temporal (bool) – If True, use the static version of the function.
- Returns:
out – Matrix which is the result of the matrix product of the unfolding of the tensor and the Khatri-Rao product of the membership matrix.
- Return type:
ndarray