utils

class cogdl.utils.utils.ArgClass[source]

Bases: object

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_max_pooling(x, batch)[source]
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.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.get_activation(act: str)[source]
cogdl.utils.utils.get_memory_usage(print_info=False)[source]

Get accurate gpu memory usage by querying torch runtime

cogdl.utils.utils.get_norm_layer(norm: str, channels: int)[source]
Args:
norm: str
type of normalization: layernorm, batchnorm, instancenorm
channels: int
size of features for normalization
cogdl.utils.utils.identity_act(input, inplace=True)[source]
cogdl.utils.utils.makedirs(path)[source]
cogdl.utils.utils.print_result(results, datasets, model_name)[source]
cogdl.utils.utils.set_random_seed(seed)[source]
cogdl.utils.utils.split_dataset_general(dataset, args)[source]
cogdl.utils.utils.tabulate_results(results_dict)[source]
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.utils.update_args_from_dict(args, dic)[source]
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, restart_p=0.0)[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) p : float
Return:
list(np.array(dtype=np.int32))