Data

numpy_to_disjoint

spektral.utils.numpy_to_disjoint(X_list, A_list, E_list=None)

Converts a batch of graphs stored in lists (X, A, and optionally E) to the disjoint mode.

Each entry i of the lists should be associated to the same graph, i.e., X_list[i].shape[0] == A_list[i].shape[0] == E_list[i].shape[0].

The method also computes the batch index I.

Arguments

  • X_list: a list of np.arrays of shape (N, F);

  • A_list: a list of np.arrays or sparse matrices of shape (N, N);

  • E_list: a list of np.arrays of shape (N, N, S);

Return

  • X_out: a rank 2 array of shape (n_nodes, F);
  • A_out: a rank 2 array of shape (n_nodes, n_nodes);
  • E_out: (only if E_list is given) a rank 2 array of shape (n_edges, S);
  • I_out: a rank 1 array of shape (n_nodes, );

numpy_to_batch

spektral.utils.numpy_to_batch(X_list, A_list, E_list=None)

Converts a batch of graphs stored in lists (X, A, and optionally E) to the batch mode by zero-padding all X, A and E matrices to have the same node dimensions (N_max).

Each entry i of the lists should be associated to the same graph, i.e., X_list[i].shape[0] == A_list[i].shape[0] == E_list[i].shape[0].

Note that if A_list contains sparse matrices, they will be converted to dense np.arrays, which can be expensice.

Arguments

  • X_list: a list of np.arrays of shape (N, F);

  • A_list: a list of np.arrays or sparse matrices of shape (N, N);

  • E_list: a list of np.arrays of shape (N, N, S);

Return

  • X_out: a rank 3 array of shape (batch, N_max, F);
  • A_out: a rank 2 array of shape (batch, N_max, N_max);
  • E_out: (only if E_list if given) a rank 2 array of shape (batch, N_max, N_max, S);

batch_iterator

spektral.utils.batch_iterator(data, batch_size=32, epochs=1, shuffle=True)

Iterates over the data for the given number of epochs, yielding batches of size batch_size.

Arguments

  • data: np.array or list of np.arrays with the same first dimension;

  • batch_size: number of samples in a batch;

  • epochs: number of times to iterate over the data;

  • shuffle: whether to shuffle the data at the beginning of each epoch

Return
Batches of size batch_size.