utils

class cogdl.utils.utils.ArgClass[source]

Bases: object

cogdl.utils.utils.add_remaining_self_loops(edge_index, edge_weight=None, fill_value=1, num_nodes=None)[source]
cogdl.utils.utils.add_self_loops(edge_index, edge_weight=None, fill_value=1, num_nodes=None)[source]
cogdl.utils.utils.alias_draw(J, q)[source]

Draw sample from a non-uniform discrete distribution using alias sampling.

cogdl.utils.utils.alias_setup(probs)[source]

Compute utility lists for non-uniform sampling from discrete distributions. Refer to https://hips.seas.harvard.edu/blog/2013/03/03/the-alias-method-efficient-sampling-with-many-discrete-outcomes/ for details

cogdl.utils.utils.batch_mean_pooling(x, batch)[source]
cogdl.utils.utils.batch_sum_pooling(x, batch)[source]
cogdl.utils.utils.build_args_from_dict(dic)[source]
cogdl.utils.utils.check_edge_softmax()[source]
cogdl.utils.utils.check_fast_spmm()[source]
cogdl.utils.utils.check_mh_spmm()[source]
cogdl.utils.utils.coalesce(row, col, value=None)[source]
cogdl.utils.utils.coo2csc(row, col, data, num_nodes=None, sorted=False)[source]
cogdl.utils.utils.coo2csr(row, col, data, num_nodes=None, ordered=False)[source]
cogdl.utils.utils.coo2csr_index(row, col, num_nodes=None)[source]
cogdl.utils.utils.csr2coo(indptr, indices, data)[source]
cogdl.utils.utils.csr2csc(indptr, indices, data=None)[source]
cogdl.utils.utils.cycle_index(num, shift)[source]
cogdl.utils.utils.download_url(url, folder, name=None, log=True)[source]

Downloads the content of an URL to a specific folder.

Args:

url (string): The url. folder (string): The folder. name (string): saved filename. log (bool, optional): If False, will not print anything to the

console. (default: True)
cogdl.utils.utils.dropout_adj()[source]
cogdl.utils.utils.edge_softmax(graph, edge_val)[source]
Args:
indices: Tensor, shape=(2, E) values: Tensor, shape=(N,) shape: tuple(int, int)
Returns:
Softmax values of edge values for nodes
cogdl.utils.utils.filter_adj(row, col, edge_attr, mask)[source]
cogdl.utils.utils.get_activation(act: str)[source]
cogdl.utils.utils.get_degrees(row, col, num_nodes=None)[source]
cogdl.utils.utils.init_operator_configs(args=None)[source]
cogdl.utils.utils.initialize_edge_softmax(args)[source]
cogdl.utils.utils.initialize_spmm(args)[source]
cogdl.utils.utils.makedirs(path)[source]
cogdl.utils.utils.mh_spmm(graph, attention, h)[source]
Multi-head spmm
Args:
graph: Graph attention: torch.Tensor([E, H]) h: torch.Tensor([N, d])
Returns:
torch.Tensor([N, H, d])
cogdl.utils.utils.mul_edge_softmax(graph, edge_val)[source]
Returns:
Softmax values of multi-dimension edge values. shape: [E, H]
cogdl.utils.utils.negative_edge_sampling(edge_index: torch.Tensor, num_nodes: Optional[int] = None, num_neg_samples: Optional[int] = None, undirected: bool = False)[source]
cogdl.utils.utils.print_result(results, datasets, model_name)[source]
cogdl.utils.utils.remove_self_loops(indices, values=None)[source]
cogdl.utils.utils.row_normalization(num_nodes, row, col, val=None)[source]
cogdl.utils.utils.set_random_seed(seed)[source]
cogdl.utils.utils.sorted_coo2csr(row, col, data, num_nodes=None, return_index=False)[source]
cogdl.utils.utils.spmm(graph, x)[source]
cogdl.utils.utils.spmm_adj(indices, values, x, num_nodes=None)[source]
cogdl.utils.utils.spmm_scatter(row, col, values, b)[source]
Args:
indices : Tensor, shape=(2, E) values : Tensor, shape=(E,) b : Tensor, shape=(N, )
cogdl.utils.utils.symmetric_normalization(num_nodes, row, col, val=None)[source]
cogdl.utils.utils.tabulate_results(results_dict)[source]
cogdl.utils.utils.to_undirected(edge_index, num_nodes=None)[source]

Converts the graph given by edge_index to an undirected graph, so that \((j,i) \in \mathcal{E}\) for every edge \((i,j) \in \mathcal{E}\).

Args:

edge_index (LongTensor): The edge indices. num_nodes (int, optional): The number of nodes, i.e.

max_val + 1 of edge_index. (default: None)
Return type:LongTensor
cogdl.utils.utils.untar(path, fname, deleteTar=True)[source]

Unpacks the given archive file to the same directory, then (by default) deletes the archive file.

cogdl.utils.evaluator.accuracy(y_pred, y_true)[source]
cogdl.utils.evaluator.bce_with_logits_loss(y_pred, y_true, reduction='mean')[source]
cogdl.utils.evaluator.cross_entropy_loss(y_pred, y_true)[source]
cogdl.utils.evaluator.multiclass_f1(y_pred, y_true)[source]
cogdl.utils.evaluator.multilabel_f1(y_pred, y_true, sigmoid=False)[source]
class cogdl.utils.sampling.RandomWalker(adj=None, num_nodes=None)[source]

Bases: object

build_up(adj, num_nodes)[source]
walk(start, walk_length)[source]
cogdl.utils.sampling.random_walk[source]
Parameters:
start : np.array(dtype=np.int32) length : int indptr : np.array(dtype=np.int32) indices : np.array(dtype=np.int32)
Return:
list(np.array(dtype=np.int32))