probinet.utils.matrix_operations#

This module contains functions that perform matrix operations, such as the Khatri-Rao product.

Functions

Exp_ija_matrix(u, v, w)

Compute the mean lambda0_ij for all entries.

normalize_nonzero_membership(u[, axis])

Given a matrix, it returns the same matrix normalized by row.

sp_uttkrp(vals, subs, m, u, v, w[, temporal])

Compute the Khatri-Rao product (sparse version).

sp_uttkrp_assortative(vals, subs, m, u, v, w)

Compute the Khatri-Rao product (sparse version) with the assumption of assortativity.

transpose_matrix(M)

Compute the transpose of a matrix.

transpose_tensor(M)

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

probinet.utils.matrix_operations.transpose_matrix(M: ndarray) ndarray[source]#

Compute the transpose of a matrix.

Parameters:

M (ndarray) – Numpy matrix.

Return type:

Transpose of the matrix.

probinet.utils.matrix_operations.transpose_tensor(M: ndarray) ndarray[source]#

Given M tensor, it returns its transpose: for each dimension a, compute the transpose ij->ji.

Parameters:

M (ndarray) – Tensor with the mean lambda for all entries.

Return type:

Transpose version of M_aij, i.e. M_aji.