graphslim package
Subpackages
- graphslim.coarsening package
- graphslim.coarsening.coarsening_base
- graphslim.coarsening.affinity_gs module
- graphslim.coarsening.algebraic_jc module
- graphslim.coarsening.heavy_edge module
- graphslim.coarsening.kron module
- graphslim.coarsening.variation_cliques module
- graphslim.coarsening.variation_edges module
- graphslim.coarsening.variation_neighborhoods module
- graphslim.coarsening.averaging module
- graphslim.coarsening.clustering module
- graphslim.coarsening.clusteringagg module
- graphslim.coarsening.vng module
- graphslim.coarsening.utils module
coarsen_matrix()coarsen_vector()coarsening_quality()contract_variation_edges()contract_variation_linear()eig()generate_test_vectors()get_S()get_coarsening_matrix()get_proximity_measure()graph_sparsify()kron_coarsening()kron_interpolate()kron_quality()lift_matrix()lift_vector()matching_greedy()matching_optimal()maxWeightMatching()my_graph_multiresolution()zero_diag()
- graphslim.condensation package
- graphslim.condensation.gcond_base module
- graphslim.condensation.gcond module
- graphslim.condensation.gcondx module
- graphslim.condensation.doscond module
- graphslim.condensation.doscondx module
- graphslim.condensation.gcsntk module
- graphslim.condensation.geom module
- graphslim.condensation.msgc module
- graphslim.condensation.sfgc module
- graphslim.condensation.sgdd module
- graphslim.condensation.utils module
GCF()difficulty_measurer()difficulty_measurer_in()distance_wb()get_eigh()get_embed_mean()get_embed_sum()get_largest_cc()get_subspace_covariance_matrix()get_subspace_embed()get_syn_eigen()get_train_lcc()load_eigen()match_loss()neighborhood_difficulty_measurer()neighborhood_difficulty_measurer_in()normalize_data()sort_training_nodes()sort_training_nodes_in()sub_E()training_scheduler()update_E()
- graphslim.dataset package
- graphslim.dataset.attack module
- graphslim.dataset.convertor module
- graphslim.dataset.loader module
- graphslim.dataset.utils module
canonical_label_to_naturals()disjointed_union()get_data()get_dataloader()get_invalid_trees()get_label_maps()get_syn_data()index2mask()load_reduced()myDatasetparse_canonical_label()parse_canonical_label_bak()preprocess_dataset()preprocess_dataset_test()prettify_canonical_label()process_labels()pyfpgrowth_wrapper()roots_to_embed()save_reduced()sparsify()splits()tree_class_ctr()
- graphslim.evaluation package
- graphslim.models package
- graphslim.models.base module
- graphslim.models.gcn module
- graphslim.models.appnp module
- graphslim.models.cheby module
- graphslim.models.gat module
- graphslim.models.gntk module
- graphslim.models.graphsage module
- graphslim.models.sgc module
- graphslim.models.layers module
- graphslim.models.sgformer module
- graphslim.models.ignr module
- graphslim.models.krr module
- graphslim.models.prbcd module
- graphslim.models.reparam_module module
- graphslim.models.sntk module
- graphslim.models.random_attack module
- graphslim.models.parametrized_adj module
- graphslim.sparsification package
- Node Sparsification (Coreset)
- graphslim.sparsification.coreset_base module
- graphslim.sparsification.model_based_coreset_base module
- graphslim.sparsification.herding module
- graphslim.sparsification.kcenter module
- graphslim.sparsification.kcenter_sample module
- graphslim.sparsification.model_free_coreset_base module
- graphslim.sparsification.random module
- graphslim.sparsification.cent_degree module
- graphslim.sparsification.cent_pagerank module
- graphslim.sparsification.herding_agg module
- graphslim.sparsification.kcenter_agg module
- Edge Sparsification
- graphslim.sparsification.edge_sparsification_base module
- graphslim.sparsification.random_edge module
- graphslim.sparsification.g_spar module
- graphslim.sparsification.local_degree module
- graphslim.sparsification.rank_degree module
- graphslim.sparsification.scan module
- graphslim.sparsification.spanning_forest module
- graphslim.sparsification.t_spanner module
- graphslim.sparsification.utils module
Submodules
graphslim.configs module
graphslim.train_all module
graphslim.utils module
- graphslim.utils.accuracy(output, labels)[source]
Return accuracy of output compared to labels.
- Parameters:
output (torch.Tensor) – output from model
labels (torch.Tensor or numpy.array) – node labels
- Returns:
accuracy
- Return type:
float
- graphslim.utils.classification_margin(output, true_label)[source]
Calculate classification margin for outputs. probs_true_label - probs_best_second_class
- Parameters:
output (torch.Tensor) – output vector (1 dimension)
true_label (int) – true label for this node
- Returns:
classification margin for this node
- Return type:
list
- graphslim.utils.degree_normalize_sparse_tensor(adj, fill_value=1)[source]
degree_normalize_sparse_tensor.
- graphslim.utils.degree_sequence_log_likelihood(degree_sequence, d_min)[source]
Compute the (maximum) log likelihood of the Powerlaw distribution fit on a degree distribution.
- graphslim.utils.encode_onehot(labels)[source]
Convert label to onehot format.
- Parameters:
labels (numpy.array) – node labels
- Returns:
onehot labels
- Return type:
numpy.array
- graphslim.utils.f1_macro(output, labels, is_sigmoid=False)[source]
Return F1-macro score of output compared to labels.
- Parameters:
output (torch.Tensor) – output from model
labels (torch.Tensor or numpy.array) – true labels (0 or 1)
- Returns:
F1-macro score
- Return type:
float
- graphslim.utils.gcn_norm(edge_index, edge_weight=None, num_nodes=None, improved=False, add_self_loops=True, flow='source_to_target', dtype=None)[source]
- graphslim.utils.get_splits_each_class(labels, train_size)[source]
We randomly sample n instances for class, where n = train_size.
- graphslim.utils.get_train_test(nnodes, test_size=0.8, stratify=None, seed=None)[source]
This function returns training and test set without validation. It can be used for settings of different label rates.
- Parameters:
nnodes (int) – number of nodes in total
test_size (float) – size of test set
stratify – data is expected to split in a stratified fashion. So stratify should be labels.
seed (int or None) – random seed
- Returns:
idx_train – node training indices
idx_test – node test indices
- graphslim.utils.get_train_test_labelrate(labels, label_rate)[source]
Get train test according to given label rate.
- graphslim.utils.get_train_val_test(nnodes, val_size=0.1, test_size=0.8, stratify=None, seed=None)[source]
This setting follows nettack/mettack, where we split the nodes into 10% training, 10% validation and 80% testing data
- Parameters:
nnodes (int) – number of nodes in total
val_size (float) – size of validation set
test_size (float) – size of test set
stratify – data is expected to split in a stratified fashion. So stratify should be labels.
seed (int or None) – random seed
- Returns:
idx_train – node training indices
idx_val – node validation indices
idx_test – node test indices
- graphslim.utils.get_train_val_test_gcn(labels, seed=None)[source]
This setting follows gcn, where we randomly sample 20 instances for each class as training data, 500 instances as validation data, 1000 instances as test data. Note here we are not using fixed splits. When random seed changes, the splits will also change.
- Parameters:
labels (numpy.array) – node labels
seed (int or None) – random seed
- Returns:
idx_train – node training indices
idx_val – node validation indices
idx_test – node test indices
- graphslim.utils.is_sparse_tensor(tensor)[source]
Check if a tensor is sparse tensor.
- Parameters:
tensor (torch.Tensor) – given tensor
- Returns:
whether a tensor is sparse tensor
- Return type:
bool
- graphslim.utils.normalize_adj_sgformer(adj)[source]
Normalize the adjacency matrix. Works for both dense and sparse matrices.
Args: adj (torch.Tensor): The adjacency matrix (either dense or sparse COO). device (torch.device): The device to run the normalization on.
Returns: torch.Tensor or SparseTensor: The normalized adjacency matrix.
- graphslim.utils.normalize_adj_tensor(adj, sparse=False)[source]
Normalize adjacency tensor matrix, return sparse or not
- graphslim.utils.normalize_feature(mx)[source]
Row-normalize sparse matrix or dense matrix
- Parameters:
mx (scipy.sparse.csr_matrix or numpy.array) – matrix to be normalized
- Returns:
normalized matrix
- Return type:
scipy.sprase.lil_matrix
- graphslim.utils.normalize_sparse_tensor(adj, fill_value=1)[source]
Normalize sparse tensor. Need to import torch_scatter
- graphslim.utils.ravel_multiple_indices(ixs, shape, reverse=False)[source]
“Flattens” multiple 2D input indices into indices on the flattened matrix, similar to np.ravel_multi_index. Does the same as ravel_index but for multiple indices at once. :param ixs: The array of n indices that will be flattened. :type ixs: array of ints shape (n, 2) :param shape: The shape of the corresponding matrix. :type shape: list or tuple of ints of length 2
- Returns:
The indices on the flattened matrix corresponding to the 2D input indices.
- Return type:
array of n ints between 0 and shape[0]*shape[1]-1
- graphslim.utils.roc_auc(output, labels, is_sigmoid=False)[source]
Return ROC-AUC score of output compared to labels.
- Parameters:
output (torch.Tensor) – output from model
labels (torch.Tensor or numpy.array) – true labels (0 or 1)
is_sigmoid (bool, optional) – If True, apply sigmoid thresholding on the output, by default False.
- Returns:
ROC-AUC score
- Return type:
float
- graphslim.utils.sparse_mx_to_torch_sparse_tensor(sparse_mx)[source]
Convert a scipy sparse matrix to a torch sparse tensor.
- graphslim.utils.tensor2onehot(labels)[source]
Convert label tensor to label onehot tensor.
- Parameters:
labels (torch.LongTensor) – node labels
- Returns:
onehot labels tensor
- Return type:
torch.LongTensor
- graphslim.utils.updated_log_likelihood_for_edge_changes(node_pairs, adjacency_matrix, d_min)[source]
Adopted from https://github.com/danielzuegner/nettack