graphslim.dataset package
graphslim.dataset.attack module
graphslim.dataset.convertor module
- graphslim.dataset.convertor.loadSparseGraph(dataset_name)[source]
Load original graph from file from paper CHEN Y, YE H, VEDULA S, et al. Demystifying graph sparsification algorithms in graph properties preservation[M/OL].
GraphSlim package only supports undirected graph and we do not distinguish the weighted and unweighted pyg->nt->save sparsified nt->pyg->evaluation
- Parameters:
dataset_name (str) – dataset name
config (dict) – config loaded from json
undirected_only (bool, optional) – Set to True to override graph directness in config file and load undirected graph only. Defaults to False. This is used for sparsifiers that only support undirected graph.
- Returns:
original graph
- Return type:
nk graph
graphslim.dataset.loader module
- class graphslim.dataset.loader.DataGraphSAINT(root, dataset, **kwargs)[source]
Bases:
objectdatasets used in GraphSAINT paper
- class graphslim.dataset.loader.LargeDataLoader(*args: Any, **kwargs: Any)[source]
Bases:
Module- GCF(adj, x, k=2)[source]
Graph convolution filter :param adj: torch.Tensor, adjacency matrix, must be self-looped :param x: torch.Tensor, features :param k: int, number of hops
- Returns:
torch.Tensor, filtered features
graphslim.dataset.utils module
- graphslim.dataset.utils.disjointed_union(tree_list, class_=None, device=None)[source]
Computes disjointed union of trees inside tree_list. trees are in torch_geometric.data.Data format. Returns a torch_geometric.data.Data graph without the roots_to_embed information.
- graphslim.dataset.utils.get_data(node_label_map, edge_label_map, node_label_map_original, node_label_map_orig, edge_label_map_orig, node_label_map_full, class_)[source]
- graphslim.dataset.utils.get_syn_data(data, args, model_type, verbose=False)[source]
Loads or computes synthetic data for evaluation.
- Parameters:
data (Dataset) – The dataset containing the graph data.
model_type (str) – The type of model used for generating synthetic data.
verbose (bool, optional, default=False) – Whether to print detailed logs.
- Returns:
feat_syn (torch.Tensor) – Synthetic feature matrix.
adj_syn (torch.Tensor) – Synthetic adjacency matrix.
labels_syn (torch.Tensor) – Synthetic labels.
- graphslim.dataset.utils.index2mask(index, size)[source]
Convert an index list to a boolean mask.
- Parameters:
index (list or tensor) – List or tensor of indices to be set to True.
size (int or tuple of int) – Shape of the mask. If an integer, the mask is 1-dimensional.
- Returns:
mask – A boolean tensor of the specified size, with True at the given index positions and False elsewhere.
- Return type:
tensor
Examples
>>> index = [0, 2, 4] >>> size = 5 >>> index2mask(index, size) tensor([True, False, True, False, True], dtype=torch.bool)
- graphslim.dataset.utils.preprocess_dataset_test(dataset, node_label_map, edge_label_map, node_label_map_full)[source]
- graphslim.dataset.utils.save_reduced(adj_syn=None, feat_syn=None, labels_syn=None, args=None)[source]
- graphslim.dataset.utils.sparsify(model_type, adj_syn, args, verbose=False)[source]
Applies sparsification to the adjacency matrix based on the model type and given arguments.
This function modifies the adjacency matrix to make it sparser according to the model type and method specified. For specific methods and datasets, it adjusts the threshold used for sparsification.
Parametersm
- model_typestr
The type of model used, which determines the sparsification strategy. Can be ‘MLP’, ‘GAT’, or other.
- adj_syntorch.Tensor
The adjacency matrix to be sparsified.
- argsargparse.Namespace
Command-line arguments and configuration parameters which may include method-specific settings.
- verbosebool, optional
If True, prints information about the sparsity of the adjacency matrix before and after sparsification. Default is False.
- returns:
adj_syn – The sparsified adjacency matrix.
- rtype:
torch.Tensor