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.coalesce(row, col, value=None)[source]
cogdl.utils.utils.coo2csc(edge_index, edge_attr)[source]
cogdl.utils.utils.coo2csr(edge_index, edge_attr, num_nodes=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(edge_index: torch.Tensor, edge_weight: Optional[torch.Tensor] = None, drop_rate: float = 0.5, renorm: bool = True)[source]
cogdl.utils.utils.edge_softmax(indices, values, shape)[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_csr_from_edge_index(edge_index, edge_attr, size)[source]
cogdl.utils.utils.get_csr_ind(edge_index, edge_weight=None, num_nodes=None)[source]
cogdl.utils.utils.get_degrees(indices, num_nodes=None)[source]
cogdl.utils.utils.initialize_spmm(args)[source]
cogdl.utils.utils.makedirs(path)[source]
cogdl.utils.utils.mul_edge_softmax(indices, values, shape)[source]
Args:
indices: Tensor, shape=(2, E) values: Tensor, shape=(E, d) shape: tuple(int, int)
Returns:
Softmax values of multi-dimension edge values for nodes
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, edge_index, edge_weight=None)[source]
cogdl.utils.utils.set_random_seed(seed)[source]
cogdl.utils.utils.spmm(edge_index, edge_weight, x, num_nodes=None)[source]
Args:
edge_index : Tensor, shape=(2, E) edge_weight : Tensor, shape=(E,) x : Tensor, shape=(N, ) num_nodes : Optional[int]
cogdl.utils.utils.spmm_adj(indices, values, x, num_nodes=None)[source]
cogdl.utils.utils.spmm_scatter(indices, values, b)[source]
Args:
indices : Tensor, shape=(2, E) values : Tensor, shape=(E,) b : Tensor, shape=(N, )
cogdl.utils.utils.symmetric_normalization(num_nodes, edge_index, edge_weight=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))