probinet.input.preprocessing#

It provides functions for preprocessing and constructing adjacency tensors from NetworkX graphs. The script facilitates the creation of both dense and sparse adjacency tensors, considering edge weights, and ensures proper formatting of input data tensors.

Functions

create_adjacency_tensor_from_graph_list(A[, ...])

Create the numpy adjacency tensor of a networkX graph.

create_sparse_adjacency_tensor_from_graph_list(A)

Create the sparse tensor adjacency tensor of a networkX graph using TensorLy.

preprocess_adjacency_tensor(A)

Pre-process input data tensor.

preprocess_data_matrix(X)

Pre-process input data matrix.

probinet.input.preprocessing.create_adjacency_tensor_from_graph_list(A: List[MultiDiGraph], nodes: List | None = None, calculate_reciprocity: bool = True, label: str = 'weight') ndarray | Tuple[ndarray, List[Any]][source]#

Create the numpy adjacency tensor of a networkX graph.

Parameters:
  • A (list) – List of MultiDiGraph NetworkX objects.

  • nodes (list, optional) – List of nodes IDs. If not provided, use all nodes in the first graph as the default.

  • calculate_reciprocity (bool, optional) – Whether to calculate reciprocity or not.

  • label (str, optional) – The edge attribute key used to determine the weight of the edges.

Returns:

B – Graph adjacency tensor. If calculate_reciprocity is True, returns a tuple with B and a list of reciprocity values.

Return type:

ndarray or Tuple[ndarray, List[Any]]

Raises:

AssertionError – If any graph in A has a different set of vertices than the first graph. If any weight in B is not an integer.

probinet.input.preprocessing.create_sparse_adjacency_tensor_from_graph_list(A: List[MultiDiGraph], calculate_reciprocity: bool = False) COO | Tuple[COO, COO, ndarray, List[Any]][source]#

Create the sparse tensor adjacency tensor of a networkX graph using TensorLy.

Parameters:
  • A (list) – List of MultiDiGraph NetworkX objects.

  • calculate_reciprocity (bool, optional) – Whether to calculate and return the reciprocity values..

Returns:

data – Graph adjacency tensor. If calculate_reciprocity is True, returns a tuple with the adjacency tensor, its transpose, an array with values of entries A[j, i] given non-zero entry (i, j), and a list of reciprocity values.

Return type:

SparseTensor or Tuple[SparseTensor, SparseTensor, ndarray, List[Any]]

probinet.input.preprocessing.preprocess_adjacency_tensor(A: ndarray) COO | ndarray[source]#

Pre-process input data tensor.

If the input is sparse, returns an integer sparse tensor (COO). Otherwise, returns an integer dense tensor (ndarray).

Parameters:

A (ndarray) – Input data tensor.

Returns:

A – Pre-processed data. If the input is sparse, returns an integer sparse tensor (COO). Otherwise, returns an integer dense tensor (ndarray).

Return type:

COO or ndarray

probinet.input.preprocessing.preprocess_data_matrix(X)[source]#

Pre-process input data matrix. If the input is sparse, returns a scipy sparse matrix. Otherwise, returns a numpy array.

Parameters:

X (ndarray) – Input data (matrix).

Returns:

X – Pre-processed data. If the input is sparse, returns a scipy sparse matrix. Otherwise, returns a numpy array.

Return type:

scipy sparse matrix/ndarray