ugnn.utils package

Submodules

ugnn.utils.masks module

ugnn.utils.masks.mask_mix(mask_1, mask_2, seed=0)[source]
ugnn.utils.masks.mask_split(mask, split_props, seed=0, regime='transductive')[source]

Split a mask into train/valid/calib/test based on the specified regime.

Parameters:
  • mask (np.ndarray) – A boolean mask of shape (n, T), where n is the number of nodes and T is the number of time steps.

  • split_props (list of float) – Proportions for splitting the data into train/valid/calib/test. The proportions should sum to 1.

  • seed (int, optional) – Random seed for reproducibility. Defaults to 0.

  • regime (str, optional) – Splitting regime, either “transductive” or “semi-inductive”. Defaults to “transductive”.

Returns:

A list of boolean masks for each split (train, valid, calib, test).

Each mask has the same shape as the input mask.

Return type:

list of np.ndarray

ugnn.utils.masks.non_zero_degree_mask(As, n, T)[source]

Create a data mask which removes nodes with zero connections at each time step.

Parameters:
  • As (list of np.ndarray) – List of adjacency matrices for each time step.

  • n (int) – Number of nodes.

  • T (int) – Number of time steps.

Returns:

A boolean mask indicating usable node/time pairs.

Return type:

np.ndarray

ugnn.utils.masks.pad_unfolded_mask(mask, n)[source]

Padding required due to the n extra anchor nodes introduced in the unfolded representation.

These nodes are not included in training.

Parameters:
  • mask (np.ndarray) – The original mask.

  • n (int) – The number of nodes.

Returns:

The padded mask.

Return type:

np.ndarray

ugnn.utils.metrics module

ugnn.utils.metrics.accuracy(output: Tensor, data: Data, test_mask: Tensor) float[source]

Calculate the accuracy of predictions.

Parameters:
  • output (Tensor) – Model output logits.

  • data (Data) – Graph data containing ground truth labels.

  • test_mask (Tensor) – Mask indicating test nodes.

Returns:

Accuracy of the predictions.

Return type:

float

ugnn.utils.metrics.avg_set_size(pred_sets: ndarray) float[source]

Calculate the average size of prediction sets.

Parameters:
  • pred_sets (np.ndarray) – Array of prediction sets.

  • test_mask (np.ndarray) – Mask indicating test nodes.

Returns:

Average size of prediction sets.

Return type:

float

ugnn.utils.metrics.coverage(pred_sets: ndarray[bool], data: Data, test_mask: ndarray) float[source]

Calculate the coverage of prediction sets.

Parameters:
  • pred_sets (np.ndarray) – Array of prediction sets.

  • data (Data) – Graph data containing ground truth labels.

  • test_mask (np.ndarray) – Mask indicating test nodes.

Returns:

Coverage of the prediction sets.

Return type:

float

Module contents