├── CV_helpers_HOLS_ft.jl ├── README.md ├── Tensor_Package ├── Tensor_Package.jl ├── crossval.jl ├── labelspreading.jl ├── similarity_knn.jl ├── tensors.jl └── utils.jl ├── competitors ├── competitors_setups │ ├── APPNP │ │ ├── LICENSE │ │ ├── README.md │ │ ├── appnp.egg-info │ │ │ ├── PKG-INFO │ │ │ ├── SOURCES.txt │ │ │ ├── dependency_links.txt │ │ │ ├── not-zip-safe │ │ │ └── top_level.txt │ │ ├── appnp │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-36.pyc │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ ├── appnp.cpython-36.pyc │ │ │ │ ├── appnp.cpython-38.pyc │ │ │ │ ├── appnp_layer.cpython-36.pyc │ │ │ │ ├── appnp_layer.cpython-38.pyc │ │ │ │ ├── main.cpython-38.pyc │ │ │ │ ├── main_jl.cpython-36.pyc │ │ │ │ ├── main_jl.cpython-38.pyc │ │ │ │ ├── param_parser.cpython-38.pyc │ │ │ │ └── utils.cpython-38.pyc │ │ │ ├── appnp.py │ │ │ ├── appnp_layer.py │ │ │ ├── input │ │ │ │ ├── cora_edges.csv │ │ │ │ ├── cora_features.json │ │ │ │ └── cora_target.csv │ │ │ ├── main.py │ │ │ ├── main_jl.py │ │ │ ├── param_parser.py │ │ │ └── utils.py │ │ ├── appnp_run.jpg │ │ ├── build │ │ │ ├── lib │ │ │ │ └── appnp │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── appnp.py │ │ │ │ │ ├── appnp_layer.py │ │ │ │ │ ├── main.py │ │ │ │ │ ├── main_jl.py │ │ │ │ │ ├── param_parser.py │ │ │ │ │ └── utils.py │ │ │ └── scripts-3.6 │ │ │ │ └── main_jl.py │ │ ├── dist │ │ │ └── appnp-0.1-py3.6.egg │ │ ├── ppnp.jpg │ │ └── setup.py │ ├── HGNN │ │ ├── build │ │ │ ├── lib │ │ │ │ └── hgnn │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── train.py │ │ │ │ │ └── train_jl.py │ │ │ └── scripts-3.6 │ │ │ │ └── train_jl.py │ │ ├── dist │ │ │ └── hgnn-0.1-py3.6.egg │ │ ├── hgnn.egg-info │ │ │ ├── PKG-INFO │ │ │ ├── SOURCES.txt │ │ │ ├── dependency_links.txt │ │ │ ├── not-zip-safe │ │ │ └── top_level.txt │ │ ├── hgnn │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-36.pyc │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ ├── train.cpython-36.pyc │ │ │ │ ├── train_jl.cpython-36.pyc │ │ │ │ └── train_jl.cpython-38.pyc │ │ │ ├── config │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ │ ├── __init__.cpython-36.pyc │ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ │ ├── config.cpython-36.pyc │ │ │ │ │ ├── config.cpython-37.pyc │ │ │ │ │ └── config.cpython-38.pyc │ │ │ │ ├── config.py │ │ │ │ └── config.yaml │ │ │ ├── data │ │ │ │ ├── features.pickle │ │ │ │ ├── hypergraph.pickle │ │ │ │ └── labels.pickle │ │ │ ├── datasets │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ │ ├── __init__.cpython-36.pyc │ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ │ ├── data_helper.cpython-36.pyc │ │ │ │ │ ├── data_helper.cpython-37.pyc │ │ │ │ │ ├── data_helper.cpython-38.pyc │ │ │ │ │ ├── visual_data.cpython-36.pyc │ │ │ │ │ ├── visual_data.cpython-37.pyc │ │ │ │ │ └── visual_data.cpython-38.pyc │ │ │ │ ├── data_helper.py │ │ │ │ └── visual_data.py │ │ │ ├── doc │ │ │ │ └── pipline.png │ │ │ ├── models │ │ │ │ ├── HGNN.py │ │ │ │ ├── __init__.py │ │ │ │ ├── __pycache__ │ │ │ │ │ ├── HGNN.cpython-36.pyc │ │ │ │ │ ├── HGNN.cpython-37.pyc │ │ │ │ │ ├── HGNN.cpython-38.pyc │ │ │ │ │ ├── __init__.cpython-36.pyc │ │ │ │ │ ├── __init__.cpython-37.pyc │ │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ │ ├── layers.cpython-36.pyc │ │ │ │ │ ├── layers.cpython-37.pyc │ │ │ │ │ └── layers.cpython-38.pyc │ │ │ │ └── layers.py │ │ │ ├── train.py │ │ │ ├── train_jl.py │ │ │ └── utils │ │ │ │ ├── __pycache__ │ │ │ │ ├── hypergraph_utils.cpython-36.pyc │ │ │ │ ├── hypergraph_utils.cpython-37.pyc │ │ │ │ └── hypergraph_utils.cpython-38.pyc │ │ │ │ └── hypergraph_utils.py │ │ └── setup.py │ ├── HyperGCN │ │ ├── LICENSE │ │ ├── README.md │ │ ├── __pycache__ │ │ │ └── hypergcn_jl.cpython-36.pyc │ │ ├── build │ │ │ ├── lib │ │ │ │ └── hypergcn │ │ │ │ │ ├── hypergcn.py │ │ │ │ │ └── hypergcn_jl.py │ │ │ └── scripts-3.6 │ │ │ │ └── hypergcn_jl.py │ │ ├── dist │ │ │ └── hypergcn-0.1-py3.6.egg │ │ ├── hypergcn.egg-info │ │ │ ├── PKG-INFO │ │ │ ├── SOURCES.txt │ │ │ ├── dependency_links.txt │ │ │ ├── not-zip-safe │ │ │ └── top_level.txt │ │ ├── hypergcn │ │ │ ├── .gitignore │ │ │ ├── config │ │ │ │ ├── coauthorship.yml │ │ │ │ └── config.py │ │ │ ├── data │ │ │ │ └── data.py │ │ │ ├── hmlap.png │ │ │ ├── hypergcn.py │ │ │ ├── hypergcn_jl.py │ │ │ └── model │ │ │ │ ├── model.py │ │ │ │ ├── networks.py │ │ │ │ └── utils.py │ │ └── setup.py │ ├── SCE │ │ ├── build │ │ │ ├── lib │ │ │ │ └── sce │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── classification.py │ │ │ │ │ ├── load_process.py │ │ │ │ │ ├── mlp.py │ │ │ │ │ ├── networks.py │ │ │ │ │ ├── preprocess.py │ │ │ │ │ ├── splits.py │ │ │ │ │ ├── test.py │ │ │ │ │ ├── train.py │ │ │ │ │ ├── train_jl.py │ │ │ │ │ └── utils.py │ │ │ └── scripts-3.6 │ │ │ │ └── train_jl.py │ │ ├── dist │ │ │ └── sce-0.1-py3.6.egg │ │ ├── sce.egg-info │ │ │ ├── PKG-INFO │ │ │ ├── SOURCES.txt │ │ │ ├── dependency_links.txt │ │ │ ├── not-zip-safe │ │ │ └── top_level.txt │ │ ├── sce │ │ │ ├── README.md │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-36.pyc │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ ├── classification.cpython-36.pyc │ │ │ │ ├── classification.cpython-38.pyc │ │ │ │ ├── load_process.cpython-36.pyc │ │ │ │ ├── load_process.cpython-38.pyc │ │ │ │ ├── mlp.cpython-36.pyc │ │ │ │ ├── mlp.cpython-38.pyc │ │ │ │ ├── networks.cpython-36.pyc │ │ │ │ ├── networks.cpython-38.pyc │ │ │ │ ├── preprocess.cpython-36.pyc │ │ │ │ ├── preprocess.cpython-38.pyc │ │ │ │ ├── train.cpython-36.pyc │ │ │ │ ├── train_jl.cpython-36.pyc │ │ │ │ ├── train_jl.cpython-38.pyc │ │ │ │ ├── utils.cpython-36.pyc │ │ │ │ └── utils.cpython-38.pyc │ │ │ ├── classification.py │ │ │ ├── load_process.py │ │ │ ├── mlp.py │ │ │ ├── networks.py │ │ │ ├── preprocess.py │ │ │ ├── splits.py │ │ │ ├── test.py │ │ │ ├── train.py │ │ │ ├── train_jl.py │ │ │ └── utils.py │ │ └── setup.py │ ├── SGC │ │ ├── __pycache__ │ │ │ ├── args.cpython-36.pyc │ │ │ ├── citation_jl.cpython-36.pyc │ │ │ ├── citation_jl.cpython-38.pyc │ │ │ ├── metrics.cpython-36.pyc │ │ │ ├── models.cpython-36.pyc │ │ │ ├── normalization.cpython-36.pyc │ │ │ └── utils.cpython-36.pyc │ │ ├── build │ │ │ ├── lib │ │ │ │ └── sgc │ │ │ │ │ ├── __init__.py │ │ │ │ │ ├── args.py │ │ │ │ │ ├── citation.py │ │ │ │ │ ├── citation_jl.py │ │ │ │ │ ├── metrics.py │ │ │ │ │ ├── models.py │ │ │ │ │ ├── normalization.py │ │ │ │ │ ├── reddit.py │ │ │ │ │ ├── tuning.py │ │ │ │ │ └── utils.py │ │ │ └── scripts-3.6 │ │ │ │ └── citation_jl.py │ │ ├── dist │ │ │ └── sgc-0.1-py3.6.egg │ │ ├── setup.py │ │ ├── sgc.egg-info │ │ │ ├── PKG-INFO │ │ │ ├── SOURCES.txt │ │ │ ├── dependency_links.txt │ │ │ ├── not-zip-safe │ │ │ └── top_level.txt │ │ └── sgc │ │ │ ├── .gitignore │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── SGC-tuning │ │ │ ├── citeseer.txt │ │ │ ├── cora.txt │ │ │ └── pubmed.txt │ │ │ ├── __init__.py │ │ │ ├── args.py │ │ │ ├── citation.py │ │ │ ├── citation_jl.py │ │ │ ├── data │ │ │ ├── ind.citeseer.allx │ │ │ ├── ind.citeseer.ally │ │ │ ├── ind.citeseer.graph │ │ │ ├── ind.citeseer.test.index │ │ │ ├── ind.citeseer.tx │ │ │ ├── ind.citeseer.ty │ │ │ ├── ind.citeseer.x │ │ │ ├── ind.citeseer.y │ │ │ ├── ind.cora.allx │ │ │ ├── ind.cora.ally │ │ │ ├── ind.cora.graph │ │ │ ├── ind.cora.test.index │ │ │ ├── ind.cora.tx │ │ │ ├── ind.cora.ty │ │ │ ├── ind.cora.x │ │ │ ├── ind.cora.y │ │ │ ├── ind.pubmed.allx │ │ │ ├── ind.pubmed.ally │ │ │ ├── ind.pubmed.graph │ │ │ ├── ind.pubmed.test.index │ │ │ ├── ind.pubmed.tx │ │ │ ├── ind.pubmed.ty │ │ │ ├── ind.pubmed.x │ │ │ └── ind.pubmed.y │ │ │ ├── downstream │ │ │ └── TextSGC │ │ │ │ ├── README.md │ │ │ │ ├── build_corpus.py │ │ │ │ ├── build_graph.py │ │ │ │ ├── models.py │ │ │ │ ├── remove_words.py │ │ │ │ ├── requirements.txt │ │ │ │ ├── train.py │ │ │ │ ├── tuned_result │ │ │ │ ├── 20ng.SGC.tuning.txt │ │ │ │ ├── R52.SGC.tuning.txt │ │ │ │ ├── R8.SGC.tuning.txt │ │ │ │ ├── mr.SGC.tuning.txt │ │ │ │ └── ohsumed.SGC.tuning.txt │ │ │ │ ├── tuning.py │ │ │ │ └── utils.py │ │ │ ├── metrics.py │ │ │ ├── model.jpg │ │ │ ├── models.py │ │ │ ├── normalization.py │ │ │ ├── reddit.py │ │ │ ├── requirements.txt │ │ │ ├── tuning.py │ │ │ └── utils.py │ ├── install.sh │ └── readme.md ├── results │ ├── citeseer.csv │ ├── contact-high-school.csv │ ├── cora-author.csv │ ├── cora-cit.csv │ ├── dblp.csv │ ├── pubmed.csv │ └── time.csv └── scripts │ ├── appnp.jl │ ├── hgnn.jl │ ├── hols.jl │ ├── hypergcn.jl │ ├── main.jl │ ├── sce.jl │ ├── sgc.jl │ ├── time.jl │ └── utils.jl ├── cross_val_datasets_HOLS_ft.jl ├── data ├── citeseer │ ├── features.pickle │ ├── hyperedges-citeseer.txt │ ├── hypergraph.pickle │ ├── labels.pickle │ ├── node-labels-citeseer.txt │ └── splits │ │ ├── 1.pickle │ │ ├── 10.pickle │ │ ├── 2.pickle │ │ ├── 3.pickle │ │ ├── 4.pickle │ │ ├── 5.pickle │ │ ├── 6.pickle │ │ ├── 7.pickle │ │ ├── 8.pickle │ │ └── 9.pickle ├── contact-high-school │ ├── hyperedges-contact-high-school.txt │ ├── label-names-contact-high-school.txt │ ├── node-labels-contact-high-school.txt │ └── parse.jl ├── cora-author │ ├── features.pickle │ ├── hyperedges-cora-author.txt │ ├── hypergraph.pickle │ ├── labels.pickle │ ├── node-labels-cora-author.txt │ └── splits │ │ ├── 1.pickle │ │ ├── 10.pickle │ │ ├── 2.pickle │ │ ├── 3.pickle │ │ ├── 4.pickle │ │ ├── 5.pickle │ │ ├── 6.pickle │ │ ├── 7.pickle │ │ ├── 8.pickle │ │ └── 9.pickle ├── cora-cit │ ├── features.pickle │ ├── hyperedges-cora-cit.txt │ ├── hypergraph.pickle │ ├── labels.pickle │ ├── node-labels-cora-cit.txt │ └── splits │ │ ├── 1.pickle │ │ ├── 10.pickle │ │ ├── 2.pickle │ │ ├── 3.pickle │ │ ├── 4.pickle │ │ ├── 5.pickle │ │ ├── 6.pickle │ │ ├── 7.pickle │ │ ├── 8.pickle │ │ └── 9.pickle ├── dblp │ ├── features.pickle │ ├── hyperedges-dblp.txt │ ├── hypergraph.pickle │ ├── labels.pickle │ ├── node-labels-dblp.txt │ └── splits │ │ ├── 1.pickle │ │ ├── 10.pickle │ │ ├── 2.pickle │ │ ├── 3.pickle │ │ ├── 4.pickle │ │ ├── 5.pickle │ │ ├── 6.pickle │ │ ├── 7.pickle │ │ ├── 8.pickle │ │ └── 9.pickle ├── foodweb │ ├── additional_data │ │ ├── foodweb_species.txt │ │ └── hyperedges-foodweb_old.txt │ ├── hyperedges-foodweb.txt │ └── node-labels-foodweb.txt ├── mag-dual │ ├── hyperedges-mag-dual.txt │ ├── mag-dual-incidence.txt │ ├── mag_data_papers.txt │ ├── mag_ml_papers.txt │ ├── mag_theory_papers.txt │ ├── mag_vision_papers.txt │ ├── node-label-identities.txt │ └── node-labels-mag-dual.txt ├── optdigits.csv ├── pendigits.csv └── pubmed │ ├── features.pickle │ ├── hyperedges-pubmed.txt │ ├── hypergraph.pickle │ ├── labels.pickle │ ├── node-labels-pubmed.txt │ └── splits │ ├── 1.pickle │ ├── 10.pickle │ ├── 2.pickle │ ├── 3.pickle │ ├── 4.pickle │ ├── 5.pickle │ ├── 6.pickle │ ├── 7.pickle │ ├── 8.pickle │ └── 9.pickle └── packages.jl /README.md: -------------------------------------------------------------------------------- 1 | ## HyperND 2 | 3 | 4 | This repo contains the implementation for the algorithm HyperND from the paper: 5 | 6 | [Nonlinear Feature Diffusion on Hypergraphs](https://arxiv.org/abs/2103.14867) \ 7 | By Konstantin Prokopchik, [Austin R. Benson](https://www.cs.cornell.edu/~arb/) and [Francesco Tudisco](https://ftudisco.gitlab.io/post/) \ 8 | 9 | To be presented at ICML 2022. 10 | 11 | 12 | ## Baselines 13 | 14 | 15 | To install required julia packages run `julia packages.jl` or `include(packages.jl)` (if you are in a julia terminal). 16 | 17 | We have gathered 5 baselines, each of their realizations is taken from a github page. 18 | 19 | 1. [APPNP](https://github.com/benedekrozemberczki/APPNP) 20 | 2. [HGNN](https://github.com/iMoonLab/HGNN) 21 | 3. [HyperGCN](https://github.com/malllabiisc/HyperGCN) 22 | 4. [SCE](https://github.com/szzhang17/Sparsest-Cut-Network-Embedding) 23 | 5. [SGC](https://github.com/Tiiiger/SGC) 24 | 25 | We have wrapped them into packages for convenience, the guide to installation inside `competitors/competitors_setups` directory. 26 | 27 | There are 3 experiments: 28 | 29 | 1. HyperGCN experiment is in the old format in the root folder, that extensively compares HyperGCN with our algorithm. 30 | Execute `julia cross_val_datasets_HOLS_ft.jl` or `include("cross_val_datasets_HOLS_ft.jl")` to reproduce. 31 | 2. Time experiment compares times of our algorithm and baselines. 32 | Execute `julia competitors/scripts/time.jl` or `include("competitors/scripts/time.jl")` to reproduce. 33 | 3. Main experiment does a CV for our algorithm and compares the results with all the baselines on the same input data across multiple runs. 34 | Execute `julia competitors/scripts/main.jl` or `include("competitors/scripts/main.jl")` to reproduce. 35 | 36 | The datasets for experiments are inside the `data` folder. Results are stored in `competitors/results`. All the additional information is inside the scripts. 37 | -------------------------------------------------------------------------------- /Tensor_Package/Tensor_Package.jl: -------------------------------------------------------------------------------- 1 | module Tensor_Package 2 | 3 | using Base.Threads 4 | using Distances 5 | using LightGraphs 6 | using LinearAlgebra 7 | using PyCall 8 | using Random 9 | using ScikitLearn 10 | using SparseArrays 11 | using Statistics 12 | #using UCIData 13 | #using DataFrames 14 | using CSV 15 | 16 | 17 | 18 | include("similarity_knn.jl") 19 | include("tensors.jl") 20 | include("labelspreading.jl") 21 | include("utils.jl") 22 | include("crossval.jl") 23 | 24 | 25 | end 26 | -------------------------------------------------------------------------------- /Tensor_Package/crossval.jl: -------------------------------------------------------------------------------- 1 | 2 | 3 | function CV_splits(training_inds, num_splits, split=0.5) 4 | all_splits = [] 5 | for _ in 1:num_splits 6 | trial_train_splits = [] 7 | trial_val_splits = [] 8 | for inds in training_inds 9 | split_ind = Int64.(ceil(length(inds) * split)) 10 | class_splits = [] 11 | shuffle!(inds) 12 | push!(trial_train_splits, inds[1:split_ind]) 13 | push!(trial_val_splits, inds[(split_ind + 1):end]) 14 | end 15 | push!(all_splits, (vcat(trial_train_splits...), vcat(trial_val_splits...))) 16 | end 17 | return all_splits 18 | end 19 | 20 | 21 | function CV_run(args, method, X, y, train_inds, test_inds, 22 | num_CV_trials; 23 | balanced=true) 24 | splits = CV_splits(train_inds, num_CV_trials) 25 | df = DataFrame 26 | 27 | accs = Float64[] 28 | for split in splits 29 | train_inds = split[1] 30 | test_inds = collect(setdiff(Set(1:length(y)), Set(train_inds))) 31 | acc, _, _ = HGNN(args, X, y, train_inds, test_inds) 32 | push!(accs, acc) 33 | end 34 | 35 | return mean(accs) 36 | 37 | for split in splits 38 | val_inds = split[2] 39 | test_inds = collect(setdiff(Set(1:length(y)), Set(train_inds))) 40 | acc, _, _ = HGNN(args, X, y, train_inds, test_inds) 41 | push!(accs, acc) 42 | end 43 | 44 | #acc, rec, prec = validation_metrics(y, training_inds, A, DG_isqrt, T, DH_isqrt, B, 45 | # α_best, β_best, f, ε, max_iterations) 46 | end 47 | -------------------------------------------------------------------------------- /Tensor_Package/similarity_knn.jl: -------------------------------------------------------------------------------- 1 | @sk_import neighbors: NearestNeighbors 2 | const scipy_sparse_find = pyimport("scipy.sparse")."find" 3 | 4 | export SuperSparse3Tensor, 5 | cosine_angle, 6 | area_triangle, 7 | mean_square_distance, 8 | mean_distance_squared, 9 | max_square_distance, 10 | scipy2julia_sparse, 11 | distance_matrix, 12 | time_distance_matrix, 13 | rbf_similarity_weights_tensor, 14 | rbf_similarity_weights 15 | 16 | struct SuperSparse3Tensor 17 | I::Vector{Int64} 18 | J::Vector{Int64} 19 | K::Vector{Int64} 20 | V::Vector{Float64} 21 | n::Int64 22 | end 23 | 24 | 25 | ###### Weight functions for similarity tensor 26 | function cosine_angle(a,b,c) 27 | dif1 = (a - b) 28 | dif2 = (c - b) 29 | den = (norm(dif1)*norm(dif2)) 30 | if den > 1e-20 cosine = dot(dif1, dif2) / den else cosine = 0 end 31 | return 1-cosine 32 | end 33 | 34 | function area_triangle(a,b,c) 35 | p = (a+b+c)/2 36 | if p*(p-a)*(p-b)*(p-c) < 0 37 | return 1 38 | else 39 | return sqrt(p*(p-a)*(p-b)*(p-c)) 40 | end 41 | end 42 | 43 | function mean_square_distance(a,b,c) 44 | p = (a^2+b^2+c^2)/3 45 | return p 46 | end 47 | 48 | function mean_distance_squared(a,b,c) 49 | p = ((a+b+c)/3)^2 50 | return p 51 | end 52 | 53 | function max_square_distance(a,b,c) 54 | p = max(a,b,c) ^ 2 55 | return p 56 | end 57 | 58 | 59 | 60 | ######## KNN matrix from dataset 61 | function scipy2julia_sparse(Apy::PyObject) 62 | IA, JA, SA = scipy_sparse_find(Apy) 63 | return sparse(Int[i+1 for i in IA], Int[i+1 for i in JA], SA) 64 | end 65 | 66 | function distance_matrix(X, kn; mode="distance") 67 | nn = NearestNeighbors(n_neighbors=kn, p=2, n_jobs=-1) 68 | nn.fit(X) 69 | A = nn.kneighbors_graph(X, mode=mode) 70 | K = scipy2julia_sparse(A) 71 | K = max.(K,K') 72 | return K 73 | end 74 | 75 | 76 | 77 | function time_distance_matrix(X,kn; mode="distance") 78 | print("distance matrix:\t") 79 | @time distance_matrix(X,kn,mode=mode) 80 | end 81 | 82 | 83 | function rbf_similarity_weights(T::SuperSparse3Tensor; fast = true) 84 | valsT = T.V 85 | valsTT = copy(valsT) 86 | if fast 87 | valsTT = exp.(- ((valsT.^2) ./ 4) ) 88 | else 89 | σ = zeros(Float64,T.n) 90 | for i in 1:T.n 91 | σ[i] = maximum(valsT[T.I .== i]) 92 | end 93 | 94 | for (h , (i,j,k,v)) in enumerate(zip(T.I,T.J,T.K,T.V)) 95 | valsTT[h] = exp(-4*v^2 / min(σ[i],σ[j],σ[k])^2 ) 96 | end 97 | 98 | end 99 | return SuperSparse3Tensor(T.I,T.J,T.K,valsTT,T.n) 100 | end 101 | 102 | 103 | function rbf_similarity_weights(K::SparseArrays.SparseMatrixCSC; fast=true) 104 | I, J, valsK = findnz(K) 105 | n = size(K,1) 106 | furthest = maximum(K, dims=1) 107 | 108 | if fast 109 | # W_ij = - ||x_i -x_j||^2 / 2σ^2, for σ = √2 110 | valsTT = exp.(- ((valsK.^2 ) ./ 4) ) 111 | W = sparse(I,J,valsTT,n,n) 112 | else 113 | # S_ij = exp(- 4 ||x_i -x_j||^2 / σ^2), for σ = distance xi to its k-th neighbor 114 | # W_ij = max(S_ij,S_ji) 115 | W = spzeros(n,n) 116 | for (i,j,v) in zip(I,J,valsK) 117 | W[i,j] = exp(-4*v^2 / min(furthest[i],furthest[j])^2 ) 118 | end 119 | end 120 | return W 121 | end 122 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: appnp 3 | Version: 0.1 4 | Summary: UNKNOWN 5 | Home-page: https://github.com/benedekrozemberczki/APPNP 6 | License: Proprietary License 7 | Platform: UNKNOWN 8 | License-File: LICENSE 9 | 10 | UNKNOWN 11 | 12 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE 2 | README.md 3 | setup.py 4 | appnp/__init__.py 5 | appnp/appnp.py 6 | appnp/appnp_layer.py 7 | appnp/main.py 8 | appnp/main_jl.py 9 | appnp/param_parser.py 10 | appnp/utils.py 11 | appnp.egg-info/PKG-INFO 12 | appnp.egg-info/SOURCES.txt 13 | appnp.egg-info/dependency_links.txt 14 | appnp.egg-info/not-zip-safe 15 | appnp.egg-info/top_level.txt -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | appnp 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__init__.py: -------------------------------------------------------------------------------- 1 | import appnp.main_jl -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/appnp.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/appnp.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/appnp.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/appnp.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/appnp_layer.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/appnp_layer.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/appnp_layer.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/appnp_layer.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/main.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/main.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/main_jl.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/main_jl.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/main_jl.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/main_jl.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/param_parser.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/param_parser.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/__pycache__/utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp/__pycache__/utils.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/main.py: -------------------------------------------------------------------------------- 1 | """ Running the APPNP model.""" 2 | 3 | import torch 4 | from appnp.appnp import APPNPTrainer 5 | from appnp.param_parser import parameter_parser 6 | from appnp.utils import tab_printer, graph_reader, feature_reader, target_reader 7 | 8 | import os 9 | os.chdir((os.path.dirname(os.path.realpath(__file__)))) 10 | 11 | def main(): 12 | """ 13 | Parsing command line parameters, reading data, fitting an APPNP/PPNP and scoring the model. 14 | """ 15 | args = parameter_parser() 16 | torch.manual_seed(args.seed) 17 | tab_printer(args) 18 | graph = graph_reader(args.edge_path) 19 | features = feature_reader(args.features_path) 20 | target = target_reader(args.target_path) 21 | trainer = APPNPTrainer(args, graph, features, target) 22 | trainer.fit() 23 | 24 | if __name__ == "__main__": 25 | main() 26 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/main_jl.py: -------------------------------------------------------------------------------- 1 | """ Running the APPNP model.""" 2 | 3 | import torch 4 | import os 5 | import sys 6 | from appnp.appnp import APPNPTrainer 7 | from appnp.param_parser import parameter_parser 8 | from appnp.utils import tab_printer, graph_reader, graph_reader_from_var,\ 9 | feature_reader, target_reader, feature_reader_from_var 10 | 11 | from argparse import Namespace 12 | 13 | def main(args, edges, features, target, train_inds, test_inds, val_inds): 14 | """ 15 | Parsing command line parameters, reading data, fitting an APPNP/PPNP and scoring the model. 16 | """ 17 | args = Namespace(**args) 18 | torch.manual_seed(args.seed) 19 | tab_printer(args) 20 | edges = [list(a) for a in edges] 21 | graph = graph_reader_from_var(edges) 22 | features = feature_reader_from_var(features) 23 | trainer = APPNPTrainer(args, graph, features, target, train_inds, test_inds, val_inds) 24 | result = trainer.fit() 25 | return result.cpu().detach().numpy() 26 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp/param_parser.py: -------------------------------------------------------------------------------- 1 | """Getting the parameters from the commandline.""" 2 | 3 | import argparse 4 | 5 | def parameter_parser(): 6 | """ 7 | A method to parse up command line parameters. By default it trains on the Cora dataset. 8 | The default hyperparameters give a good quality representation without grid search. 9 | """ 10 | parser = argparse.ArgumentParser(description="Run PPNP/APPNP.") 11 | 12 | parser.add_argument("--edge-path", 13 | nargs="?", 14 | default="./input/cora_edges.csv", 15 | help="Edge list csv.") 16 | 17 | parser.add_argument("--features-path", 18 | nargs="?", 19 | default="./input/cora_features.json", 20 | help="Features json.") 21 | 22 | parser.add_argument("--target-path", 23 | nargs="?", 24 | default="./input/cora_target.csv", 25 | help="Target classes csv.") 26 | 27 | parser.add_argument("--model", 28 | nargs="?", 29 | default="exact", 30 | help="Model type.") 31 | 32 | parser.add_argument("--epochs", 33 | type=int, 34 | default=2000, 35 | help="Number of training epochs. Default is 2000.") 36 | 37 | parser.add_argument("--seed", 38 | type=int, 39 | default=42, 40 | help="Random seed for train-test split. Default is 42.") 41 | 42 | parser.add_argument("--iterations", 43 | type=int, 44 | default=10, 45 | help="Number of Approximate Personalized PageRank iterations. Default is 10.") 46 | 47 | parser.add_argument("--early-stopping-rounds", 48 | type=int, 49 | default=500, 50 | help="Number of training rounds before early stopping. Default is 10.") 51 | 52 | parser.add_argument("--train-size", 53 | type=int, 54 | default=1500, 55 | help="Training set size. Default is 1500.") 56 | 57 | parser.add_argument("--test-size", 58 | type=int, 59 | default=500, 60 | help="Test set size. Default is 500.") 61 | 62 | parser.add_argument("--dropout", 63 | type=float, 64 | default=0.5, 65 | help="Dropout parameter. Default is 0.5.") 66 | 67 | parser.add_argument("--alpha", 68 | type=float, 69 | default=0.1, 70 | help="Page rank teleport parameter. Default is 0.1.") 71 | 72 | parser.add_argument("--learning-rate", 73 | type=float, 74 | default=0.01, 75 | help="Learning rate. Default is 0.01.") 76 | 77 | parser.add_argument("--lambd", 78 | type=float, 79 | default=0.005, 80 | help="Weight matrix regularization. Default is 0.005.") 81 | 82 | parser.add_argument("--layers", 83 | nargs="+", 84 | type=int, 85 | help="Layer dimensions separated by space. E.g. 64 64.") 86 | 87 | parser.set_defaults(layers=[64, 64]) 88 | 89 | return parser.parse_args() 90 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/appnp_run.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/appnp_run.jpg -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/build/lib/appnp/__init__.py: -------------------------------------------------------------------------------- 1 | import appnp.main_jl -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/build/lib/appnp/main.py: -------------------------------------------------------------------------------- 1 | """ Running the APPNP model.""" 2 | 3 | import torch 4 | from appnp.appnp import APPNPTrainer 5 | from appnp.param_parser import parameter_parser 6 | from appnp.utils import tab_printer, graph_reader, feature_reader, target_reader 7 | 8 | import os 9 | os.chdir((os.path.dirname(os.path.realpath(__file__)))) 10 | 11 | def main(): 12 | """ 13 | Parsing command line parameters, reading data, fitting an APPNP/PPNP and scoring the model. 14 | """ 15 | args = parameter_parser() 16 | torch.manual_seed(args.seed) 17 | tab_printer(args) 18 | graph = graph_reader(args.edge_path) 19 | features = feature_reader(args.features_path) 20 | target = target_reader(args.target_path) 21 | trainer = APPNPTrainer(args, graph, features, target) 22 | trainer.fit() 23 | 24 | if __name__ == "__main__": 25 | main() 26 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/build/lib/appnp/main_jl.py: -------------------------------------------------------------------------------- 1 | """ Running the APPNP model.""" 2 | 3 | import torch 4 | import os 5 | import sys 6 | from appnp.appnp import APPNPTrainer 7 | from appnp.param_parser import parameter_parser 8 | from appnp.utils import tab_printer, graph_reader, graph_reader_from_var,\ 9 | feature_reader, target_reader, feature_reader_from_var 10 | 11 | from argparse import Namespace 12 | 13 | def main(args, edges, features, target): 14 | """ 15 | Parsing command line parameters, reading data, fitting an APPNP/PPNP and scoring the model. 16 | """ 17 | args = Namespace(**args) 18 | torch.manual_seed(args.seed) 19 | tab_printer(args) 20 | 21 | edges = [list(a) for a in edges] 22 | graph = graph_reader_from_var(edges) 23 | features = feature_reader_from_var(features) 24 | trainer = APPNPTrainer(args, graph, features, target) 25 | result = trainer.fit() 26 | return result.detach().numpy() 27 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/build/lib/appnp/param_parser.py: -------------------------------------------------------------------------------- 1 | """Getting the parameters from the commandline.""" 2 | 3 | import argparse 4 | 5 | def parameter_parser(): 6 | """ 7 | A method to parse up command line parameters. By default it trains on the Cora dataset. 8 | The default hyperparameters give a good quality representation without grid search. 9 | """ 10 | parser = argparse.ArgumentParser(description="Run PPNP/APPNP.") 11 | 12 | parser.add_argument("--edge-path", 13 | nargs="?", 14 | default="./input/cora_edges.csv", 15 | help="Edge list csv.") 16 | 17 | parser.add_argument("--features-path", 18 | nargs="?", 19 | default="./input/cora_features.json", 20 | help="Features json.") 21 | 22 | parser.add_argument("--target-path", 23 | nargs="?", 24 | default="./input/cora_target.csv", 25 | help="Target classes csv.") 26 | 27 | parser.add_argument("--model", 28 | nargs="?", 29 | default="exact", 30 | help="Model type.") 31 | 32 | parser.add_argument("--epochs", 33 | type=int, 34 | default=2000, 35 | help="Number of training epochs. Default is 2000.") 36 | 37 | parser.add_argument("--seed", 38 | type=int, 39 | default=42, 40 | help="Random seed for train-test split. Default is 42.") 41 | 42 | parser.add_argument("--iterations", 43 | type=int, 44 | default=10, 45 | help="Number of Approximate Personalized PageRank iterations. Default is 10.") 46 | 47 | parser.add_argument("--early-stopping-rounds", 48 | type=int, 49 | default=500, 50 | help="Number of training rounds before early stopping. Default is 10.") 51 | 52 | parser.add_argument("--train-size", 53 | type=int, 54 | default=1500, 55 | help="Training set size. Default is 1500.") 56 | 57 | parser.add_argument("--test-size", 58 | type=int, 59 | default=500, 60 | help="Test set size. Default is 500.") 61 | 62 | parser.add_argument("--dropout", 63 | type=float, 64 | default=0.5, 65 | help="Dropout parameter. Default is 0.5.") 66 | 67 | parser.add_argument("--alpha", 68 | type=float, 69 | default=0.1, 70 | help="Page rank teleport parameter. Default is 0.1.") 71 | 72 | parser.add_argument("--learning-rate", 73 | type=float, 74 | default=0.01, 75 | help="Learning rate. Default is 0.01.") 76 | 77 | parser.add_argument("--lambd", 78 | type=float, 79 | default=0.005, 80 | help="Weight matrix regularization. Default is 0.005.") 81 | 82 | parser.add_argument("--layers", 83 | nargs="+", 84 | type=int, 85 | help="Layer dimensions separated by space. E.g. 64 64.") 86 | 87 | parser.set_defaults(layers=[64, 64]) 88 | 89 | return parser.parse_args() 90 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/build/scripts-3.6/main_jl.py: -------------------------------------------------------------------------------- 1 | """ Running the APPNP model.""" 2 | 3 | import torch 4 | import os 5 | import sys 6 | from appnp.appnp import APPNPTrainer 7 | from appnp.param_parser import parameter_parser 8 | from appnp.utils import tab_printer, graph_reader, graph_reader_from_var,\ 9 | feature_reader, target_reader, feature_reader_from_var 10 | 11 | from argparse import Namespace 12 | 13 | def main(args, edges, features, target): 14 | """ 15 | Parsing command line parameters, reading data, fitting an APPNP/PPNP and scoring the model. 16 | """ 17 | args = Namespace(**args) 18 | torch.manual_seed(args.seed) 19 | tab_printer(args) 20 | 21 | edges = [list(a) for a in edges] 22 | graph = graph_reader_from_var(edges) 23 | features = feature_reader_from_var(features) 24 | trainer = APPNPTrainer(args, graph, features, target) 25 | result = trainer.fit() 26 | return result.detach().numpy() 27 | -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/dist/appnp-0.1-py3.6.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/dist/appnp-0.1-py3.6.egg -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/ppnp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/APPNP/ppnp.jpg -------------------------------------------------------------------------------- /competitors/competitors_setups/APPNP/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from setuptools import find_packages 3 | 4 | setup(name='appnp', 5 | version='0.1', 6 | url='https://github.com/benedekrozemberczki/APPNP', 7 | packages=['appnp'], 8 | scripts=['appnp/main_jl.py'], 9 | license='Proprietary License', 10 | include_package_data=True, 11 | zip_safe=False) -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/build/lib/hgnn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/build/lib/hgnn/__init__.py -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/dist/hgnn-0.1-py3.6.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/dist/hgnn-0.1-py3.6.egg -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: hgnn 3 | Version: 0.1 4 | Summary: UNKNOWN 5 | Home-page: https://github.com/iMoonLab/HGNN 6 | License: Proprietary License 7 | Platform: UNKNOWN 8 | 9 | UNKNOWN 10 | 11 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | setup.py 2 | hgnn/__init__.py 3 | hgnn/train.py 4 | hgnn/train_jl.py 5 | hgnn.egg-info/PKG-INFO 6 | hgnn.egg-info/SOURCES.txt 7 | hgnn.egg-info/dependency_links.txt 8 | hgnn.egg-info/not-zip-safe 9 | hgnn.egg-info/top_level.txt -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | hgnn 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Yue's Group of THU 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/__init__.py -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/__pycache__/train.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/__pycache__/train.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/__pycache__/train_jl.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/__pycache__/train_jl.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/__pycache__/train_jl.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/__pycache__/train_jl.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/config/__init__.py: -------------------------------------------------------------------------------- 1 | from .config import get_config 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/config/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/config/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/config/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/config/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/config/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/config/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/config/__pycache__/config.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/config/__pycache__/config.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/config/__pycache__/config.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/config/__pycache__/config.cpython-37.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/config/__pycache__/config.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/config/__pycache__/config.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/config/config.py: -------------------------------------------------------------------------------- 1 | import os 2 | import yaml 3 | import os.path as osp 4 | 5 | 6 | def get_config(dir='config/config.yaml'): 7 | # add direction join function when parse the yaml file 8 | def join(loader, node): 9 | seq = loader.construct_sequence(node) 10 | return os.path.sep.join(seq) 11 | 12 | # add string concatenation function when parse the yaml file 13 | def concat(loader, node): 14 | seq = loader.construct_sequence(node) 15 | seq = [str(tmp) for tmp in seq] 16 | return ''.join(seq) 17 | 18 | yaml.add_constructor('!join', join) 19 | yaml.add_constructor('!concat', concat) 20 | with open(dir, 'r') as f: 21 | cfg = yaml.load(f) 22 | 23 | #check_dirs(cfg) 24 | 25 | return cfg 26 | 27 | 28 | def check_dir(folder, mk_dir=True): 29 | if not osp.exists(folder): 30 | if mk_dir: 31 | print(f'making direction {folder}!') 32 | os.mkdir(folder) 33 | else: 34 | raise Exception(f'Not exist direction {folder}') 35 | 36 | 37 | def check_dirs(cfg): 38 | check_dir(cfg['data_root'], mk_dir=False) 39 | 40 | check_dir(cfg['result_root']) 41 | check_dir(cfg['ckpt_folder']) 42 | check_dir(cfg['result_sub_folder']) 43 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/config/config.yaml: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------# 2 | # must check the direction of data_root and result_root before run # 3 | #------------------------------------------------------------------# 4 | 5 | #configure feature path 6 | # **** please must modify the data_root before first running **** 7 | data_root: &d_r ../data 8 | modelnet40_ft: !join [*d_r, ModelNet40_mvcnn_gvcnn.mat] 9 | ntu2012_ft: !join [*d_r, NTU2012_mvcnn_gvcnn.mat] 10 | 11 | 12 | #Hypergraph 13 | graph_type: &g_t hypergraph 14 | K_neigs: [10] 15 | #K_neigs: [10, 15 ] 16 | m_prob: 1.0 17 | is_probH: True 18 | #--------------------------------------- 19 | # change me 20 | use_mvcnn_feature_for_structure: True 21 | use_gvcnn_feature_for_structure: True 22 | #--------------------------------------- 23 | 24 | 25 | #Model 26 | #-------------------------------------------------- 27 | # select the dataset you use, ModelNet40 or NTU2012 28 | on_dataset: &o_d ModelNet40 29 | #on_dataset: &o_d NTU2012 30 | #-------------------------------------------------- 31 | 32 | #--------------------------------------- 33 | # change me 34 | use_mvcnn_feature: False 35 | use_gvcnn_feature: True 36 | #--------------------------------------- 37 | 38 | 39 | #Result 40 | # configure result path 41 | # **** please must modify the result_root before first running **** 42 | result_root: &r_r ./result 43 | result_sub_folder: !join [*r_r, !concat [ *g_t, _, *o_d ]] 44 | ckpt_folder: !join [*r_r, ckpt] 45 | 46 | 47 | #Train 48 | max_epoch: 600 49 | n_hid: 128 50 | lr: 0.001 51 | milestones: [100] 52 | gamma: 0.9 53 | drop_out: 0.5 54 | print_freq: 50 55 | weight_decay: 0.0005 56 | decay_step: 200 57 | decay_rate: 0.7 58 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/data/features.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/data/features.pickle -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/data/hypergraph.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/data/hypergraph.pickle -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/data/labels.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/data/labels.pickle -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | from .data_helper import load_ft 2 | from .visual_data import load_feature_construct_H -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/data_helper.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/data_helper.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/data_helper.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/data_helper.cpython-37.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/data_helper.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/data_helper.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/visual_data.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/visual_data.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/visual_data.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/visual_data.cpython-37.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/visual_data.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/datasets/__pycache__/visual_data.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/data_helper.py: -------------------------------------------------------------------------------- 1 | import scipy.io as scio 2 | import numpy as np 3 | 4 | 5 | def load_ft(data_dir, feature_name='GVCNN'): 6 | data = scio.loadmat(data_dir) 7 | lbls = data['Y'].astype(np.long) 8 | if lbls.min() == 1: 9 | lbls = lbls - 1 10 | idx = data['indices'].item() 11 | 12 | if feature_name == 'MVCNN': 13 | fts = data['X'][0].item().astype(np.float32) 14 | elif feature_name == 'GVCNN': 15 | fts = data['X'][1].item().astype(np.float32) 16 | else: 17 | print(f'wrong feature name{feature_name}!') 18 | raise IOError 19 | 20 | idx_train = np.where(idx == 1)[0] 21 | idx_test = np.where(idx == 0)[0] 22 | return fts, lbls, idx_train, idx_test 23 | 24 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/datasets/visual_data.py: -------------------------------------------------------------------------------- 1 | from hgnn.datasets import load_ft 2 | from hgnn.utils import hypergraph_utils as hgut 3 | 4 | 5 | def load_feature_construct_H(fts, lbls, idx_train, idx_test, 6 | m_prob=1, 7 | K_neigs=[10], 8 | is_probH=True, 9 | split_diff_scale=False, 10 | use_mvcnn_feature=False, 11 | use_gvcnn_feature=True, 12 | use_mvcnn_feature_for_structure=False, 13 | use_gvcnn_feature_for_structure=True): 14 | """ 15 | 16 | :param data_dir: directory of feature data 17 | :param m_prob: parameter in hypergraph incidence matrix construction 18 | :param K_neigs: the number of neighbor expansion 19 | :param is_probH: probability Vertex-Edge matrix or binary 20 | :param use_mvcnn_feature: 21 | :param use_gvcnn_feature: 22 | :param use_mvcnn_feature_for_structure: 23 | :param use_gvcnn_feature_for_structure: 24 | :return: 25 | """ 26 | # init feature 27 | if use_mvcnn_feature or use_mvcnn_feature_for_structure: 28 | mvcnn_ft, lbls, idx_train, idx_test = fts, lbls, idx_train, idx_test 29 | if use_gvcnn_feature or use_gvcnn_feature_for_structure: 30 | gvcnn_ft, lbls, idx_train, idx_test = fts, lbls, idx_train, idx_test 31 | # if 'mvcnn_ft' not in dir() and 'gvcnn_ft' not in dir(): 32 | # raise Exception('None feature initialized') 33 | 34 | # construct feature matrix 35 | fts = None 36 | if use_mvcnn_feature: 37 | fts = hgut.feature_concat(fts, mvcnn_ft) 38 | if use_gvcnn_feature: 39 | fts = hgut.feature_concat(fts, gvcnn_ft) 40 | if fts is None: 41 | raise Exception(f'None feature used for model!') 42 | 43 | # construct hypergraph incidence matrix 44 | print('Constructing hypergraph incidence matrix! \n(It may take several minutes! Please wait patiently!)') 45 | H = None 46 | if use_mvcnn_feature_for_structure: 47 | tmp = hgut.construct_H_with_KNN(mvcnn_ft, K_neigs=K_neigs, 48 | split_diff_scale=split_diff_scale, 49 | is_probH=is_probH, m_prob=m_prob) 50 | H = hgut.hyperedge_concat(H, tmp) 51 | if use_gvcnn_feature_for_structure: 52 | tmp = hgut.construct_H_with_KNN(gvcnn_ft, K_neigs=K_neigs, 53 | split_diff_scale=split_diff_scale, 54 | is_probH=is_probH, m_prob=m_prob) 55 | H = hgut.hyperedge_concat(H, tmp) 56 | if H is None: 57 | raise Exception('None feature to construct hypergraph incidence matrix!') 58 | 59 | return fts, lbls, idx_train, idx_test, H 60 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/doc/pipline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/doc/pipline.png -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/HGNN.py: -------------------------------------------------------------------------------- 1 | from torch import nn 2 | from hgnn.models import HGNN_conv 3 | import torch.nn.functional as F 4 | 5 | 6 | class HGNN(nn.Module): 7 | def __init__(self, in_ch, n_class, n_hid, dropout=0.5): 8 | super(HGNN, self).__init__() 9 | self.dropout = dropout 10 | self.hgc1 = HGNN_conv(in_ch, n_hid) 11 | self.hgc2 = HGNN_conv(n_hid, n_class) 12 | 13 | def forward(self, x, G): 14 | x = F.relu(self.hgc1(x, G)) 15 | x = F.dropout(x, self.dropout) 16 | x = self.hgc2(x, G) 17 | return x 18 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .layers import HGNN_conv, HGNN_fc, HGNN_embedding, HGNN_classifier 2 | from .HGNN import HGNN 3 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/__pycache__/HGNN.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/models/__pycache__/HGNN.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/__pycache__/HGNN.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/models/__pycache__/HGNN.cpython-37.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/__pycache__/HGNN.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/models/__pycache__/HGNN.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/models/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/models/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/models/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/__pycache__/layers.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/models/__pycache__/layers.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/__pycache__/layers.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/models/__pycache__/layers.cpython-37.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/__pycache__/layers.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/models/__pycache__/layers.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/models/layers.py: -------------------------------------------------------------------------------- 1 | import math 2 | import torch 3 | import torch.nn as nn 4 | import torch.nn.functional as F 5 | from torch.nn.parameter import Parameter 6 | 7 | 8 | class HGNN_conv(nn.Module): 9 | def __init__(self, in_ft, out_ft, bias=True): 10 | super(HGNN_conv, self).__init__() 11 | 12 | self.weight = Parameter(torch.Tensor(in_ft, out_ft)) 13 | if bias: 14 | self.bias = Parameter(torch.Tensor(out_ft)) 15 | else: 16 | self.register_parameter('bias', None) 17 | self.reset_parameters() 18 | 19 | def reset_parameters(self): 20 | stdv = 1. / math.sqrt(self.weight.size(1)) 21 | self.weight.data.uniform_(-stdv, stdv) 22 | if self.bias is not None: 23 | self.bias.data.uniform_(-stdv, stdv) 24 | 25 | def forward(self, x: torch.Tensor, G: torch.Tensor): 26 | x = x.matmul(self.weight) 27 | if self.bias is not None: 28 | x = x + self.bias 29 | x = G.matmul(x) 30 | return x 31 | 32 | 33 | class HGNN_fc(nn.Module): 34 | def __init__(self, in_ch, out_ch): 35 | super(HGNN_fc, self).__init__() 36 | self.fc = nn.Linear(in_ch, out_ch) 37 | 38 | def forward(self, x): 39 | return self.fc(x) 40 | 41 | 42 | class HGNN_embedding(nn.Module): 43 | def __init__(self, in_ch, n_hid, dropout=0.5): 44 | super(HGNN_embedding, self).__init__() 45 | self.dropout = dropout 46 | self.hgc1 = HGNN_conv(in_ch, n_hid) 47 | self.hgc2 = HGNN_conv(n_hid, n_hid) 48 | 49 | def forward(self, x, G): 50 | x = F.relu(self.hgc1(x, G)) 51 | x = F.dropout(x, self.dropout) 52 | x = F.relu(self.hgc2(x, G)) 53 | return x 54 | 55 | 56 | class HGNN_classifier(nn.Module): 57 | def __init__(self, n_hid, n_class): 58 | super(HGNN_classifier, self).__init__() 59 | self.fc1 = nn.Linear(n_hid, n_class) 60 | 61 | def forward(self, x): 62 | x = self.fc1(x) 63 | return x -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/utils/__pycache__/hypergraph_utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/utils/__pycache__/hypergraph_utils.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/utils/__pycache__/hypergraph_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/utils/__pycache__/hypergraph_utils.cpython-37.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/hgnn/utils/__pycache__/hypergraph_utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HGNN/hgnn/utils/__pycache__/hypergraph_utils.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HGNN/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from setuptools import find_packages 3 | 4 | setup(name='hgnn', 5 | version='0.1', 6 | url='https://github.com/iMoonLab/HGNN', 7 | packages=['hgnn'], 8 | scripts=['hgnn/train_jl.py'], 9 | license='Proprietary License', 10 | include_package_data=True, 11 | zip_safe=False) -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/README.md: -------------------------------------------------------------------------------- 1 | # HyperGCN: A New Method of Training Graph Convolutional Networks on Hypergraphs 2 | 3 | [![Conference](http://img.shields.io/badge/NeurIPS-2019-4b44ce.svg)](https://nips.cc/) [![Paper](http://img.shields.io/badge/paper-arxiv.1809.02589-B31B1B.svg)](https://arxiv.org/abs/1809.02589) 4 | 5 | Source code for [NeurIPS 2019](https://nips.cc/) paper: [**HyperGCN: A New Method of Training Graph Convolutional Networks on Hypergraphs**](https://papers.nips.cc/paper/8430-hypergcn-a-new-method-for-training-graph-convolutional-networks-on-hypergraphs) 6 | 7 | ![](./hmlap.png) 8 | 9 | **Overview of HyperGCN:** *Given a hypergraph and node features, HyperGCN approximates the hypergraph by a graph in which each hyperedge is approximated by a subgraph consisting of an edge between maximally disparate nodes and edges between each of these and every other node (mediator) of the hyperedge. A graph convolutional network (GCN) is then run on the resulting graph approximation. * 10 | 11 | ### Dependencies 12 | 13 | - Compatible with PyTorch 1.0 and Python 3.x. 14 | - For data (and/or splits) not used in the paper, please consider tuning hyperparameters such as [hidden size](https://github.com/malllabiisc/HyperGCN/blob/master/model/networks.py#L25), [learning rate](https://github.com/malllabiisc/HyperGCN/blob/master/config/config.py#L49), [seed](https://github.com/malllabiisc/HyperGCN/blob/master/config/config.py#L28), etc. on validation data. 15 | 16 | ### Training model (Node classifiction): 17 | 18 | - To start training run: 19 | 20 | ```shell 21 | python hypergcn.py --mediators True --split 1 --data coauthorship --dataset dblp 22 | ``` 23 | 24 | - `--mediators` denotes whether to use mediators (True) or not (False) 25 | - `--split` is the train-test split number 26 | 27 | 28 | ### Citation: 29 | 30 | ```bibtex 31 | @incollection{hypergcn_neurips19, 32 | title = {HyperGCN: A New Method For Training Graph Convolutional Networks on Hypergraphs}, 33 | author = {Yadati, Naganand and Nimishakavi, Madhav and Yadav, Prateek and Nitin, Vikram and Louis, Anand and Talukdar, Partha}, 34 | booktitle = {Advances in Neural Information Processing Systems (NeurIPS) 32}, 35 | pages = {1509--1520}, 36 | year = {2019}, 37 | publisher = {Curran Associates, Inc.} 38 | } 39 | 40 | ``` 41 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/__pycache__/hypergcn_jl.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HyperGCN/__pycache__/hypergcn_jl.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/build/lib/hypergcn/hypergcn.py: -------------------------------------------------------------------------------- 1 | # parse arguments ([ConfigArgParse](https://github.com/bw2/ConfigArgParse)) 2 | from config import config 3 | args = config.parse() 4 | 5 | 6 | 7 | # seed 8 | import os, torch, numpy as np 9 | torch.manual_seed(args.seed) 10 | np.random.seed(args.seed) 11 | 12 | 13 | 14 | # gpu, seed 15 | os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" 16 | os.environ["CUDA_VISIBLE_DEVICES"] = str(args.gpu) 17 | os.environ['PYTHONHASHSEED'] = str(args.seed) 18 | 19 | 20 | 21 | # load data 22 | from data import data 23 | dataset, train, test = data.load(args) 24 | print("length of train is", len(train)) 25 | 26 | 27 | 28 | # # initialise HyperGCN 29 | from model import model 30 | HyperGCN = model.initialise(dataset, args) 31 | 32 | 33 | 34 | # train and test HyperGCN 35 | HyperGCN = model.train(HyperGCN, dataset, train, args) 36 | acc, H, Z = model.test(HyperGCN, dataset, test, args) 37 | print("accuracy:", float(acc), ", error:", float(100*(1-acc))) 38 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/build/lib/hypergcn/hypergcn_jl.py: -------------------------------------------------------------------------------- 1 | # parse arguments ([ConfigArgParse](https://github.com/bw2/ConfigArgParse)) 2 | # from config import config 3 | from argparse import Namespace 4 | from hypergcn.model import model 5 | 6 | def train(args, X, y, hypergraph, train, test): 7 | args = Namespace(**args) 8 | #args = config.parse() 9 | dataset = {'hypergraph': hypergraph, 'features': X.todense(), 'labels': y, 'n': len(y)} 10 | 11 | #print(X.shape) 12 | #print(y.shape) 13 | #print(INC) 14 | #print(train[:10]) 15 | #print(test) 16 | #print(args) 17 | 18 | # seed 19 | import os, torch, numpy as np 20 | torch.manual_seed(args.seed) 21 | np.random.seed(args.seed) 22 | 23 | 24 | 25 | # gpu, seed 26 | os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" 27 | os.environ["CUDA_VISIBLE_DEVICES"] = str(args.gpu) 28 | os.environ['PYTHONHASHSEED'] = str(args.seed) 29 | 30 | 31 | 32 | # load data 33 | #dataset, train, test = data.load(args) 34 | #print(type(dataset['features'])) 35 | #print(type(X)) 36 | #print(dataset['hypergraph']) 37 | #print(train[:10]) 38 | #print(test[:10]) 39 | print("length of train is", len(train)) 40 | 41 | 42 | 43 | 44 | # # initialise HyperGCN 45 | HyperGCN = model.initialise(dataset, args) 46 | 47 | 48 | 49 | # train and test HyperGCN 50 | HyperGCN = model.train(HyperGCN, dataset, train, args) 51 | acc, H, Z = model.test(HyperGCN, dataset, test, args) 52 | return float(acc), H.cpu().detach().numpy(), Z.cpu().detach().numpy() 53 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/build/scripts-3.6/hypergcn_jl.py: -------------------------------------------------------------------------------- 1 | # parse arguments ([ConfigArgParse](https://github.com/bw2/ConfigArgParse)) 2 | # from config import config 3 | from argparse import Namespace 4 | from hypergcn.model import model 5 | 6 | def train(args, X, y, hypergraph, train, test): 7 | args = Namespace(**args) 8 | #args = config.parse() 9 | dataset = {'hypergraph': hypergraph, 'features': X.todense(), 'labels': y, 'n': len(y)} 10 | 11 | #print(X.shape) 12 | #print(y.shape) 13 | #print(INC) 14 | #print(train[:10]) 15 | #print(test) 16 | #print(args) 17 | 18 | # seed 19 | import os, torch, numpy as np 20 | torch.manual_seed(args.seed) 21 | np.random.seed(args.seed) 22 | 23 | 24 | 25 | # gpu, seed 26 | os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" 27 | os.environ["CUDA_VISIBLE_DEVICES"] = str(args.gpu) 28 | os.environ['PYTHONHASHSEED'] = str(args.seed) 29 | 30 | 31 | 32 | # load data 33 | #dataset, train, test = data.load(args) 34 | #print(type(dataset['features'])) 35 | #print(type(X)) 36 | #print(dataset['hypergraph']) 37 | #print(train[:10]) 38 | #print(test[:10]) 39 | print("length of train is", len(train)) 40 | 41 | 42 | 43 | 44 | # # initialise HyperGCN 45 | HyperGCN = model.initialise(dataset, args) 46 | 47 | 48 | 49 | # train and test HyperGCN 50 | HyperGCN = model.train(HyperGCN, dataset, train, args) 51 | acc, H, Z = model.test(HyperGCN, dataset, test, args) 52 | return float(acc), H.cpu().detach().numpy(), Z.cpu().detach().numpy() 53 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/dist/hypergcn-0.1-py3.6.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HyperGCN/dist/hypergcn-0.1-py3.6.egg -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: hypergcn 3 | Version: 0.1 4 | Summary: UNKNOWN 5 | Home-page: https://github.com/malllabiisc/HyperGCN 6 | License: Proprietary License 7 | Platform: UNKNOWN 8 | License-File: LICENSE 9 | 10 | UNKNOWN 11 | 12 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE 2 | README.md 3 | setup.py 4 | hypergcn/hypergcn.py 5 | hypergcn/hypergcn_jl.py 6 | hypergcn.egg-info/PKG-INFO 7 | hypergcn.egg-info/SOURCES.txt 8 | hypergcn.egg-info/dependency_links.txt 9 | hypergcn.egg-info/not-zip-safe 10 | hypergcn.egg-info/top_level.txt -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | hypergcn 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn/config/coauthorship.yml: -------------------------------------------------------------------------------- 1 | gpu: 0 -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn/config/config.py: -------------------------------------------------------------------------------- 1 | ''' 2 | data: coauthorship/cocitation 3 | dataset: cora/dblp/acm for coauthorship and cora/citeseer/pubmed for cocitation 4 | ''' 5 | data = "cocitation" 6 | dataset = "citeseer" 7 | 8 | 9 | 10 | ''' 11 | mediators: Laplacian with mediators (True) or Laplacian without mediators (False) 12 | fast: FastHyperGCN (True) or not fast (False) 13 | split: train-test split used for the dataset 14 | ''' 15 | mediators = False 16 | fast = False 17 | split = 1 18 | 19 | 20 | 21 | ''' 22 | gpu: gpu number to use 23 | cuda: True or False 24 | seed: an integer 25 | ''' 26 | gpu = 3 27 | cuda = True 28 | seed = 5 29 | 30 | 31 | 32 | ''' 33 | model related parameters 34 | depth: number of hidden layers in the graph convolutional network (GCN) 35 | dropout: dropout probability for GCN hidden layer 36 | epochs: number of training epochs 37 | ''' 38 | depth = 2 39 | dropout = 0.5 40 | epochs = 200 41 | 42 | 43 | 44 | ''' 45 | parameters for optimisation 46 | rate: learning rate 47 | decay: weight decay 48 | ''' 49 | rate = 0.01 50 | decay = 0.0005 51 | 52 | 53 | 54 | import configargparse, os,sys,inspect 55 | from configargparse import YAMLConfigFileParser 56 | 57 | 58 | 59 | def parse(): 60 | """ 61 | adds and parses arguments / hyperparameters 62 | """ 63 | default = os.path.join(current(), data + ".yml") 64 | p = configargparse.ArgParser(config_file_parser_class = YAMLConfigFileParser, default_config_files=[default]) 65 | p.add('-c', '--my-config', is_config_file=True, help='config file path') 66 | p.add('--data', type=str, default=data, help='data name (coauthorship/cocitation)') 67 | p.add('--dataset', type=str, default=dataset, help='dataset name (e.g.: cora/dblp/acm for coauthorship, cora/citeseer/pubmed for cocitation)') 68 | p.add('--mediators', type=bool, default=mediators, help='True for Laplacian with mediators, False for Laplacian without mediators') 69 | p.add('--fast', type=bool, default=fast, help='faster version of HyperGCN (True)') 70 | p.add('--split', type=int, default=split, help='train-test split used for the dataset') 71 | p.add('--depth', type=int, default=depth, help='number of hidden layers') 72 | p.add('--dropout', type=float, default=dropout, help='dropout probability for GCN hidden layer') 73 | p.add('--rate', type=float, default=rate, help='learning rate') 74 | p.add('--decay', type=float, default=decay, help='weight decay') 75 | p.add('--epochs', type=int, default=epochs, help='number of epochs to train') 76 | p.add('--gpu', type=int, default=gpu, help='gpu number to use') 77 | p.add('--cuda', type=bool, default=cuda, help='cuda for gpu') 78 | p.add('--seed', type=int, default=seed, help='seed for randomness') 79 | p.add('-f') # for jupyter default 80 | return p.parse_args() 81 | 82 | 83 | 84 | def current(): 85 | """ 86 | returns the current directory path 87 | """ 88 | current = os.path.abspath(inspect.getfile(inspect.currentframe())) 89 | head, tail = os.path.split(current) 90 | return head 91 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn/data/data.py: -------------------------------------------------------------------------------- 1 | import os, inspect, random, pickle 2 | import numpy as np, scipy.sparse as sp 3 | from tqdm import tqdm 4 | import pickle 5 | 6 | 7 | def load(args): 8 | """ 9 | parses the dataset 10 | """ 11 | dataset = parser(args.data, args.dataset).parse() 12 | 13 | current = os.path.abspath(inspect.getfile(inspect.currentframe())) 14 | Dir, _ = os.path.split(current) 15 | file = os.path.join(Dir, args.data, args.dataset, "splits", str(args.split) + ".pickle") 16 | 17 | if not os.path.isfile(file): print("split + ", str(args.split), "does not exist") 18 | with open(file, 'rb') as H: 19 | Splits = pickle.load(H) 20 | train, test = Splits['train'], Splits['test'] 21 | 22 | return dataset, train, test 23 | 24 | 25 | 26 | class parser(object): 27 | """ 28 | an object for parsing data 29 | """ 30 | 31 | def __init__(self, data, dataset): 32 | """ 33 | initialises the data directory 34 | 35 | arguments: 36 | data: coauthorship/cocitation 37 | dataset: cora/dblp/acm for coauthorship and cora/citeseer/pubmed for cocitation 38 | """ 39 | 40 | current = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) 41 | self.d = os.path.join(current, data, dataset) 42 | self.data, self.dataset = data, dataset 43 | 44 | 45 | 46 | def parse(self): 47 | """ 48 | returns a dataset specific function to parse 49 | """ 50 | 51 | name = "_load_data" 52 | function = getattr(self, name, lambda: {}) 53 | return function() 54 | 55 | 56 | 57 | def _load_data(self): 58 | """ 59 | loads the coauthorship hypergraph, features, and labels of cora 60 | 61 | assumes the following files to be present in the dataset directory: 62 | hypergraph.pickle: coauthorship hypergraph 63 | features.pickle: bag of word features 64 | labels.pickle: labels of papers 65 | 66 | n: number of hypernodes 67 | returns: a dictionary with hypergraph, features, and labels as keys 68 | """ 69 | 70 | with open(os.path.join(self.d, 'hypergraph.pickle'), 'rb') as handle: 71 | hypergraph = pickle.load(handle) 72 | print("number of hyperedges is", len(hypergraph)) 73 | 74 | with open(os.path.join(self.d, 'features.pickle'), 'rb') as handle: 75 | features = pickle.load(handle).todense() 76 | 77 | with open(os.path.join(self.d, 'labels.pickle'), 'rb') as handle: 78 | labels = self._1hot(pickle.load(handle)) 79 | 80 | return {'hypergraph': hypergraph, 'features': features, 'labels': labels, 'n': features.shape[0]} 81 | 82 | 83 | 84 | def _1hot(self, labels): 85 | """ 86 | converts each positive integer (representing a unique class) into ints one-hot form 87 | 88 | Arguments: 89 | labels: a list of positive integers with eah integer representing a unique label 90 | """ 91 | 92 | classes = set(labels) 93 | onehot = {c: np.identity(len(classes))[i, :] for i, c in enumerate(classes)} 94 | return np.array(list(map(onehot.get, labels)), dtype=np.int32) 95 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn/hmlap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/HyperGCN/hypergcn/hmlap.png -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn/hypergcn.py: -------------------------------------------------------------------------------- 1 | # parse arguments ([ConfigArgParse](https://github.com/bw2/ConfigArgParse)) 2 | from config import config 3 | args = config.parse() 4 | 5 | 6 | 7 | # seed 8 | import os, torch, numpy as np 9 | torch.manual_seed(args.seed) 10 | np.random.seed(args.seed) 11 | 12 | 13 | 14 | # gpu, seed 15 | os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" 16 | os.environ["CUDA_VISIBLE_DEVICES"] = str(args.gpu) 17 | os.environ['PYTHONHASHSEED'] = str(args.seed) 18 | 19 | 20 | 21 | # load data 22 | from data import data 23 | dataset, train, test = data.load(args) 24 | print("length of train is", len(train)) 25 | 26 | 27 | 28 | # # initialise HyperGCN 29 | from model import model 30 | HyperGCN = model.initialise(dataset, args) 31 | 32 | 33 | 34 | # train and test HyperGCN 35 | HyperGCN = model.train(HyperGCN, dataset, train, args) 36 | acc, H, Z = model.test(HyperGCN, dataset, test, args) 37 | print("accuracy:", float(acc), ", error:", float(100*(1-acc))) 38 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn/hypergcn_jl.py: -------------------------------------------------------------------------------- 1 | # parse arguments ([ConfigArgParse](https://github.com/bw2/ConfigArgParse)) 2 | # from config import config 3 | from argparse import Namespace 4 | from hypergcn.model import model 5 | 6 | def train(args, X, y, hypergraph, train, test): 7 | args = Namespace(**args) 8 | #args = config.parse() 9 | dataset = {'hypergraph': hypergraph, 'features': X.todense(), 'labels': y, 'n': len(y)} 10 | 11 | 12 | # seed 13 | import os, torch, numpy as np 14 | torch.manual_seed(args.seed) 15 | np.random.seed(args.seed) 16 | 17 | 18 | 19 | # gpu, seed 20 | os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" 21 | os.environ["CUDA_VISIBLE_DEVICES"] = str(args.gpu) 22 | os.environ['PYTHONHASHSEED'] = str(args.seed) 23 | 24 | 25 | 26 | # load data 27 | #dataset, train, test = data.load(args) 28 | print("length of train is", len(train)) 29 | 30 | 31 | 32 | 33 | # # initialise HyperGCN 34 | HyperGCN = model.initialise(dataset, args) 35 | 36 | 37 | 38 | # train and test HyperGCN 39 | HyperGCN = model.train(HyperGCN, dataset, train, args) 40 | acc, H, Z = model.test(HyperGCN, dataset, test, args) 41 | return float(acc), H.cpu().detach().numpy(), Z.cpu().detach().numpy() 42 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/hypergcn/model/networks.py: -------------------------------------------------------------------------------- 1 | import torch, numpy as np 2 | import torch.nn as nn, torch.nn.functional as F 3 | 4 | from torch.autograd import Variable 5 | from hypergcn.model import utils 6 | 7 | 8 | 9 | class HyperGCN(nn.Module): 10 | def __init__(self, V, E, X, args): 11 | """ 12 | d: initial node-feature dimension 13 | h: number of hidden units 14 | c: number of classes 15 | """ 16 | super(HyperGCN, self).__init__() 17 | d, l, c = args.d, args.depth, args.c 18 | cuda = args.cuda and torch.cuda.is_available() 19 | 20 | h = [d] 21 | for i in range(l-1): 22 | power = l - i + 2 23 | if args.dataset == 'citeseer': power = l - i + 4 24 | h.append(2**power) 25 | h.append(c) 26 | 27 | if args.fast: 28 | reapproximate = False 29 | structure = utils.Laplacian(V, E, X, args.mediators) 30 | else: 31 | reapproximate = True 32 | structure = E 33 | 34 | self.layers = nn.ModuleList([utils.HyperGraphConvolution(h[i], h[i+1], reapproximate, cuda) for i in range(l)]) 35 | self.do, self.l = args.dropout, args.depth 36 | self.structure, self.m = structure, args.mediators 37 | 38 | 39 | 40 | def forward(self, H): 41 | """ 42 | an l-layer GCN 43 | """ 44 | do, l, m = self.do, self.l, self.m 45 | for i, hidden in enumerate(self.layers): 46 | H = F.relu(hidden(self.structure, H, m)) 47 | # print("H: ", H.shape) 48 | if i < l - 1: 49 | V = H 50 | H = F.dropout(H, do, training=self.training) 51 | return F.log_softmax(H, dim=1), H 52 | -------------------------------------------------------------------------------- /competitors/competitors_setups/HyperGCN/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from setuptools import find_packages 3 | 4 | setup(name='hypergcn', 5 | version='0.1', 6 | url='https://github.com/malllabiisc/HyperGCN', 7 | packages=['hypergcn'], 8 | scripts=['hypergcn/hypergcn_jl.py'], 9 | license='Proprietary License', 10 | include_package_data=True, 11 | zip_safe=False) -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/build/lib/sce/__init__.py: -------------------------------------------------------------------------------- 1 | import sce.train_jl -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/build/lib/sce/classification.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import numpy as np 3 | from sklearn.metrics import accuracy_score 4 | 5 | def run_regression(train_embeds, train_labels, test_embeds, test_labels): 6 | from sklearn.linear_model import LogisticRegression 7 | log = LogisticRegression(solver='liblinear', multi_class='ovr') 8 | log.fit(train_embeds, train_labels) 9 | predict = (log.predict(test_embeds)).tolist() 10 | accuracy = accuracy_score(test_labels, predict) 11 | print("Test Accuracy:", accuracy) 12 | return accuracy, predict 13 | 14 | def classify(embeds, dataset, per_class): 15 | 16 | label_file = open("data/{}{}".format(dataset,"_labels.txt"), 'r') 17 | label_text = label_file.readlines() 18 | labels = [] 19 | for line in label_text: 20 | if line.strip('\n'): 21 | line = line.strip('\n').split(' ') 22 | labels.append(int(line[1])) 23 | label_file.close() 24 | labels = np.array(labels) 25 | train_file = open("data/{}/{}/train_text.txt".format(dataset, per_class), 'r') 26 | train_text = train_file.readlines() 27 | train_file.close() 28 | test_file = open( "data/{}/{}/test_text.txt".format(dataset, per_class), 'r') 29 | test_text = test_file.readlines() 30 | test_file.close() 31 | ave = [] 32 | for k in range(50): 33 | train_ids = eval(train_text[k]) 34 | test_ids = eval(test_text[k]) 35 | train_labels = [labels[i] for i in train_ids] 36 | test_labels = [labels[i] for i in test_ids] 37 | train_embeds = embeds[[id for id in train_ids]] 38 | test_embeds = embeds[[id for id in test_ids]] 39 | # print(test_labels) 40 | acc, _ = run_regression(train_embeds, train_labels, test_embeds, test_labels) 41 | ave.append(acc) 42 | print(np.mean(ave)*100) 43 | print(np.std(ave)*100) 44 | 45 | def classify_ours(embeds, labels, idx_train, idx_test): 46 | 47 | labels = np.array(labels) 48 | ave = [] 49 | train_labels = [labels[i] for i in idx_train] 50 | test_labels = [labels[i] for i in idx_test] 51 | train_embeds = embeds[[id for id in idx_train]] 52 | test_embeds = embeds[[id for id in idx_test]] 53 | # print(test_labels) 54 | acc, pred = run_regression(train_embeds, train_labels, test_embeds, test_labels) 55 | return acc, pred 56 | 57 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/build/lib/sce/mlp.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch import nn 3 | from torch.nn import functional as F 4 | import math 5 | 6 | 7 | def glorot(tensor): 8 | if tensor is not None: 9 | stdv = math.sqrt(6.0 / (tensor.size(-2) + tensor.size(-1))) 10 | tensor.data.uniform_(-stdv, stdv) 11 | 12 | def zeros(tensor): 13 | if tensor is not None: 14 | tensor.data.fill_(0) 15 | 16 | class mlp(nn.Module): 17 | def __init__(self, input_dim, output_dim, 18 | dropout=0., 19 | is_sparse_inputs=False, 20 | bias=False, 21 | activation=F.relu, 22 | featureless=False): 23 | super(mlp, self).__init__() 24 | 25 | self.dropout = dropout 26 | self.bias = bias 27 | self.activation = activation 28 | self.is_sparse_inputs = is_sparse_inputs 29 | self.featureless = featureless 30 | 31 | self.weight = nn.Parameter(torch.Tensor(input_dim, output_dim)) 32 | self.bias = None 33 | if bias: 34 | self.bias = nn.Parameter(torch.Tensor(output_dim)) 35 | 36 | self.reset_parameters() 37 | 38 | def reset_parameters(self): 39 | glorot(self.weight) 40 | zeros(self.bias) 41 | 42 | def forward(self, inputs): 43 | x = inputs 44 | xw = torch.matmul(x, self.weight) 45 | 46 | return xw 47 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/build/lib/sce/networks.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn.functional as F 3 | from sce.mlp import mlp 4 | 5 | class Net(torch.nn.Module): 6 | def __init__(self, args): 7 | super(Net, self).__init__() 8 | 9 | #self.conv0 = mlp(input_dim=args.num_features, output_dim=args.output) 10 | self.conv1 = mlp(input_dim=args.num_features, output_dim=args.output) 11 | self.conv2 = mlp(input_dim=args.num_features, output_dim=args.nhid) 12 | self.conv3 = mlp(input_dim=args.nhid, output_dim=args.output) 13 | 14 | 15 | def forward(self, F_1, F_2): 16 | 17 | z_1 = self.conv1(F_1) 18 | z_2 = self.conv3(self.conv2(F_2)) 19 | z = (z_1+z_2)/2 20 | 21 | return z -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/build/lib/sce/splits.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | fout = open('data/citeseer_labels.txt', 'r') 4 | label_file = fout.readlines() 5 | 6 | #np.random.seed(123) 7 | label_dict = {} 8 | for line in label_file: 9 | if line.strip('\n'): 10 | line = line.strip('\n').split(' ') 11 | if line[1] not in label_dict: 12 | label_dict[line[1]] = [] 13 | label_dict[line[1]].append(line[0]) 14 | else: 15 | label_dict[line[1]].append(line[0]) 16 | fout.close() 17 | 18 | train_file = open('train_text.txt', 'w') 19 | val_file = open('val_text.txt', 'w') 20 | test_file = open('test_text.txt', 'w') 21 | 22 | #The size of training set are [5, 20] per class for each dataset respectively. 23 | for i in range(50): 24 | idx_train = [] 25 | idx_val = [] 26 | idx_test = [] 27 | for j in label_dict: 28 | if len(label_dict[j]) > 20: 29 | train = list(np.random.choice(label_dict[j], size=5, replace=False)) 30 | val = list(np.random.choice(list(set(label_dict[j]) - set(train)), size=5, replace=False)) 31 | test = list(set(label_dict[j]) - set(train) - set(val)) 32 | else: 33 | train = list(np.random.choice(label_dict[j], size=int(len(label_dict[j]) * 0.5), replace=False)) 34 | test = list(set(label_dict[j]) - set(train)) 35 | idx_train.extend([int(x) for x in train]) 36 | idx_val.extend([int(x) for x in val]) 37 | idx_test.extend([int(x) for x in test]) 38 | # val = list(np.random.choice(list(set(label_dict[j]) - set(train)), size=num, replace=False)) 39 | train_file.write(str(idx_train) + '\n') 40 | val_file.write(str(idx_val) + '\n') 41 | test_file.write(str(idx_test) + '\n') 42 | 43 | train_file.close() 44 | val_file.close() 45 | test_file.close() 46 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/build/lib/sce/test.py: -------------------------------------------------------------------------------- 1 | from sce import train_jl 2 | 3 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/build/lib/sce/train.py: -------------------------------------------------------------------------------- 1 | # NOTE: Splits are randomized and results might slightly deviate from reported numbers in the paper. 2 | import torch 3 | from sce.utils import load_adj_neg, load_dataset 4 | from sce.networks import Net 5 | import argparse 6 | import numpy as np 7 | from sce.classification import classify 8 | 9 | import os 10 | os.chdir((os.path.dirname(os.path.realpath(__file__)))) 11 | 12 | parser = argparse.ArgumentParser() 13 | 14 | parser.add_argument('--dataset', type=str, default='cora_full', 15 | help='dataset') 16 | parser.add_argument('--seed', type=int, default=123, 17 | help='seed') 18 | parser.add_argument('--nhid', type=int, default=512, 19 | help='hidden size') 20 | parser.add_argument('--output', type=int, default=512, 21 | help='output size') 22 | parser.add_argument('--lr', type=float, default=0.01, 23 | help='learning rate') 24 | parser.add_argument('--weight_decay', type=float, default=0, 25 | help='weight decay') 26 | parser.add_argument('--epochs', type=int, default=30, 27 | help='maximum number of epochs') 28 | parser.add_argument('--sample', type=int, default=5, 29 | help=' ') 30 | parser.add_argument('--alpha', type=int, default=100000, 31 | help=' ') 32 | parser.add_argument('--num_nodes', type=int, default=19793, 33 | help=' ') 34 | parser.add_argument('--num_features', type=int, default=8710, 35 | help=' ') 36 | 37 | args = parser.parse_args() 38 | args.device = 'cpu' 39 | torch.manual_seed(args.seed) 40 | device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 41 | feature, adj_normalized = load_dataset(args.dataset) 42 | feature = feature.to(device) 43 | adj_normalized = adj_normalized.to(device) 44 | #feature=F.normalize(feature, p=1) 45 | F_1 = torch.mm(adj_normalized, feature) 46 | F_2 = torch.mm(adj_normalized, F_1) 47 | neg_sample = torch.from_numpy(load_adj_neg(args.num_nodes, args.sample)).float().to(device) 48 | 49 | model = Net(args).to(device) 50 | optimizer = torch.optim.Adam(model.parameters(), lr=args.lr, weight_decay=args.weight_decay) 51 | model.train() 52 | 53 | for epoch in range(args.epochs): 54 | 55 | optimizer.zero_grad() 56 | out = model(F_1, F_2) 57 | loss = args.alpha / torch.trace(torch.mm(torch.mm(torch.transpose(out, 0, 1), neg_sample), out)) 58 | print(loss) 59 | loss.backward() 60 | optimizer.step() 61 | 62 | model.eval() 63 | emb = model(F_1, F_2).cpu().detach().numpy() 64 | np.save('embedding.npy', emb) 65 | classify(emb, args.dataset, per_class='20') 66 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/build/lib/sce/train_jl.py: -------------------------------------------------------------------------------- 1 | # NOTE: Splits are randomized and results might slightly deviate from reported numbers in the paper. 2 | import torch 3 | from sce.utils import load_adj_neg, load_dataset, prepare_dataset 4 | from sce.networks import Net 5 | import argparse 6 | import numpy as np 7 | from sce.classification import classify, classify_ours 8 | from argparse import Namespace 9 | 10 | def train(args, adj, features, labels, idx_train, idx_val, idx_test): 11 | 12 | parser = argparse.ArgumentParser() 13 | 14 | parser.add_argument('--dataset', type=str, default='cora', 15 | help='dataset') 16 | parser.add_argument('--seed', type=int, default=123, 17 | help='seed') 18 | parser.add_argument('--nhid', type=int, default=512, 19 | help='hidden size') 20 | parser.add_argument('--output', type=int, default=512, 21 | help='output size') 22 | parser.add_argument('--lr', type=float, default=0.01, 23 | help='learning rate') 24 | parser.add_argument('--weight_decay', type=float, default=0, 25 | help='weight decay') 26 | parser.add_argument('--epochs', type=int, default=30, 27 | help='maximum number of epochs') 28 | parser.add_argument('--sample', type=int, default=5, 29 | help=' ') 30 | parser.add_argument('--alpha', type=int, default=100000, 31 | help=' ') 32 | parser.add_argument('--num_nodes', type=int, default=19793, 33 | help=' ') 34 | parser.add_argument('--num_features', type=int, default=8710, 35 | help=' ') 36 | 37 | #args = parser.parse_args() 38 | args = Namespace(**args) 39 | args.device = 'cpu' 40 | torch.manual_seed(args.seed) 41 | device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 42 | feature, adj_normalized= prepare_dataset(adj, features) 43 | feature = feature.to(device) 44 | adj_normalized = adj_normalized.to(device) 45 | #feature=F.normalize(feature, p=1) 46 | F_1 = torch.mm(adj_normalized, feature) 47 | F_2 = torch.mm(adj_normalized, F_1) 48 | args.num_nodes = adj_normalized.shape[0] 49 | args.num_features = feature.shape[1] 50 | neg_sample = torch.from_numpy(load_adj_neg(args.num_nodes, args.sample)).float().to(device) 51 | 52 | model = Net(args).to(device) 53 | optimizer = torch.optim.Adam(model.parameters(), lr=args.lr, weight_decay=args.weight_decay) 54 | model.train() 55 | 56 | for epoch in range(args.epochs): 57 | 58 | optimizer.zero_grad() 59 | out = model(F_1, F_2) 60 | loss = args.alpha / torch.trace(torch.mm(torch.mm(torch.transpose(out, 0, 1), neg_sample), out)) 61 | print(loss) 62 | loss.backward() 63 | optimizer.step() 64 | 65 | model.eval() 66 | emb = model(F_1, F_2).cpu().detach().numpy() 67 | np.save('embedding.npy', emb) 68 | acc, pred = classify_ours(emb, labels, idx_train, idx_test) 69 | return pred 70 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/build/scripts-3.6/train_jl.py: -------------------------------------------------------------------------------- 1 | # NOTE: Splits are randomized and results might slightly deviate from reported numbers in the paper. 2 | import torch 3 | from sce.utils import load_adj_neg, load_dataset, prepare_dataset 4 | from sce.networks import Net 5 | import argparse 6 | import numpy as np 7 | from sce.classification import classify, classify_ours 8 | from argparse import Namespace 9 | 10 | def train(args, adj, features, labels, idx_train, idx_val, idx_test): 11 | 12 | parser = argparse.ArgumentParser() 13 | 14 | parser.add_argument('--dataset', type=str, default='cora', 15 | help='dataset') 16 | parser.add_argument('--seed', type=int, default=123, 17 | help='seed') 18 | parser.add_argument('--nhid', type=int, default=512, 19 | help='hidden size') 20 | parser.add_argument('--output', type=int, default=512, 21 | help='output size') 22 | parser.add_argument('--lr', type=float, default=0.01, 23 | help='learning rate') 24 | parser.add_argument('--weight_decay', type=float, default=0, 25 | help='weight decay') 26 | parser.add_argument('--epochs', type=int, default=30, 27 | help='maximum number of epochs') 28 | parser.add_argument('--sample', type=int, default=5, 29 | help=' ') 30 | parser.add_argument('--alpha', type=int, default=100000, 31 | help=' ') 32 | parser.add_argument('--num_nodes', type=int, default=19793, 33 | help=' ') 34 | parser.add_argument('--num_features', type=int, default=8710, 35 | help=' ') 36 | 37 | #args = parser.parse_args() 38 | args = Namespace(**args) 39 | args.device = 'cpu' 40 | torch.manual_seed(args.seed) 41 | device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 42 | feature, adj_normalized= prepare_dataset(adj, features) 43 | feature = feature.to(device) 44 | adj_normalized = adj_normalized.to(device) 45 | #feature=F.normalize(feature, p=1) 46 | F_1 = torch.mm(adj_normalized, feature) 47 | F_2 = torch.mm(adj_normalized, F_1) 48 | args.num_nodes = adj_normalized.shape[0] 49 | args.num_features = feature.shape[1] 50 | neg_sample = torch.from_numpy(load_adj_neg(args.num_nodes, args.sample)).float().to(device) 51 | 52 | model = Net(args).to(device) 53 | optimizer = torch.optim.Adam(model.parameters(), lr=args.lr, weight_decay=args.weight_decay) 54 | model.train() 55 | 56 | for epoch in range(args.epochs): 57 | 58 | optimizer.zero_grad() 59 | out = model(F_1, F_2) 60 | loss = args.alpha / torch.trace(torch.mm(torch.mm(torch.transpose(out, 0, 1), neg_sample), out)) 61 | print(loss) 62 | loss.backward() 63 | optimizer.step() 64 | 65 | model.eval() 66 | emb = model(F_1, F_2).cpu().detach().numpy() 67 | np.save('embedding.npy', emb) 68 | acc, pred = classify_ours(emb, labels, idx_train, idx_test) 69 | return pred 70 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/dist/sce-0.1-py3.6.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/dist/sce-0.1-py3.6.egg -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: sce 3 | Version: 0.1 4 | Summary: UNKNOWN 5 | Home-page: https://github.com/szzhang17/Sparsest-Cut-Network-Embedding 6 | License: Proprietary License 7 | Platform: UNKNOWN 8 | 9 | UNKNOWN 10 | 11 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | setup.py 2 | sce/__init__.py 3 | sce/classification.py 4 | sce/load_process.py 5 | sce/mlp.py 6 | sce/networks.py 7 | sce/preprocess.py 8 | sce/splits.py 9 | sce/test.py 10 | sce/train.py 11 | sce/train_jl.py 12 | sce/utils.py 13 | sce.egg-info/PKG-INFO 14 | sce.egg-info/SOURCES.txt 15 | sce.egg-info/dependency_links.txt 16 | sce.egg-info/not-zip-safe 17 | sce.egg-info/top_level.txt -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | sce 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/README.md: -------------------------------------------------------------------------------- 1 | # Sparsest-Cut-Network-Embedding 2 | Code for the KDD 2020 paper "[SCE: Scalable Network Embedding from Sparsest Cut](https://arxiv.org/abs/2006.16499)". 3 | 4 | 5 | ## Requirements 6 | * python == 3.7 7 | * pytorch == 1.1.0 8 | * numpy == 1.17.2 9 | * scikit-learn== 0.19.1 10 | 11 | ## Cite 12 | 13 | Please cite our paper if you use this code in your own work: 14 | 15 | 16 | ``` 17 | @inproceedings{zhang2020sce, 18 | title={SCE: Scalable Network Embedding from Sparsest Cut}, 19 | author={Shengzhong Zhang, Zengfeng Huang, Haicang Zhou and Ziang Zhou}, 20 | booktitle={In Proceedings of the 26th ACM SIGKDD Conference on Knowledge Discovery and Data Mining (KDD '20)}, 21 | year={2020} 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__init__.py: -------------------------------------------------------------------------------- 1 | import sce.train_jl -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/classification.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/classification.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/classification.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/classification.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/load_process.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/load_process.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/load_process.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/load_process.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/mlp.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/mlp.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/mlp.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/mlp.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/networks.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/networks.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/networks.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/networks.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/preprocess.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/preprocess.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/preprocess.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/preprocess.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/train.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/train.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/train_jl.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/train_jl.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/train_jl.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/train_jl.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/utils.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/__pycache__/utils.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SCE/sce/__pycache__/utils.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/classification.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import numpy as np 3 | from sklearn.metrics import accuracy_score 4 | 5 | def run_regression(train_embeds, train_labels, test_embeds, test_labels): 6 | from sklearn.linear_model import LogisticRegression 7 | log = LogisticRegression(solver='liblinear', multi_class='ovr') 8 | log.fit(train_embeds, train_labels) 9 | predict = (log.predict(test_embeds)).tolist() 10 | accuracy = accuracy_score(test_labels, predict) 11 | print("Test Accuracy:", accuracy) 12 | return accuracy, predict 13 | 14 | def classify(embeds, dataset, per_class): 15 | 16 | label_file = open("data/{}{}".format(dataset,"_labels.txt"), 'r') 17 | label_text = label_file.readlines() 18 | labels = [] 19 | for line in label_text: 20 | if line.strip('\n'): 21 | line = line.strip('\n').split(' ') 22 | labels.append(int(line[1])) 23 | label_file.close() 24 | labels = np.array(labels) 25 | train_file = open("data/{}/{}/train_text.txt".format(dataset, per_class), 'r') 26 | train_text = train_file.readlines() 27 | train_file.close() 28 | test_file = open( "data/{}/{}/test_text.txt".format(dataset, per_class), 'r') 29 | test_text = test_file.readlines() 30 | test_file.close() 31 | ave = [] 32 | for k in range(50): 33 | train_ids = eval(train_text[k]) 34 | test_ids = eval(test_text[k]) 35 | train_labels = [labels[i] for i in train_ids] 36 | test_labels = [labels[i] for i in test_ids] 37 | train_embeds = embeds[[id for id in train_ids]] 38 | test_embeds = embeds[[id for id in test_ids]] 39 | # print(test_labels) 40 | acc, _ = run_regression(train_embeds, train_labels, test_embeds, test_labels) 41 | ave.append(acc) 42 | print(np.mean(ave)*100) 43 | print(np.std(ave)*100) 44 | 45 | def classify_ours(embeds, labels, idx_train, idx_test): 46 | 47 | labels = np.array(labels) 48 | ave = [] 49 | train_labels = [labels[i] for i in idx_train] 50 | test_labels = [labels[i] for i in idx_test] 51 | train_embeds = embeds[[id for id in idx_train]] 52 | test_embeds = embeds[[id for id in idx_test]] 53 | # print(test_labels) 54 | acc, pred = run_regression(train_embeds, train_labels, test_embeds, test_labels) 55 | return acc, pred 56 | 57 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/mlp.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch import nn 3 | from torch.nn import functional as F 4 | import math 5 | 6 | 7 | def glorot(tensor): 8 | if tensor is not None: 9 | stdv = math.sqrt(6.0 / (tensor.size(-2) + tensor.size(-1))) 10 | tensor.data.uniform_(-stdv, stdv) 11 | 12 | def zeros(tensor): 13 | if tensor is not None: 14 | tensor.data.fill_(0) 15 | 16 | class mlp(nn.Module): 17 | def __init__(self, input_dim, output_dim, 18 | dropout=0., 19 | is_sparse_inputs=False, 20 | bias=False, 21 | activation=F.relu, 22 | featureless=False): 23 | super(mlp, self).__init__() 24 | 25 | self.dropout = dropout 26 | self.bias = bias 27 | self.activation = activation 28 | self.is_sparse_inputs = is_sparse_inputs 29 | self.featureless = featureless 30 | 31 | self.weight = nn.Parameter(torch.Tensor(input_dim, output_dim)) 32 | self.bias = None 33 | if bias: 34 | self.bias = nn.Parameter(torch.Tensor(output_dim)) 35 | 36 | self.reset_parameters() 37 | 38 | def reset_parameters(self): 39 | glorot(self.weight) 40 | zeros(self.bias) 41 | 42 | def forward(self, inputs): 43 | x = inputs 44 | xw = torch.matmul(x, self.weight) 45 | 46 | return xw 47 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/networks.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn.functional as F 3 | from sce.mlp import mlp 4 | 5 | class Net(torch.nn.Module): 6 | def __init__(self, args): 7 | super(Net, self).__init__() 8 | 9 | #self.conv0 = mlp(input_dim=args.num_features, output_dim=args.output) 10 | self.conv1 = mlp(input_dim=args.num_features, output_dim=args.output) 11 | self.conv2 = mlp(input_dim=args.num_features, output_dim=args.nhid) 12 | self.conv3 = mlp(input_dim=args.nhid, output_dim=args.output) 13 | 14 | 15 | def forward(self, F_1, F_2): 16 | 17 | z_1 = self.conv1(F_1) 18 | z_2 = self.conv3(self.conv2(F_2)) 19 | z = (z_1+z_2)/2 20 | 21 | return z -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/splits.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | fout = open('data/citeseer_labels.txt', 'r') 4 | label_file = fout.readlines() 5 | 6 | #np.random.seed(123) 7 | label_dict = {} 8 | for line in label_file: 9 | if line.strip('\n'): 10 | line = line.strip('\n').split(' ') 11 | if line[1] not in label_dict: 12 | label_dict[line[1]] = [] 13 | label_dict[line[1]].append(line[0]) 14 | else: 15 | label_dict[line[1]].append(line[0]) 16 | fout.close() 17 | 18 | train_file = open('train_text.txt', 'w') 19 | val_file = open('val_text.txt', 'w') 20 | test_file = open('test_text.txt', 'w') 21 | 22 | #The size of training set are [5, 20] per class for each dataset respectively. 23 | for i in range(50): 24 | idx_train = [] 25 | idx_val = [] 26 | idx_test = [] 27 | for j in label_dict: 28 | if len(label_dict[j]) > 20: 29 | train = list(np.random.choice(label_dict[j], size=5, replace=False)) 30 | val = list(np.random.choice(list(set(label_dict[j]) - set(train)), size=5, replace=False)) 31 | test = list(set(label_dict[j]) - set(train) - set(val)) 32 | else: 33 | train = list(np.random.choice(label_dict[j], size=int(len(label_dict[j]) * 0.5), replace=False)) 34 | test = list(set(label_dict[j]) - set(train)) 35 | idx_train.extend([int(x) for x in train]) 36 | idx_val.extend([int(x) for x in val]) 37 | idx_test.extend([int(x) for x in test]) 38 | # val = list(np.random.choice(list(set(label_dict[j]) - set(train)), size=num, replace=False)) 39 | train_file.write(str(idx_train) + '\n') 40 | val_file.write(str(idx_val) + '\n') 41 | test_file.write(str(idx_test) + '\n') 42 | 43 | train_file.close() 44 | val_file.close() 45 | test_file.close() 46 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/test.py: -------------------------------------------------------------------------------- 1 | from sce import train_jl 2 | 3 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/train.py: -------------------------------------------------------------------------------- 1 | # NOTE: Splits are randomized and results might slightly deviate from reported numbers in the paper. 2 | import torch 3 | from sce.utils import load_adj_neg, load_dataset 4 | from sce.networks import Net 5 | import argparse 6 | import numpy as np 7 | from sce.classification import classify 8 | 9 | import os 10 | os.chdir((os.path.dirname(os.path.realpath(__file__)))) 11 | 12 | parser = argparse.ArgumentParser() 13 | 14 | parser.add_argument('--dataset', type=str, default='cora_full', 15 | help='dataset') 16 | parser.add_argument('--seed', type=int, default=123, 17 | help='seed') 18 | parser.add_argument('--nhid', type=int, default=512, 19 | help='hidden size') 20 | parser.add_argument('--output', type=int, default=512, 21 | help='output size') 22 | parser.add_argument('--lr', type=float, default=0.01, 23 | help='learning rate') 24 | parser.add_argument('--weight_decay', type=float, default=0, 25 | help='weight decay') 26 | parser.add_argument('--epochs', type=int, default=30, 27 | help='maximum number of epochs') 28 | parser.add_argument('--sample', type=int, default=5, 29 | help=' ') 30 | parser.add_argument('--alpha', type=int, default=100000, 31 | help=' ') 32 | parser.add_argument('--num_nodes', type=int, default=19793, 33 | help=' ') 34 | parser.add_argument('--num_features', type=int, default=8710, 35 | help=' ') 36 | 37 | args = parser.parse_args() 38 | args.device = 'cpu' 39 | torch.manual_seed(args.seed) 40 | device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 41 | feature, adj_normalized = load_dataset(args.dataset) 42 | feature = feature.to(device) 43 | adj_normalized = adj_normalized.to(device) 44 | #feature=F.normalize(feature, p=1) 45 | F_1 = torch.mm(adj_normalized, feature) 46 | F_2 = torch.mm(adj_normalized, F_1) 47 | neg_sample = torch.from_numpy(load_adj_neg(args.num_nodes, args.sample)).float().to(device) 48 | 49 | model = Net(args).to(device) 50 | optimizer = torch.optim.Adam(model.parameters(), lr=args.lr, weight_decay=args.weight_decay) 51 | model.train() 52 | 53 | for epoch in range(args.epochs): 54 | 55 | optimizer.zero_grad() 56 | out = model(F_1, F_2) 57 | loss = args.alpha / torch.trace(torch.mm(torch.mm(torch.transpose(out, 0, 1), neg_sample), out)) 58 | print(loss) 59 | loss.backward() 60 | optimizer.step() 61 | 62 | model.eval() 63 | emb = model(F_1, F_2).cpu().detach().numpy() 64 | np.save('embedding.npy', emb) 65 | classify(emb, args.dataset, per_class='20') 66 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/sce/train_jl.py: -------------------------------------------------------------------------------- 1 | # NOTE: Splits are randomized and results might slightly deviate from reported numbers in the paper. 2 | import torch 3 | from sce.utils import load_adj_neg, load_dataset, prepare_dataset 4 | from sce.networks import Net 5 | import argparse 6 | import numpy as np 7 | from sce.classification import classify, classify_ours 8 | from argparse import Namespace 9 | 10 | def train(args, adj, features, labels, idx_train, idx_val, idx_test): 11 | 12 | parser = argparse.ArgumentParser() 13 | 14 | parser.add_argument('--dataset', type=str, default='cora', 15 | help='dataset') 16 | parser.add_argument('--seed', type=int, default=123, 17 | help='seed') 18 | parser.add_argument('--nhid', type=int, default=512, 19 | help='hidden size') 20 | parser.add_argument('--output', type=int, default=512, 21 | help='output size') 22 | parser.add_argument('--lr', type=float, default=0.01, 23 | help='learning rate') 24 | parser.add_argument('--weight_decay', type=float, default=0, 25 | help='weight decay') 26 | parser.add_argument('--epochs', type=int, default=30, 27 | help='maximum number of epochs') 28 | parser.add_argument('--sample', type=int, default=5, 29 | help=' ') 30 | parser.add_argument('--alpha', type=int, default=100000, 31 | help=' ') 32 | parser.add_argument('--num_nodes', type=int, default=19793, 33 | help=' ') 34 | parser.add_argument('--num_features', type=int, default=8710, 35 | help=' ') 36 | 37 | #args = parser.parse_args() 38 | args = Namespace(**args) 39 | args.device = 'cpu' 40 | torch.manual_seed(args.seed) 41 | device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 42 | feature, adj_normalized= prepare_dataset(adj, features) 43 | feature = feature.to(device) 44 | adj_normalized = adj_normalized.to(device) 45 | #feature=F.normalize(feature, p=1) 46 | F_1 = torch.mm(adj_normalized, feature) 47 | F_2 = torch.mm(adj_normalized, F_1) 48 | args.num_nodes = adj_normalized.shape[0] 49 | args.num_features = feature.shape[1] 50 | neg_sample = torch.from_numpy(load_adj_neg(args.num_nodes, args.sample)).float().to(device) 51 | 52 | model = Net(args).to(device) 53 | optimizer = torch.optim.Adam(model.parameters(), lr=args.lr, weight_decay=args.weight_decay) 54 | model.train() 55 | 56 | for epoch in range(args.epochs): 57 | 58 | optimizer.zero_grad() 59 | out = model(F_1, F_2) 60 | loss = args.alpha / torch.trace(torch.mm(torch.mm(torch.transpose(out, 0, 1), neg_sample), out)) 61 | print(loss) 62 | loss.backward() 63 | optimizer.step() 64 | 65 | model.eval() 66 | emb = model(F_1, F_2).cpu().detach().numpy() 67 | np.save('embedding.npy', emb) 68 | print(len(idx_train), len(idx_test)) 69 | acc, pred = classify_ours(emb, labels, idx_train, idx_test) 70 | return pred 71 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SCE/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from setuptools import find_packages 3 | 4 | setup(name='sce', 5 | version='0.1', 6 | url='https://github.com/szzhang17/Sparsest-Cut-Network-Embedding', 7 | packages=['sce'], 8 | scripts=['sce/train_jl.py'], 9 | license='Proprietary License', 10 | include_package_data=True, 11 | zip_safe=False) -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/__pycache__/args.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/__pycache__/args.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/__pycache__/citation_jl.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/__pycache__/citation_jl.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/__pycache__/citation_jl.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/__pycache__/citation_jl.cpython-38.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/__pycache__/metrics.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/__pycache__/metrics.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/__pycache__/models.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/__pycache__/models.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/__pycache__/normalization.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/__pycache__/normalization.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/__pycache__/utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/__pycache__/utils.cpython-36.pyc -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/build/lib/sgc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/build/lib/sgc/__init__.py -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/build/lib/sgc/args.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import torch 3 | 4 | def get_citation_args(): 5 | parser = argparse.ArgumentParser() 6 | parser.add_argument('--no-cuda', action='store_true', default=False, 7 | help='Disables CUDA training.') 8 | parser.add_argument('--seed', type=int, default=42, help='Random seed.') 9 | parser.add_argument('--epochs', type=int, default=100, 10 | help='Number of epochs to train.') 11 | parser.add_argument('--lr', type=float, default=0.2, 12 | help='Initial learning rate.') 13 | parser.add_argument('--weight_decay', type=float, default=5e-6, 14 | help='Weight decay (L2 loss on parameters).') 15 | parser.add_argument('--hidden', type=int, default=0, 16 | help='Number of hidden units.') 17 | parser.add_argument('--dropout', type=float, default=0, 18 | help='Dropout rate (1 - keep probability).') 19 | parser.add_argument('--dataset', type=str, default="cora", 20 | help='Dataset to use.') 21 | parser.add_argument('--model', type=str, default="SGC", 22 | choices=["SGC", "GCN"], 23 | help='model to use.') 24 | parser.add_argument('--feature', type=str, default="mul", 25 | choices=['mul', 'cat', 'adj'], 26 | help='feature-type') 27 | parser.add_argument('--normalization', type=str, default='AugNormAdj', 28 | choices=['AugNormAdj'], 29 | help='Normalization method for the adjacency matrix.') 30 | parser.add_argument('--degree', type=int, default=2, 31 | help='degree of the approximation.') 32 | parser.add_argument('--per', type=int, default=-1, 33 | help='Number of each nodes so as to balance.') 34 | parser.add_argument('--experiment', type=str, default="base-experiment", 35 | help='feature-type') 36 | parser.add_argument('--tuned', action='store_true', help='use tuned hyperparams') 37 | 38 | args, _ = parser.parse_known_args() 39 | args.cuda = not args.no_cuda and torch.cuda.is_available() 40 | return args 41 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/build/lib/sgc/citation.py: -------------------------------------------------------------------------------- 1 | import time 2 | import argparse 3 | import numpy as np 4 | import torch 5 | import torch.nn.functional as F 6 | import torch.optim as optim 7 | from sgc.utils import load_citation, sgc_precompute, set_seed 8 | from sgc.models import get_model 9 | from sgc.metrics import accuracy 10 | import pickle as pkl 11 | from sgc.args import get_citation_args 12 | from time import perf_counter 13 | 14 | 15 | import os 16 | os.chdir((os.path.dirname(os.path.realpath(__file__)))) 17 | 18 | 19 | # Arguments 20 | args = get_citation_args() 21 | 22 | if args.tuned: 23 | if args.model == "SGC": 24 | with open("{}-tuning/{}.txt".format(args.model, args.dataset), 'rb') as f: 25 | args.weight_decay = pkl.load(f)['weight_decay'] 26 | print("using tuned weight decay: {}".format(args.weight_decay)) 27 | else: 28 | raise NotImplemented 29 | 30 | # setting random seeds 31 | set_seed(args.seed, args.cuda) 32 | 33 | adj, features, labels, idx_train, idx_val, idx_test = load_citation(args.dataset, args.normalization, args.cuda) 34 | 35 | 36 | model = get_model(args.model, features.size(1), labels.max().item()+1, args.hidden, args.dropout, args.cuda) 37 | 38 | if args.model == "SGC": features, precompute_time = sgc_precompute(features, adj, args.degree) 39 | print("{:.4f}s".format(precompute_time)) 40 | 41 | def train_regression(model, 42 | train_features, train_labels, 43 | val_features, val_labels, 44 | epochs=args.epochs, weight_decay=args.weight_decay, 45 | lr=args.lr, dropout=args.dropout): 46 | 47 | optimizer = optim.Adam(model.parameters(), lr=lr, 48 | weight_decay=weight_decay) 49 | t = perf_counter() 50 | for epoch in range(epochs): 51 | model.train() 52 | optimizer.zero_grad() 53 | output = model(train_features) 54 | loss_train = F.cross_entropy(output, train_labels) 55 | loss_train.backward() 56 | optimizer.step() 57 | train_time = perf_counter()-t 58 | 59 | with torch.no_grad(): 60 | model.eval() 61 | output = model(val_features) 62 | acc_val = accuracy(output, val_labels) 63 | 64 | return model, acc_val, train_time 65 | 66 | def test_regression(model, test_features, test_labels): 67 | model.eval() 68 | return accuracy(model(test_features), test_labels) 69 | 70 | if args.model == "SGC": 71 | model, acc_val, train_time = train_regression(model, features[idx_train], labels[idx_train], features[idx_val], labels[idx_val], 72 | args.epochs, args.weight_decay, args.lr, args.dropout) 73 | acc_test = test_regression(model, features[idx_test], labels[idx_test]) 74 | 75 | print("Validation Accuracy: {:.4f} Test Accuracy: {:.4f}".format(acc_val, acc_test)) 76 | print("Pre-compute time: {:.4f}s, train time: {:.4f}s, total: {:.4f}s".format(precompute_time, train_time, precompute_time+train_time)) 77 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/build/lib/sgc/citation_jl.py: -------------------------------------------------------------------------------- 1 | import time 2 | import argparse 3 | import numpy as np 4 | import torch 5 | import torch.nn.functional as F 6 | import torch.optim as optim 7 | import os 8 | import pickle as pkl 9 | from time import perf_counter 10 | from argparse import Namespace 11 | 12 | from sgc.utils import load_citation, sgc_precompute, set_seed, prepare_data 13 | from sgc.models import get_model 14 | from sgc.metrics import accuracy 15 | from sgc.args import get_citation_args 16 | 17 | 18 | # Arguments 19 | def main(args, adj, features, labels, idx_train, idx_val, idx_test): 20 | #args = get_citation_args() 21 | args = Namespace(**args) 22 | args.cuda = not args.no_cuda and torch.cuda.is_available() 23 | 24 | if args.tuned: 25 | if args.model == "SGC": 26 | with open("{}-tuning/{}.txt".format(args.model, args.dataset), 'rb') as f: 27 | args.weight_decay = pkl.load(f)['weight_decay'] 28 | print("using tuned weight decay: {}".format(args.weight_decay)) 29 | else: 30 | raise NotImplemented 31 | 32 | # setting random seeds 33 | set_seed(args.seed, args.cuda) 34 | data = [adj, features, labels, idx_train, idx_val, idx_test] 35 | adj, features, labels, idx_train, idx_val, idx_test = prepare_data(data, args.normalization, args.cuda) 36 | model = get_model(args.model, features.size(1), labels.max().item()+1, args.hidden, args.dropout, args.cuda) 37 | 38 | if args.model == "SGC": features, precompute_time = sgc_precompute(features, adj, args.degree) 39 | print("{:.4f}s".format(precompute_time)) 40 | 41 | def train_regression(model, 42 | train_features, train_labels, 43 | val_features, val_labels, 44 | epochs=args.epochs, weight_decay=args.weight_decay, 45 | lr=args.lr, dropout=args.dropout): 46 | 47 | optimizer = optim.Adam(model.parameters(), lr=lr, 48 | weight_decay=weight_decay) 49 | t = perf_counter() 50 | for epoch in range(epochs): 51 | model.train() 52 | optimizer.zero_grad() 53 | output = model(train_features) 54 | loss_train = F.cross_entropy(output, train_labels) 55 | loss_train.backward() 56 | optimizer.step() 57 | train_time = perf_counter()-t 58 | 59 | with torch.no_grad(): 60 | model.eval() 61 | output = model(val_features) 62 | acc_val = accuracy(output, val_labels) 63 | 64 | return model, acc_val, train_time 65 | 66 | def test_regression(model, test_features, test_labels): 67 | model.eval() 68 | return accuracy(model(test_features), test_labels), model(test_features).detach().numpy() 69 | 70 | if args.model == "SGC": 71 | model, acc_val, train_time = train_regression(model, features[idx_train], labels[idx_train], features[idx_val], labels[idx_val], 72 | args.epochs, args.weight_decay, args.lr, args.dropout) 73 | acc_test, pred = test_regression(model, features[idx_test], labels[idx_test]) 74 | 75 | 76 | print("Validation Accuracy: {:.4f} Test Accuracy: {:.4f}".format(acc_val, acc_test)) 77 | print("Pre-compute time: {:.4f}s, train time: {:.4f}s, total: {:.4f}s".format(precompute_time, train_time, precompute_time+train_time)) 78 | return pred 79 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/build/lib/sgc/metrics.py: -------------------------------------------------------------------------------- 1 | from sklearn.metrics import f1_score 2 | 3 | def accuracy(output, labels): 4 | preds = output.max(1)[1].type_as(labels) 5 | correct = preds.eq(labels).double() 6 | correct = correct.sum() 7 | return correct / len(labels) 8 | 9 | def f1(output, labels): 10 | preds = output.max(1)[1] 11 | preds = preds.cpu().detach().numpy() 12 | labels = labels.cpu().detach().numpy() 13 | micro = f1_score(labels, preds, average='micro') 14 | macro = f1_score(labels, preds, average='macro') 15 | return micro, macro 16 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/build/lib/sgc/models.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | from torch.nn import Module 4 | import torch.nn.functional as F 5 | import math 6 | 7 | class SGC(nn.Module): 8 | """ 9 | A Simple PyTorch Implementation of Logistic Regression. 10 | Assuming the features have been preprocessed with k-step graph propagation. 11 | """ 12 | def __init__(self, nfeat, nclass): 13 | super(SGC, self).__init__() 14 | 15 | self.W = nn.Linear(nfeat, nclass) 16 | 17 | def forward(self, x): 18 | return self.W(x) 19 | 20 | class GraphConvolution(Module): 21 | """ 22 | A Graph Convolution Layer (GCN) 23 | """ 24 | 25 | def __init__(self, in_features, out_features, bias=True): 26 | super(GraphConvolution, self).__init__() 27 | self.in_features = in_features 28 | self.out_features = out_features 29 | self.W = nn.Linear(in_features, out_features, bias=bias) 30 | self.init() 31 | 32 | def init(self): 33 | stdv = 1. / math.sqrt(self.W.weight.size(1)) 34 | self.W.weight.data.uniform_(-stdv, stdv) 35 | 36 | def forward(self, input, adj): 37 | support = self.W(input) 38 | output = torch.spmm(adj, support) 39 | 40 | class GCN(nn.Module): 41 | """ 42 | A Two-layer GCN. 43 | """ 44 | def __init__(self, nfeat, nhid, nclass, dropout): 45 | super(GCN, self).__init__() 46 | 47 | self.gc1 = GraphConvolution(nfeat, nhid) 48 | self.gc2 = GraphConvolution(nhid, nclass) 49 | self.dropout = dropout 50 | 51 | def forward(self, x, adj, use_relu=True): 52 | x = self.gc1(x, adj) 53 | if use_relu: 54 | x = F.relu(x) 55 | x = F.dropout(x, self.dropout, training=self.training) 56 | x = self.gc2(x, adj) 57 | return x 58 | 59 | def get_model(model_opt, nfeat, nclass, nhid=0, dropout=0, cuda=True): 60 | if model_opt == "GCN": 61 | model = GCN(nfeat=nfeat, 62 | nhid=nhid, 63 | nclass=nclass, 64 | dropout=dropout) 65 | elif model_opt == "SGC": 66 | model = SGC(nfeat=nfeat, 67 | nclass=nclass) 68 | else: 69 | raise NotImplementedError('model:{} is not implemented!'.format(model_opt)) 70 | 71 | if cuda: model.cuda() 72 | return model 73 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/build/lib/sgc/normalization.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.sparse as sp 3 | import torch 4 | 5 | def aug_normalized_adjacency(adj): 6 | adj = adj + sp.eye(adj.shape[0]) 7 | adj = sp.coo_matrix(adj) 8 | row_sum = np.array(adj.sum(1)) 9 | d_inv_sqrt = np.power(row_sum, -0.5).flatten() 10 | d_inv_sqrt[np.isinf(d_inv_sqrt)] = 0. 11 | d_mat_inv_sqrt = sp.diags(d_inv_sqrt) 12 | return d_mat_inv_sqrt.dot(adj).dot(d_mat_inv_sqrt).tocoo() 13 | 14 | def fetch_normalization(type): 15 | switcher = { 16 | 'AugNormAdj': aug_normalized_adjacency, # A' = (D + I)^-1/2 * ( A + I ) * (D + I)^-1/2 17 | } 18 | func = switcher.get(type, lambda: "Invalid normalization technique.") 19 | return func 20 | 21 | def row_normalize(mx): 22 | """Row-normalize sparse matrix""" 23 | rowsum = np.array(mx.sum(1)) 24 | r_inv = np.power(rowsum, -1).flatten() 25 | r_inv[np.isinf(r_inv)] = 0. 26 | r_mat_inv = sp.diags(r_inv) 27 | mx = r_mat_inv.dot(mx) 28 | return mx 29 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/build/lib/sgc/reddit.py: -------------------------------------------------------------------------------- 1 | from time import perf_counter 2 | import argparse 3 | import numpy as np 4 | import torch 5 | import torch.nn.functional as F 6 | import torch.optim as optim 7 | from utils import load_reddit_data, sgc_precompute, set_seed 8 | from metrics import f1 9 | from models import SGC 10 | 11 | # Args 12 | parser = argparse.ArgumentParser() 13 | parser.add_argument('--no-cuda', action='store_true', default=False, 14 | help='Disables CUDA training.') 15 | parser.add_argument('--inductive', action='store_true', default=False, 16 | help='inductive training.') 17 | parser.add_argument('--test', action='store_true', default=False, 18 | help='inductive training.') 19 | parser.add_argument('--seed', type=int, default=42, help='Random seed.') 20 | parser.add_argument('--epochs', type=int, default=2, 21 | help='Number of epochs to train.') 22 | parser.add_argument('--weight_decay', type=float, default=0, 23 | help='Weight decay (L2 loss on parameters).') 24 | parser.add_argument('--normalization', type=str, default='AugNormAdj', 25 | choices=['NormLap', 'Lap', 'RWalkLap', 'FirstOrderGCN', 26 | 'AugNormAdj', 'NormAdj', 'RWalk', 'AugRWalk', 'NoNorm'], 27 | help='Normalization method for the adjacency matrix.') 28 | parser.add_argument('--model', type=str, default="SGC", 29 | help='model to use.') 30 | parser.add_argument('--degree', type=int, default=2, 31 | help='degree of the approximation.') 32 | 33 | args = parser.parse_args() 34 | args.cuda = not args.no_cuda and torch.cuda.is_available() 35 | 36 | set_seed(args.seed, args.cuda) 37 | 38 | adj, train_adj, features, labels, idx_train, idx_val, idx_test = load_reddit_data(args.normalization) 39 | print("Finished data loading.") 40 | 41 | model = SGC(features.size(1), labels.max().item()+1) 42 | if args.cuda: model.cuda() 43 | processed_features, precompute_time = sgc_precompute(features, adj, args.degree) 44 | if args.inductive: 45 | train_features, _ = sgc_precompute(features[idx_train], train_adj, args.degree) 46 | else: 47 | train_features = processed_features[idx_train] 48 | 49 | test_features = processed_features[idx_test if args.test else idx_val] 50 | 51 | def train_regression(model, train_features, train_labels, epochs): 52 | optimizer = optim.LBFGS(model.parameters(), lr=1) 53 | model.train() 54 | def closure(): 55 | optimizer.zero_grad() 56 | output = model(train_features) 57 | loss_train = F.cross_entropy(output, train_labels) 58 | loss_train.backward() 59 | return loss_train 60 | t = perf_counter() 61 | for epoch in range(epochs): 62 | loss_train = optimizer.step(closure) 63 | train_time = perf_counter()-t 64 | return model, train_time 65 | 66 | def test_regression(model, test_features, test_labels): 67 | model.eval() 68 | return f1(model(test_features), test_labels) 69 | 70 | model, train_time = train_regression(model, train_features, labels[idx_train], args.epochs) 71 | test_f1, _ = test_regression(model, test_features, labels[idx_test if args.test else idx_val]) 72 | print("Total Time: {:.4f}s, {} F1: {:.4f}".format(train_time+precompute_time, 73 | "Test" if args.test else "Val", 74 | test_f1)) 75 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/build/lib/sgc/tuning.py: -------------------------------------------------------------------------------- 1 | import time 2 | import argparse 3 | import numpy as np 4 | import pickle as pkl 5 | import os 6 | from math import log 7 | from citation import train_regression 8 | from models import get_model 9 | from utils import sgc_precompute, load_citation, set_seed 10 | from args import get_citation_args 11 | import torch 12 | from hyperopt import fmin, tpe, hp, STATUS_OK, Trials 13 | 14 | # Arguments 15 | args = get_citation_args() 16 | 17 | # setting random seeds 18 | set_seed(args.seed, args.cuda) 19 | 20 | # Hyperparameter optimization 21 | space = {'weight_decay' : hp.loguniform('weight_decay', log(1e-10), log(1e-4))} 22 | 23 | adj, features, labels, idx_train, idx_val, idx_test = load_citation(args.dataset, args.normalization, args.cuda) 24 | if args.model == "SGC": features, precompute_time = sgc_precompute(features, adj, args.degree) 25 | 26 | def sgc_objective(space): 27 | model = get_model(args.model, features.size(1), labels.max().item()+1, args.hidden, args.dropout, args.cuda) 28 | model, acc_val, _ = train_regression(model, features[idx_train], labels[idx_train], features[idx_val], labels[idx_val], 29 | args.epochs, space['weight_decay'], args.lr, args.dropout) 30 | print('weight decay: {:.2e} '.format(space['weight_decay']) + 'accuracy: {:.4f}'.format(acc_val)) 31 | return {'loss': -acc_val, 'status': STATUS_OK} 32 | 33 | best = fmin(sgc_objective, space=space, algo=tpe.suggest, max_evals=60) 34 | print("Best weight decay: {:.2e}".format(best["weight_decay"])) 35 | 36 | os.makedirs("./{}-tuning".format(args.model), exist_ok=True) 37 | path = '{}-tuning/{}.txt'.format(args.model, args.dataset) 38 | with open(path, 'wb') as f: pkl.dump(best, f) 39 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/dist/sgc-0.1-py3.6.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/dist/sgc-0.1-py3.6.egg -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from setuptools import find_packages 3 | 4 | setup(name='sgc', 5 | version='0.1', 6 | url='https://github.com/Tiiiger/SGC', 7 | packages=['sgc'], 8 | scripts=['sgc/citation_jl.py'], 9 | license='Proprietary License', 10 | include_package_data=True, 11 | zip_safe=False) -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: sgc 3 | Version: 0.1 4 | Summary: UNKNOWN 5 | Home-page: https://github.com/Tiiiger/SGC 6 | License: Proprietary License 7 | Platform: UNKNOWN 8 | 9 | UNKNOWN 10 | 11 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | setup.py 2 | sgc/__init__.py 3 | sgc/args.py 4 | sgc/citation.py 5 | sgc/citation_jl.py 6 | sgc/metrics.py 7 | sgc/models.py 8 | sgc/normalization.py 9 | sgc/reddit.py 10 | sgc/tuning.py 11 | sgc/utils.py 12 | sgc.egg-info/PKG-INFO 13 | sgc.egg-info/SOURCES.txt 14 | sgc.egg-info/dependency_links.txt 15 | sgc.egg-info/not-zip-safe 16 | sgc.egg-info/top_level.txt -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | sgc 2 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/.gitignore: -------------------------------------------------------------------------------- 1 | data/*reddit* 2 | downstream/TextSGC/data 3 | __pycache__/ 4 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2019 Tianyi Zhang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/SGC-tuning/citeseer.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/SGC-tuning/citeseer.txt -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/SGC-tuning/cora.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/SGC-tuning/cora.txt -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/SGC-tuning/pubmed.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/SGC-tuning/pubmed.txt -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/__init__.py -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/args.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import torch 3 | 4 | def get_citation_args(): 5 | parser = argparse.ArgumentParser() 6 | parser.add_argument('--no-cuda', action='store_true', default=False, 7 | help='Disables CUDA training.') 8 | parser.add_argument('--seed', type=int, default=42, help='Random seed.') 9 | parser.add_argument('--epochs', type=int, default=100, 10 | help='Number of epochs to train.') 11 | parser.add_argument('--lr', type=float, default=0.2, 12 | help='Initial learning rate.') 13 | parser.add_argument('--weight_decay', type=float, default=5e-6, 14 | help='Weight decay (L2 loss on parameters).') 15 | parser.add_argument('--hidden', type=int, default=0, 16 | help='Number of hidden units.') 17 | parser.add_argument('--dropout', type=float, default=0, 18 | help='Dropout rate (1 - keep probability).') 19 | parser.add_argument('--dataset', type=str, default="cora", 20 | help='Dataset to use.') 21 | parser.add_argument('--model', type=str, default="SGC", 22 | choices=["SGC", "GCN"], 23 | help='model to use.') 24 | parser.add_argument('--feature', type=str, default="mul", 25 | choices=['mul', 'cat', 'adj'], 26 | help='feature-type') 27 | parser.add_argument('--normalization', type=str, default='AugNormAdj', 28 | choices=['AugNormAdj'], 29 | help='Normalization method for the adjacency matrix.') 30 | parser.add_argument('--degree', type=int, default=2, 31 | help='degree of the approximation.') 32 | parser.add_argument('--per', type=int, default=-1, 33 | help='Number of each nodes so as to balance.') 34 | parser.add_argument('--experiment', type=str, default="base-experiment", 35 | help='feature-type') 36 | parser.add_argument('--tuned', action='store_true', help='use tuned hyperparams') 37 | 38 | args, _ = parser.parse_known_args() 39 | args.cuda = not args.no_cuda and torch.cuda.is_available() 40 | return args 41 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/citation.py: -------------------------------------------------------------------------------- 1 | import time 2 | import argparse 3 | import numpy as np 4 | import torch 5 | import torch.nn.functional as F 6 | import torch.optim as optim 7 | from sgc.utils import load_citation, sgc_precompute, set_seed 8 | from sgc.models import get_model 9 | from sgc.metrics import accuracy 10 | import pickle as pkl 11 | from sgc.args import get_citation_args 12 | from time import perf_counter 13 | 14 | 15 | import os 16 | os.chdir((os.path.dirname(os.path.realpath(__file__)))) 17 | 18 | 19 | # Arguments 20 | args = get_citation_args() 21 | 22 | if args.tuned: 23 | if args.model == "SGC": 24 | with open("{}-tuning/{}.txt".format(args.model, args.dataset), 'rb') as f: 25 | args.weight_decay = pkl.load(f)['weight_decay'] 26 | print("using tuned weight decay: {}".format(args.weight_decay)) 27 | else: 28 | raise NotImplemented 29 | 30 | # setting random seeds 31 | set_seed(args.seed, args.cuda) 32 | 33 | adj, features, labels, idx_train, idx_val, idx_test = load_citation(args.dataset, args.normalization, args.cuda) 34 | 35 | 36 | model = get_model(args.model, features.size(1), labels.max().item()+1, args.hidden, args.dropout, args.cuda) 37 | 38 | if args.model == "SGC": features, precompute_time = sgc_precompute(features, adj, args.degree) 39 | print("{:.4f}s".format(precompute_time)) 40 | 41 | def train_regression(model, 42 | train_features, train_labels, 43 | val_features, val_labels, 44 | epochs=args.epochs, weight_decay=args.weight_decay, 45 | lr=args.lr, dropout=args.dropout): 46 | 47 | optimizer = optim.Adam(model.parameters(), lr=lr, 48 | weight_decay=weight_decay) 49 | t = perf_counter() 50 | for epoch in range(epochs): 51 | model.train() 52 | optimizer.zero_grad() 53 | output = model(train_features) 54 | loss_train = F.cross_entropy(output, train_labels) 55 | loss_train.backward() 56 | optimizer.step() 57 | train_time = perf_counter()-t 58 | 59 | with torch.no_grad(): 60 | model.eval() 61 | output = model(val_features) 62 | acc_val = accuracy(output, val_labels) 63 | 64 | return model, acc_val, train_time 65 | 66 | def test_regression(model, test_features, test_labels): 67 | model.eval() 68 | return accuracy(model(test_features), test_labels) 69 | 70 | if args.model == "SGC": 71 | model, acc_val, train_time = train_regression(model, features[idx_train], labels[idx_train], features[idx_val], labels[idx_val], 72 | args.epochs, args.weight_decay, args.lr, args.dropout) 73 | acc_test = test_regression(model, features[idx_test], labels[idx_test]) 74 | 75 | print("Validation Accuracy: {:.4f} Test Accuracy: {:.4f}".format(acc_val, acc_test)) 76 | print("Pre-compute time: {:.4f}s, train time: {:.4f}s, total: {:.4f}s".format(precompute_time, train_time, precompute_time+train_time)) 77 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/citation_jl.py: -------------------------------------------------------------------------------- 1 | import time 2 | import argparse 3 | import numpy as np 4 | import torch 5 | import torch.nn.functional as F 6 | import torch.optim as optim 7 | import os 8 | import pickle as pkl 9 | from time import perf_counter 10 | from argparse import Namespace 11 | 12 | from sgc.utils import load_citation, sgc_precompute, set_seed, prepare_data 13 | from sgc.models import get_model 14 | from sgc.metrics import accuracy 15 | from sgc.args import get_citation_args 16 | 17 | 18 | # Arguments 19 | def main(args, adj, features, labels, idx_train, idx_val, idx_test): 20 | #args = get_citation_args() 21 | args = Namespace(**args) 22 | args.cuda = not args.no_cuda and torch.cuda.is_available() 23 | 24 | if args.tuned: 25 | if args.model == "SGC": 26 | with open("{}-tuning/{}.txt".format(args.model, args.dataset), 'rb') as f: 27 | args.weight_decay = pkl.load(f)['weight_decay'] 28 | print("using tuned weight decay: {}".format(args.weight_decay)) 29 | else: 30 | raise NotImplemented 31 | 32 | # setting random seeds 33 | set_seed(args.seed, args.cuda) 34 | print(adj) 35 | data = [adj, features, labels, idx_train, idx_val, idx_test] 36 | adj, features, labels, idx_train, idx_val, idx_test = prepare_data(data, args.normalization, args.cuda) 37 | print(adj.shape, features.shape, labels.shape, idx_train.shape, idx_val.shape, idx_test.shape) 38 | model = get_model(args.model, features.size(1), labels.max().item()+1, args.hidden, args.dropout, args.cuda) 39 | 40 | if args.model == "SGC": features, precompute_time = sgc_precompute(features, adj, args.degree) 41 | print("{:.4f}s".format(precompute_time)) 42 | 43 | def train_regression(model, 44 | train_features, train_labels, 45 | val_features, val_labels, 46 | epochs=args.epochs, weight_decay=args.weight_decay, 47 | lr=args.lr, dropout=args.dropout): 48 | 49 | optimizer = optim.Adam(model.parameters(), lr=lr, 50 | weight_decay=weight_decay) 51 | t = perf_counter() 52 | for epoch in range(epochs): 53 | model.train() 54 | optimizer.zero_grad() 55 | output = model(train_features) 56 | loss_train = F.cross_entropy(output, train_labels) 57 | loss_train.backward() 58 | optimizer.step() 59 | train_time = perf_counter()-t 60 | 61 | with torch.no_grad(): 62 | model.eval() 63 | output = model(val_features) 64 | acc_val = accuracy(output, val_labels) 65 | 66 | return model, acc_val, train_time 67 | 68 | def test_regression(model, test_features, test_labels): 69 | model.eval() 70 | return accuracy(model(test_features), test_labels), model(test_features).cpu().detach().numpy() 71 | 72 | if args.model == "SGC": 73 | model, acc_val, train_time = train_regression(model, features[idx_train], labels[idx_train], features[idx_val], labels[idx_val], 74 | args.epochs, args.weight_decay, args.lr, args.dropout) 75 | acc_test, pred = test_regression(model, features[idx_test], labels[idx_test]) 76 | 77 | 78 | print("Validation Accuracy: {:.4f} Test Accuracy: {:.4f}".format(acc_val, acc_test)) 79 | print("Pre-compute time: {:.4f}s, train time: {:.4f}s, total: {:.4f}s".format(precompute_time, train_time, precompute_time+train_time)) 80 | return pred 81 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.citeseer.allx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.citeseer.allx -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.citeseer.ally: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.citeseer.ally -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.citeseer.graph: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.citeseer.graph -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.citeseer.tx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.citeseer.tx -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.citeseer.ty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.citeseer.ty -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.citeseer.x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.citeseer.x -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.citeseer.y: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.citeseer.y -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.cora.allx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.cora.allx -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.cora.ally: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.cora.ally -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.cora.graph: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.cora.graph -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.cora.tx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.cora.tx -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.cora.ty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.cora.ty -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.cora.x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.cora.x -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.cora.y: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.cora.y -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.pubmed.allx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.pubmed.allx -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.pubmed.ally: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.pubmed.ally -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.pubmed.graph: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.pubmed.graph -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.pubmed.tx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.pubmed.tx -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.pubmed.ty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.pubmed.ty -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.pubmed.x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.pubmed.x -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/data/ind.pubmed.y: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/data/ind.pubmed.y -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/downstream/TextSGC/README.md: -------------------------------------------------------------------------------- 1 | # TextSGC 2 | 3 | Implementation of SGC for text classification following 4 | ([Graph Convolutional Networks for Text Classification](https://arxiv.org/abs/1809.05679)). 5 | Code modified from the original repo of 6 | Text-GCN(https://github.com/yao8839836/text_gcn) and the pytorch implementation 7 | of GCN (https://github.com/tkipf/pygcn). 8 | 9 | For reference, 10 | 11 | Dataset | Accuracy | Training Time 12 | :------:|:------:|:-----------:| 13 | 20NG | 88.5 % | 19.06s 14 | R8 | 97.2 % | 1.90s 15 | R52 | 94.0 % | 3.01s 16 | Ohsumed | 68.5 % | 3.02s 17 | MR | 75.9 % | 4.00s 18 | ## Data 19 | 20 | We get the data from [original repo](https://github.com/yao8839836/text_gcn) and 21 | process with `remove_words.py`, `build_graph.py`. We modify these two files from 22 | the original repo and made some slight changes. 23 | We share the data in a zip file 24 | [online](https://drive.google.com/file/d/10kx3z3bjYFoeRjjg1_DZOAP39Jln0BCh/view?usp=sharing). 25 | Please uncompress the file and put it under `data/`. 26 | If you want to redo the processing, see options with `python build_graph.py 27 | --help` and `python remove_words.py --help`. 28 | 29 | Training with TextGCN and TextSGC can be memory intensive (10+ GB CPU memory 30 | required for the 20ng dataset). Therefore, we share a preprocessed version of 31 | the data [online](https://drive.google.com/file/d/1M3lxIjtqqsb9tzLXDeWTlh283dhc8CeV/view?usp=sharing). To use it, 32 | download and decompress to `./preprocessed`, and use the `--preprocessed` flag. 33 | 34 | ## Usage 35 | 36 | There is only one hyperparameter needs to be set and we tune it with hyperopt. 37 | We provide the tuned hyperparameters under `tuned_result`. 38 | You can replicate the paper reported result by 39 | ``` 40 | python train.py --dataset
--tuned 41 | ``` 42 | 43 | See `tuning.py` for the tuning details. 44 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/downstream/TextSGC/build_corpus.py: -------------------------------------------------------------------------------- 1 | import re 2 | # build corpus 3 | 4 | 5 | dataset = '20ng' 6 | 7 | f = open('data/' + dataset + '.txt', 'r') 8 | lines = f.readlines() 9 | docs = [] 10 | for line in lines: 11 | temp = line.split("\t") 12 | doc_file = open(temp[0], 'r') 13 | doc_content = doc_file.read() 14 | doc_file.close() 15 | print(temp[0], doc_content) 16 | doc_content = doc_content.replace('\n', ' ') 17 | docs.append(doc_content) 18 | 19 | 20 | corpus_str = '\n'.join(docs) 21 | f.close() 22 | 23 | f = open('data/corpus/' + dataset + '.txt', 'w') 24 | f.write(corpus_str) 25 | f.close() 26 | 27 | 28 | ''' 29 | # datasets from PTE paper 30 | f = open('data/dblp/label_train.txt', 'r') 31 | lines = f.readlines() 32 | f.close() 33 | 34 | doc_id = 0 35 | doc_name_list = [] 36 | for line in lines: 37 | string = str(doc_id) + '\t' + 'train' + '\t' + line.strip() 38 | doc_name_list.append(string) 39 | doc_id += 1 40 | 41 | f = open('data/dblp/label_test.txt', 'r') 42 | lines = f.readlines() 43 | f.close() 44 | 45 | for line in lines: 46 | string = str(doc_id) + '\t' + 'test' + '\t' + line.strip() 47 | doc_name_list.append(string) 48 | doc_id += 1 49 | 50 | doc_list_str = '\n'.join(doc_name_list) 51 | 52 | f = open('data/dblp.txt', 'w') 53 | f.write(doc_list_str) 54 | f.close() 55 | 56 | # TREC, R8, R52, WebKB 57 | 58 | dataset = 'R52' 59 | 60 | f = open('data/' + dataset + '/train.txt', 'r') 61 | lines = f.readlines() 62 | f.close() 63 | 64 | doc_id = 0 65 | doc_name_list = [] 66 | doc_content_list = [] 67 | 68 | for line in lines: 69 | line = line.strip() 70 | label = line[:line.find('\t')] 71 | content = line[line.find('\t') + 1:] 72 | string = str(doc_id) + '\t' + 'train' + '\t' + label 73 | doc_name_list.append(string) 74 | doc_content_list.append(content) 75 | doc_id += 1 76 | 77 | f = open('data/' + dataset + '/test.txt', 'r') 78 | lines = f.readlines() 79 | f.close() 80 | 81 | for line in lines: 82 | line = line.strip() 83 | label = line[:line.find('\t')] 84 | content = line[line.find('\t') + 1:] 85 | string = str(doc_id) + '\t' + 'test' + '\t' + label 86 | doc_name_list.append(string) 87 | doc_content_list.append(content) 88 | doc_id += 1 89 | 90 | doc_list_str = '\n'.join(doc_name_list) 91 | 92 | f = open('data/' + dataset + '.txt', 'w') 93 | f.write(doc_list_str) 94 | f.close() 95 | 96 | doc_name_list_str = '\n'.join(doc_name_list) 97 | 98 | f = open('data/' + dataset + '.txt', 'w') 99 | f.write(doc_list_str) 100 | f.close() 101 | 102 | doc_content_list_str = '\n'.join(doc_content_list) 103 | 104 | f = open('data/corpus/' + dataset + '.txt', 'w') 105 | f.write(doc_content_list_str) 106 | f.close() 107 | ''' 108 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/downstream/TextSGC/models.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | from torch.nn.parameter import Parameter 4 | import torch.nn.functional as F 5 | 6 | class SGC(nn.Module): 7 | def __init__(self, nfeat, nclass, bias=False): 8 | super(SGC, self).__init__() 9 | 10 | self.W = nn.Linear(nfeat, nclass, bias=bias) 11 | torch.nn.init.xavier_normal_(self.W.weight) 12 | 13 | def forward(self, x): 14 | out = self.W(x) 15 | return out 16 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/downstream/TextSGC/requirements.txt: -------------------------------------------------------------------------------- 1 | hyperopt==0.1.1 -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/downstream/TextSGC/tuned_result/20ng.SGC.tuning.txt: -------------------------------------------------------------------------------- 1 | 0.0013576034109430972 -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/downstream/TextSGC/tuned_result/R52.SGC.tuning.txt: -------------------------------------------------------------------------------- 1 | 3.39184266146822e-06 -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/downstream/TextSGC/tuned_result/R8.SGC.tuning.txt: -------------------------------------------------------------------------------- 1 | 0.000555422439238392 -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/downstream/TextSGC/tuned_result/mr.SGC.tuning.txt: -------------------------------------------------------------------------------- 1 | 0.0031331167329072614 -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/downstream/TextSGC/tuned_result/ohsumed.SGC.tuning.txt: -------------------------------------------------------------------------------- 1 | 0.003911359029974794 -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/downstream/TextSGC/tuning.py: -------------------------------------------------------------------------------- 1 | import time 2 | import argparse 3 | import numpy as np 4 | from train import train 5 | import pickle as pkl 6 | from hyperopt import fmin, tpe, hp, STATUS_OK, Trials 7 | from args import get_text_args 8 | from utils import * 9 | from train import train_linear, adj, sp_adj, label_dict, index_dict 10 | import torch.nn.functional as F 11 | from models import get_model 12 | from math import log 13 | 14 | args = get_text_args() 15 | set_seed(args.seed, args.cuda) 16 | 17 | adj_dense = sparse_to_torch_dense(sp_adj, device='cpu') 18 | feat_dict, precompute_time = sgc_precompute(adj, adj_dense, args.degree-1, index_dict) 19 | if args.dataset == "mr": nclass = 1 20 | else: nclass = label_dict["train"].max().item()+1 21 | 22 | def linear_objective(space): 23 | model = get_model(args.model, nfeat=feat_dict["train"].size(1), 24 | nclass=nclass, 25 | nhid=0, dropout=0, cuda=args.cuda) 26 | val_acc, _, _ = train_linear(model, feat_dict, space['weight_decay'], args.dataset=="mr") 27 | print( 'weight decay ' + str(space['weight_decay']) + '\n' + \ 28 | 'overall accuracy: ' + str(val_acc)) 29 | return {'loss': -val_acc, 'status': STATUS_OK} 30 | 31 | # Hyperparameter optimization 32 | space = {'weight_decay' : hp.loguniform('weight_decay', log(1e-6), log(1e-0))} 33 | 34 | best = fmin(linear_objective, space=space, algo=tpe.suggest, max_evals=60) 35 | print(best) 36 | 37 | with open('{}.SGC.tuning.txt'.format(args.dataset), 'w') as f: 38 | f.write(str(best['weight_decay'])) 39 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/metrics.py: -------------------------------------------------------------------------------- 1 | from sklearn.metrics import f1_score 2 | 3 | def accuracy(output, labels): 4 | preds = output.max(1)[1].type_as(labels) 5 | correct = preds.eq(labels).double() 6 | correct = correct.sum() 7 | return correct / len(labels) 8 | 9 | def f1(output, labels): 10 | preds = output.max(1)[1] 11 | preds = preds.cpu().detach().numpy() 12 | labels = labels.cpu().detach().numpy() 13 | micro = f1_score(labels, preds, average='micro') 14 | macro = f1_score(labels, preds, average='macro') 15 | return micro, macro 16 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/model.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/competitors/competitors_setups/SGC/sgc/model.jpg -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/models.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | from torch.nn import Module 4 | import torch.nn.functional as F 5 | import math 6 | 7 | class SGC(nn.Module): 8 | """ 9 | A Simple PyTorch Implementation of Logistic Regression. 10 | Assuming the features have been preprocessed with k-step graph propagation. 11 | """ 12 | def __init__(self, nfeat, nclass): 13 | super(SGC, self).__init__() 14 | 15 | self.W = nn.Linear(nfeat, nclass) 16 | 17 | def forward(self, x): 18 | return self.W(x) 19 | 20 | class GraphConvolution(Module): 21 | """ 22 | A Graph Convolution Layer (GCN) 23 | """ 24 | 25 | def __init__(self, in_features, out_features, bias=True): 26 | super(GraphConvolution, self).__init__() 27 | self.in_features = in_features 28 | self.out_features = out_features 29 | self.W = nn.Linear(in_features, out_features, bias=bias) 30 | self.init() 31 | 32 | def init(self): 33 | stdv = 1. / math.sqrt(self.W.weight.size(1)) 34 | self.W.weight.data.uniform_(-stdv, stdv) 35 | 36 | def forward(self, input, adj): 37 | support = self.W(input) 38 | output = torch.spmm(adj, support) 39 | 40 | class GCN(nn.Module): 41 | """ 42 | A Two-layer GCN. 43 | """ 44 | def __init__(self, nfeat, nhid, nclass, dropout): 45 | super(GCN, self).__init__() 46 | 47 | self.gc1 = GraphConvolution(nfeat, nhid) 48 | self.gc2 = GraphConvolution(nhid, nclass) 49 | self.dropout = dropout 50 | 51 | def forward(self, x, adj, use_relu=True): 52 | x = self.gc1(x, adj) 53 | if use_relu: 54 | x = F.relu(x) 55 | x = F.dropout(x, self.dropout, training=self.training) 56 | x = self.gc2(x, adj) 57 | return x 58 | 59 | def get_model(model_opt, nfeat, nclass, nhid=0, dropout=0, cuda=True): 60 | if model_opt == "GCN": 61 | model = GCN(nfeat=nfeat, 62 | nhid=nhid, 63 | nclass=nclass, 64 | dropout=dropout) 65 | elif model_opt == "SGC": 66 | model = SGC(nfeat=nfeat, 67 | nclass=nclass) 68 | else: 69 | raise NotImplementedError('model:{} is not implemented!'.format(model_opt)) 70 | 71 | if cuda: model.cuda() 72 | return model 73 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/normalization.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import scipy.sparse as sp 3 | import torch 4 | 5 | def aug_normalized_adjacency(adj): 6 | adj = adj + sp.eye(adj.shape[0]) 7 | adj = sp.coo_matrix(adj) 8 | row_sum = np.array(adj.sum(1)) 9 | d_inv_sqrt = np.power(row_sum, -0.5).flatten() 10 | d_inv_sqrt[np.isinf(d_inv_sqrt)] = 0. 11 | d_mat_inv_sqrt = sp.diags(d_inv_sqrt) 12 | return d_mat_inv_sqrt.dot(adj).dot(d_mat_inv_sqrt).tocoo() 13 | 14 | def fetch_normalization(type): 15 | switcher = { 16 | 'AugNormAdj': aug_normalized_adjacency, # A' = (D + I)^-1/2 * ( A + I ) * (D + I)^-1/2 17 | } 18 | func = switcher.get(type, lambda: "Invalid normalization technique.") 19 | return func 20 | 21 | def row_normalize(mx): 22 | """Row-normalize sparse matrix""" 23 | rowsum = np.array(mx.sum(1)) 24 | r_inv = np.power(rowsum, -1).flatten() 25 | r_inv[np.isinf(r_inv)] = 0. 26 | r_mat_inv = sp.diags(r_inv) 27 | mx = r_mat_inv.dot(mx) 28 | return mx 29 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/reddit.py: -------------------------------------------------------------------------------- 1 | from time import perf_counter 2 | import argparse 3 | import numpy as np 4 | import torch 5 | import torch.nn.functional as F 6 | import torch.optim as optim 7 | from utils import load_reddit_data, sgc_precompute, set_seed 8 | from metrics import f1 9 | from models import SGC 10 | 11 | # Args 12 | parser = argparse.ArgumentParser() 13 | parser.add_argument('--no-cuda', action='store_true', default=False, 14 | help='Disables CUDA training.') 15 | parser.add_argument('--inductive', action='store_true', default=False, 16 | help='inductive training.') 17 | parser.add_argument('--test', action='store_true', default=False, 18 | help='inductive training.') 19 | parser.add_argument('--seed', type=int, default=42, help='Random seed.') 20 | parser.add_argument('--epochs', type=int, default=2, 21 | help='Number of epochs to train.') 22 | parser.add_argument('--weight_decay', type=float, default=0, 23 | help='Weight decay (L2 loss on parameters).') 24 | parser.add_argument('--normalization', type=str, default='AugNormAdj', 25 | choices=['NormLap', 'Lap', 'RWalkLap', 'FirstOrderGCN', 26 | 'AugNormAdj', 'NormAdj', 'RWalk', 'AugRWalk', 'NoNorm'], 27 | help='Normalization method for the adjacency matrix.') 28 | parser.add_argument('--model', type=str, default="SGC", 29 | help='model to use.') 30 | parser.add_argument('--degree', type=int, default=2, 31 | help='degree of the approximation.') 32 | 33 | args = parser.parse_args() 34 | args.cuda = not args.no_cuda and torch.cuda.is_available() 35 | 36 | set_seed(args.seed, args.cuda) 37 | 38 | adj, train_adj, features, labels, idx_train, idx_val, idx_test = load_reddit_data(args.normalization) 39 | print("Finished data loading.") 40 | 41 | model = SGC(features.size(1), labels.max().item()+1) 42 | if args.cuda: model.cuda() 43 | processed_features, precompute_time = sgc_precompute(features, adj, args.degree) 44 | if args.inductive: 45 | train_features, _ = sgc_precompute(features[idx_train], train_adj, args.degree) 46 | else: 47 | train_features = processed_features[idx_train] 48 | 49 | test_features = processed_features[idx_test if args.test else idx_val] 50 | 51 | def train_regression(model, train_features, train_labels, epochs): 52 | optimizer = optim.LBFGS(model.parameters(), lr=1) 53 | model.train() 54 | def closure(): 55 | optimizer.zero_grad() 56 | output = model(train_features) 57 | loss_train = F.cross_entropy(output, train_labels) 58 | loss_train.backward() 59 | return loss_train 60 | t = perf_counter() 61 | for epoch in range(epochs): 62 | loss_train = optimizer.step(closure) 63 | train_time = perf_counter()-t 64 | return model, train_time 65 | 66 | def test_regression(model, test_features, test_labels): 67 | model.eval() 68 | return f1(model(test_features), test_labels) 69 | 70 | model, train_time = train_regression(model, train_features, labels[idx_train], args.epochs) 71 | test_f1, _ = test_regression(model, test_features, labels[idx_test if args.test else idx_val]) 72 | print("Total Time: {:.4f}s, {} F1: {:.4f}".format(train_time+precompute_time, 73 | "Test" if args.test else "Val", 74 | test_f1)) 75 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | scipy 3 | networkx==1.11 4 | scikit-learn 5 | hyperopt==0.1.1 6 | -------------------------------------------------------------------------------- /competitors/competitors_setups/SGC/sgc/tuning.py: -------------------------------------------------------------------------------- 1 | import time 2 | import argparse 3 | import numpy as np 4 | import pickle as pkl 5 | import os 6 | from math import log 7 | from citation import train_regression 8 | from models import get_model 9 | from utils import sgc_precompute, load_citation, set_seed 10 | from args import get_citation_args 11 | import torch 12 | from hyperopt import fmin, tpe, hp, STATUS_OK, Trials 13 | 14 | # Arguments 15 | args = get_citation_args() 16 | 17 | # setting random seeds 18 | set_seed(args.seed, args.cuda) 19 | 20 | # Hyperparameter optimization 21 | space = {'weight_decay' : hp.loguniform('weight_decay', log(1e-10), log(1e-4))} 22 | 23 | adj, features, labels, idx_train, idx_val, idx_test = load_citation(args.dataset, args.normalization, args.cuda) 24 | if args.model == "SGC": features, precompute_time = sgc_precompute(features, adj, args.degree) 25 | 26 | def sgc_objective(space): 27 | model = get_model(args.model, features.size(1), labels.max().item()+1, args.hidden, args.dropout, args.cuda) 28 | model, acc_val, _ = train_regression(model, features[idx_train], labels[idx_train], features[idx_val], labels[idx_val], 29 | args.epochs, space['weight_decay'], args.lr, args.dropout) 30 | print('weight decay: {:.2e} '.format(space['weight_decay']) + 'accuracy: {:.4f}'.format(acc_val)) 31 | return {'loss': -acc_val, 'status': STATUS_OK} 32 | 33 | best = fmin(sgc_objective, space=space, algo=tpe.suggest, max_evals=60) 34 | print("Best weight decay: {:.2e}".format(best["weight_decay"])) 35 | 36 | os.makedirs("./{}-tuning".format(args.model), exist_ok=True) 37 | path = '{}-tuning/{}.txt'.format(args.model, args.dataset) 38 | with open(path, 'wb') as f: pkl.dump(best, f) 39 | -------------------------------------------------------------------------------- /competitors/competitors_setups/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | pip3 install -e APPNP 3 | pip3 install -e HGNN 4 | pip3 install -e HyperGCN 5 | pip3 install -e SCE 6 | pip3 install -e SGC 7 | -------------------------------------------------------------------------------- /competitors/competitors_setups/readme.md: -------------------------------------------------------------------------------- 1 | Install all the libraries with install.sh and then requirements 2 | 3 | pip install torch (if it's not installed) 4 | then follow the guide here to install torch-scatter and torch-sparse https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html 5 | 6 | pip install numpy 7 | pip install pandas 8 | pip install sklearn 9 | pip install networkx 10 | pip install texttable 11 | pip install tqdm 12 | pip install hyperopt 13 | -------------------------------------------------------------------------------- /competitors/results/citeseer.csv: -------------------------------------------------------------------------------- 1 | ,dataset_name,neighbors,train_perc,trial_number,acc_appnp,rec_appnp,prec_appnp,acc_hgnn,rec_hgnn,prec_hgnn,acc_hypergcn,rec_hypergcn,prec_hypergcn,acc_sgc,rec_sgc,prec_sgc,acc_sce,rec_sce,prec_sce,acc_hols_labels_features,rec_hols_labels_features,prec_hols_labels_features,p,α 2 | 0,citeseer,7,0.042,1,63.59918200408998,56.379202919867,59.798686136056034,58.94683026584867,54.64978083076887,58.76509973276001,44.93865030674847,57.0657395509201,36.15978639052765,50.81799591002045,47.779021197870215,57.864990730104935,61.809815950920246,55.91935157213651,56.724391450337016,72.08588957055214,64.6673886395151,71.83426639803953,0.5,0.5 3 | -------------------------------------------------------------------------------- /competitors/results/contact-high-school.csv: -------------------------------------------------------------------------------- 1 | ,dataset_name,neighbors,train_perc,trial_number,acc_hols_labels_features,rec_hols_labels_features,prec_hols_labels_features,p,α 2 | 0,contact-high-school,7,0.01,1,92.88025889967638,92.90691774136907,93.46009442554158,1.0,0.7 3 | 1,contact-high-school,7,0.05,1,95.50173010380622,95.01193516998114,95.67060975663126,1.0,0.7 4 | 2,contact-high-school,7,0.1,1,98.0392156862745,97.84507947639085,98.20124784282491,1.0,0.7 5 | 3,contact-high-school,7,0.01,2,94.8220064724919,94.18823585490253,95.38456169954885,2.0,0.9 6 | 4,contact-high-school,7,0.05,2,99.65397923875432,99.68253968253968,99.64157706093191,1.0,0.9 7 | 5,contact-high-school,7,0.1,2,98.82352941176471,98.87438129373614,98.84366662144441,2.0,0.9 8 | 6,contact-high-school,7,0.01,3,97.41100323624595,96.97391627216189,97.78360041517935,1.0,0.9 9 | 7,contact-high-school,7,0.05,3,98.96193771626297,98.66666666666666,99.0990990990991,10.0,0.9 10 | 8,contact-high-school,7,0.1,3,98.82352941176471,98.72325741890961,98.8479262672811,1.0,0.9 11 | 9,contact-high-school,7,0.01,4,88.3495145631068,87.68296805577506,93.43290102164032,1.0,0.9 12 | 10,contact-high-school,7,0.05,4,99.30795847750865,99.34413580246913,99.30555555555556,2.0,0.9 13 | 11,contact-high-school,7,0.1,4,98.82352941176471,98.60646599777034,98.7938129700582,1.0,0.9 14 | 12,contact-high-school,7,0.01,5,93.20388349514563,92.24369585566694,94.5384379594906,2.0,0.9 15 | 13,contact-high-school,7,0.05,5,97.92387543252595,97.73765432098764,97.96441113645416,1.0,0.9 16 | 14,contact-high-school,7,0.1,5,98.0392156862745,97.80667701863354,97.86890064667843,1.0,0.9 17 | -------------------------------------------------------------------------------- /competitors/results/cora-author.csv: -------------------------------------------------------------------------------- 1 | ,dataset_name,neighbors,train_perc,trial_number,acc_appnp,rec_appnp,prec_appnp,acc_hgnn,rec_hgnn,prec_hgnn,acc_hypergcn,rec_hypergcn,prec_hypergcn,acc_sgc,rec_sgc,prec_sgc,acc_sce,rec_sce,prec_sce,acc_hols_labels_features,rec_hols_labels_features,prec_hols_labels_features,p,α 2 | 0,cora-author,7,0.052,1,68.07511737089203,62.44407354255955,66.03691365496103,60.610328638497656,55.69887018792562,60.43269752010385,60.093896713615024,67.7081788635631,62.343916770011155,30.751173708920188,51.59420289855072,65.19584709768759,69.71830985915493,66.1593408822852,66.5593702248177,71.87793427230046,68.83072900836324,70.5705404503836,0.5,0.5 3 | -------------------------------------------------------------------------------- /competitors/results/cora-cit.csv: -------------------------------------------------------------------------------- 1 | ,dataset_name,neighbors,train_perc,trial_number,acc_appnp,rec_appnp,prec_appnp,acc_hgnn,rec_hgnn,prec_hgnn,acc_hypergcn,rec_hypergcn,prec_hypergcn,acc_sgc,rec_sgc,prec_sgc,acc_sce,rec_sce,prec_sce,acc_hols_labels_features,rec_hols_labels_features,prec_hols_labels_features,p,α 2 | 0,cora-cit,7,0.052,1,81.18955512572535,79.07153359404757,80.70343751639064,61.992263056092845,57.674952324708364,63.74873518107657,63.34622823984526,72.32349612934594,64.82688301601162,29.061895551257255,34.44565480513193,76.22751579970831,80.51257253384912,79.90200087659746,80.1357489192098,71.76015473887814,68.50226087934645,70.94121404988336,0.5,0.5 3 | -------------------------------------------------------------------------------- /competitors/results/dblp.csv: -------------------------------------------------------------------------------- 1 | ,dataset_name,neighbors,train_perc,epochs,lr,wd,trial_number,acc_hols_labels_features,rec_hols_labels_features,prec_hols_labels_features,p,α 2 | 0,dblp,15,0.04,100.0,0.01,0.0005,1,86.38134344072436,85.47878104878176,85.90468998771178,10.0,0.1 3 | 1,dblp,15,0.04,100.0,0.01,0.0005,2,85.89176668772373,84.59243243381283,85.73154722824114,10.0,0.1 4 | 2,dblp,15,0.04,100.0,0.01,0.0005,3,86.11286586649821,85.12820586828445,85.85216920094922,10.0,0.1 5 | 3,dblp,15,0.04,100.0,0.01,0.0005,4,86.18393345967573,84.908688329064,85.84963112718495,10.0,0.1 6 | 4,dblp,15,0.04,100.0,0.01,0.0005,5,86.09970520109496,85.31508465337217,85.66107377401649,10.0,0.1 7 | -------------------------------------------------------------------------------- /competitors/results/pubmed.csv: -------------------------------------------------------------------------------- 1 | ,dataset_name,neighbors,train_perc,epochs,lr,wd,trial_number,acc_hols_labels_features,rec_hols_labels_features,prec_hols_labels_features,p,α 2 | 0,pubmed,15,0.008,100.0,0.01,0.0005,1,78.16780821917808,80.42085190886681,77.776873122308,2.0,0.1 3 | 1,pubmed,15,0.008,100.0,0.01,0.0005,2,79.60426179604262,80.10151071405157,79.66246529852205,3.0,0.1 4 | 2,pubmed,15,0.008,100.0,0.01,0.0005,3,79.96575342465754,81.19170354797161,79.00190668620722,1.0,0.1 5 | 3,pubmed,15,0.008,100.0,0.01,0.0005,4,76.9406392694064,78.90636145484143,77.35744726702683,3.0,0.1 6 | 4,pubmed,15,0.008,100.0,0.01,0.0005,5,79.21423135464232,81.03738049154914,79.09365833222758,3.0,0.1 7 | -------------------------------------------------------------------------------- /competitors/results/time.csv: -------------------------------------------------------------------------------- 1 | ,dataset_name,appnp,hgnn,hypergcn,sgc,sce,hols_labels_features 2 | 0,citeseer,4.556233199,6.115193101,9.752259699,2.018753101,6.8214153,5.8461392 3 | -------------------------------------------------------------------------------- /competitors/scripts/appnp.jl: -------------------------------------------------------------------------------- 1 | # using Revise 2 | 3 | include(joinpath(pwd(),"Tensor_Package", "Tensor_Package.jl")) 4 | include(joinpath(pwd(), "competitors", "scripts", "utils.jl")) 5 | 6 | using .Tensor_Package.Tensor_Package, 7 | Random, 8 | Base.Threads, 9 | SparseArrays, 10 | MLDataUtils, 11 | PyCall, 12 | DataStructures, 13 | CSV, 14 | StatsBase, 15 | InvertedIndices, 16 | DataFrames, 17 | LinearAlgebra 18 | 19 | np = pyimport("numpy") 20 | sp = pyimport("scipy.sparse") 21 | pickle = pyimport("pickle") 22 | main_jl = pyimport("appnp.main_jl") 23 | # @pyimport scipy.sparse as sp 24 | # @pyimport pickle 25 | # @pyimport appnp.main_jl as main_jl 26 | 27 | function APPNP_test(dataset_name, order, kn, perc_train, perc_val; balanced=true, type="network", features=false) 28 | 29 | args = Dict("model" => "exact", 30 | "epochs"=> 2000, 31 | "seed" => 42, 32 | "iterations" => 10, 33 | "early_stopping_rounds" => 500, 34 | "dropout" => 0.5, 35 | "alpha" => 0.1, 36 | "learning_rate" => 0.01, 37 | "lambd" => 0.005, 38 | "layers" => [64, 64]) 39 | 40 | X, y, B, W, _, _, edges_ = Tensor_Package.prepare_incidence_data(dataset_name, order, kn; type=type, features=features) 41 | A = clique_adj(W, B) 42 | clique_edges = adj_to_edges_list(A) 43 | train_inds, test_inds, val_inds = Tensor_Package.train_test_val_split_indices(y, perc_train, perc_val; balanced=false) 44 | features = sparse_to_dic(X) 45 | test_inds = collect(setdiff(Set(1:length(y)), Set(train_inds))) 46 | y = np.array(y) 47 | pred = main_jl.main(args, clique_edges, features, y, train_inds .- 1, test_inds .- 1, val_inds .- 1) 48 | 49 | return Tensor_Package.accuracy(vec(pred[test_inds]), y[test_inds]) 50 | end 51 | 52 | 53 | function APPNP(args, X, y, clique_edges, train_inds, test_inds, val_inds) 54 | 55 | epochs, lr, wd = args 56 | 57 | 58 | args = Dict("model" => "exact", 59 | "epochs"=> Int(epochs), 60 | "seed" => 42, 61 | "iterations" => 10, 62 | "early_stopping_rounds" => 500, 63 | "dropout" => 0.5, 64 | "alpha" => 0.1, 65 | "learning_rate" => lr, 66 | "lambd" => wd, 67 | "layers" => [64, 64]) 68 | 69 | features = sparse_to_dic(X) 70 | y = np.array(y) 71 | pred = main_jl.main(args, clique_edges, features, y, train_inds, test_inds, val_inds) 72 | 73 | return Tensor_Package.calc_metrics(vec(pred[test_inds.+ 1]), y[test_inds .+ 1]) 74 | 75 | end 76 | 77 | #pred = APPNP_test("cora-cit", 3, 15, .05, .05; type="network", features=true) 78 | -------------------------------------------------------------------------------- /competitors/scripts/hgnn.jl: -------------------------------------------------------------------------------- 1 | # using Revise 2 | 3 | include(joinpath(pwd(),"Tensor_Package", "Tensor_Package.jl")) 4 | include(joinpath(pwd(), "competitors", "scripts", "utils.jl")) 5 | 6 | 7 | using .Tensor_Package.Tensor_Package, 8 | Random, 9 | Base.Threads, 10 | SparseArrays, 11 | MLDataUtils, 12 | PyCall, 13 | DataStructures, 14 | CSV, 15 | StatsBase, 16 | InvertedIndices, 17 | Suppressor, 18 | UCIData, 19 | DataFrames 20 | 21 | np = pyimport("numpy") 22 | sp = pyimport("scipy.sparse") 23 | pickle = pyimport("pickle") 24 | train_jl = pyimport("hgnn.train_jl") 25 | 26 | 27 | function HGNN_test(dataset_name, order, kn, perc_train; balanced=true, type="network", features=true) 28 | 29 | args = Dict("K_neigs"=> [10], 30 | "max_epoch" => 600, 31 | "n_hid" => 128, 32 | "lr" => 0.001, 33 | "milestones" => [100], 34 | "gamma" => 0.9, 35 | "drop_out" => 0.5, 36 | "print_freq" => 50, 37 | "weight_decay" => 0.0005, 38 | "decay_step" => 200, 39 | "decay_rate" => 0.7) 40 | 41 | X, y, _, _, _, _ = Tensor_Package.prepare_incidence_data(dataset_name, order, kn; type=type, features=features) 42 | X_features, X_labels, train_inds = Tensor_Package.prepare_features_and_labels(X,y, 43 | perc_train; percentage_of_known_features=1, feature_remove_style="rows") 44 | test_inds = collect(setdiff(Set(1:length(y)), Set(train_inds))) 45 | 46 | X_features = np.array(X_features) 47 | y = np.array(y) 48 | 49 | 50 | pred = train_jl.train(args, X_features, y, train_inds .- 1, test_inds .- 1) 51 | 52 | 53 | return Tensor_Package.accuracy(vec(pred)[test_inds], y[test_inds]) 54 | end 55 | 56 | 57 | function HGNN(args, X_features, y, train_inds, test_inds) 58 | 59 | epochs, lr, wd = args 60 | 61 | args = Dict("K_neigs"=> [10], 62 | "max_epoch" => Int(epochs), 63 | "n_hid" => 128, 64 | "lr" => lr, 65 | "milestones" => [100], 66 | "gamma" => 0.9, 67 | "drop_out" => 0.5, 68 | "print_freq" => 50, 69 | "weight_decay" => wd, 70 | "decay_step" => 200, 71 | "decay_rate" => 0.7) 72 | 73 | X_features = np.array(X_features) 74 | y = np.array(y) 75 | pred = train_jl.train(args, X_features, y, train_inds, test_inds) 76 | 77 | pred_unknown = pred[test_inds .+ 1] 78 | y_unknown = y[test_inds .+ 1] 79 | return Tensor_Package.calc_metrics(vec(pred_unknown), y_unknown) 80 | end 81 | 82 | 83 | #pred = HGNN_test("cora-cit", 3, 15, .05, type="network", features=true) 84 | -------------------------------------------------------------------------------- /competitors/scripts/hypergcn.jl: -------------------------------------------------------------------------------- 1 | # using Revise 2 | 3 | include(joinpath(pwd(),"Tensor_Package", "Tensor_Package.jl")) 4 | include(joinpath(pwd(), "competitors", "scripts", "utils.jl")) 5 | 6 | using .Tensor_Package.Tensor_Package, 7 | Random, 8 | Base.Threads, 9 | SparseArrays, 10 | MLDataUtils, 11 | PyCall, 12 | DataStructures, 13 | CSV, 14 | StatsBase, 15 | InvertedIndices 16 | 17 | np = pyimport("numpy") 18 | sp = pyimport("scipy.sparse") 19 | pickle = pyimport("pickle") 20 | hypergcn_jl = pyimport("hypergcn.hypergcn_jl") 21 | 22 | 23 | function HyperGCN_test(dataset_name, order, kn, perc_train; balanced=true, type="network", features=true) 24 | 25 | args = Dict("dataset" => dataset_name, 26 | "mediators" => false, 27 | "fast" => false, 28 | "split" => 1, 29 | "gpu" => 3, 30 | "cuda" => true, 31 | "seed" => 5, 32 | "depth" => 2, 33 | "dropout" => 0.5, 34 | "epochs" => 200, 35 | "rate" => 0.01, 36 | "decay" => 0.0005) 37 | 38 | X, y, B, _, _, _, edges_ = Tensor_Package.prepare_incidence_data(dataset_name, order, kn; type=type, features=features) 39 | new_edges = inc_to_edges(B) 40 | hypergraph = edges_to_graph(new_edges) 41 | X_features, X_labels, train_inds = Tensor_Package.prepare_features_and_labels(X,y, 42 | perc_train; percentage_of_known_features=1, feature_remove_style="rows") 43 | test_inds = collect(setdiff(Set(1:length(y)), Set(train_inds))) 44 | classes = Set(y) 45 | n = length(y) 46 | Y = zeros(n, length(classes)) 47 | for label in classes 48 | Y[y .== label, label] .= 1.0 49 | end 50 | X_features = sp.csr_matrix(X_features) 51 | 52 | test_acc, H, Z = hypergcn_jl.train(args, X_features, Y, hypergraph, train_inds .- 1, test_inds .- 1) 53 | 54 | final_pred = map(x->x[2], argmax(H,dims=2)) 55 | 56 | #return test_acc, H, Z 57 | print(test_inds) 58 | return Tensor_Package.accuracy(vec(final_pred[test_inds]), y[test_inds]), 59 | Tensor_Package.recall(vec(final_pred[test_inds]), y[test_inds]), 60 | Tensor_Package.precision(vec(final_pred[test_inds]), y[test_inds]) 61 | end 62 | 63 | 64 | function HyperGCN(args, X_features, y, hypergraph, train_inds, test_inds) 65 | 66 | epochs, lr, wd = args 67 | 68 | args = Dict("dataset" => "", 69 | "mediators" => false, 70 | "fast" => false, 71 | "split" => 1, 72 | "gpu" => 3, 73 | "cuda" => true, 74 | "seed" => 5, 75 | "depth" => 2, 76 | "dropout" => 0.5, 77 | "epochs" => Int(epochs), 78 | "rate" => lr, 79 | "decay" => wd) 80 | 81 | 82 | X_features = sp.csr_matrix(X_features) 83 | Y = labels_to_bin(y) 84 | test_acc, H, Z = hypergcn_jl.train(args, X_features, Y, hypergraph, train_inds, test_inds) 85 | final_pred = map(x->x[2], argmax(H,dims=2)) 86 | return Tensor_Package.calc_metrics(vec(final_pred[test_inds.+ 1]), y[test_inds .+ 1]) 87 | 88 | end 89 | 90 | #pred = HyperGCN_test("cora-cit", 3, 15, .06) 91 | -------------------------------------------------------------------------------- /competitors/scripts/sce.jl: -------------------------------------------------------------------------------- 1 | # using Revise 2 | 3 | include(joinpath(pwd(),"Tensor_Package", "Tensor_Package.jl")) 4 | include(joinpath(pwd(), "competitors", "scripts", "utils.jl")) 5 | 6 | using .Tensor_Package.Tensor_Package, 7 | Random, 8 | Base.Threads, 9 | SparseArrays, 10 | MLDataUtils, 11 | PyCall, 12 | DataStructures, 13 | CSV, 14 | StatsBase, 15 | InvertedIndices, 16 | DataFrames, 17 | LinearAlgebra 18 | 19 | np = pyimport("numpy") 20 | sp = pyimport("scipy.sparse") 21 | pickle = pyimport("pickle") 22 | sce_train = pyimport("sce.train_jl") 23 | 24 | 25 | 26 | function SCE_test(dataset_name, order, kn, perc_train, perc_val; 27 | balanced=true, type="network", features=false) 28 | 29 | args = Dict("no_cuda" => false, 30 | "seed"=> 123, 31 | "nhid" => 512, 32 | "output" => 512, 33 | "lr" => 0.01, 34 | "weight_decay" => 0, 35 | "epochs" => 30, 36 | "sample" => 5, 37 | "alpha" => 100000 38 | ) 39 | 40 | 41 | 42 | X, y, B, W, _, _, edges_ = Tensor_Package.prepare_incidence_data(dataset_name, order, kn; type=type, features=features) 43 | A = clique_adj(W, B) 44 | graph = edges_to_graph(edges_) 45 | Y_train, Y_test, Y_val, train_mask, test_mask, val_mask = Tensor_Package.train_test_val_split(y, perc_train, perc_val, balanced=balanced) 46 | idx_train, idx_test, idx_val = findall(train_mask) .- 1, findall(test_mask) .- 1, findall(val_mask) .- 1 47 | features = np.array(X) 48 | labels = np.array(y) 49 | A = np.array(A) 50 | pred = sce_train.train(args, A, features, 51 | labels, idx_train, idx_val, idx_test) 52 | return Tensor_Package.accuracy(pred, y[idx_test .+ 1]) 53 | end 54 | 55 | 56 | function SCE(args, A, X, y, train_inds, test_inds, val_inds) 57 | 58 | 59 | 60 | 61 | args = Dict("no_cuda" => false, 62 | "seed"=> 123, 63 | "nhid" => 512, 64 | "output" => 512, 65 | "lr" => 0.01, 66 | "weight_decay" => 0, 67 | "epochs" => 30, 68 | "sample" => 5, 69 | "alpha" => 100000 70 | ) 71 | 72 | 73 | 74 | features = np.array(X) 75 | labels = np.array(y) 76 | A = np.array(A) 77 | pred = sce_train.train(args, A, features, 78 | labels, train_inds, val_inds, test_inds) 79 | return Tensor_Package.calc_metrics(vec(pred), y[test_inds .+ 1]) 80 | 81 | end 82 | 83 | #pred = SCE_test("cora-cit", 3, 15, .01, .02, type="network", features=true) 84 | -------------------------------------------------------------------------------- /data/citeseer/features.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/features.pickle -------------------------------------------------------------------------------- /data/citeseer/hypergraph.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/hypergraph.pickle -------------------------------------------------------------------------------- /data/citeseer/labels.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/labels.pickle -------------------------------------------------------------------------------- /data/citeseer/splits/1.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/splits/1.pickle -------------------------------------------------------------------------------- /data/citeseer/splits/10.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/splits/10.pickle -------------------------------------------------------------------------------- /data/citeseer/splits/2.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/splits/2.pickle -------------------------------------------------------------------------------- /data/citeseer/splits/3.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/splits/3.pickle -------------------------------------------------------------------------------- /data/citeseer/splits/4.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/splits/4.pickle -------------------------------------------------------------------------------- /data/citeseer/splits/5.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/splits/5.pickle -------------------------------------------------------------------------------- /data/citeseer/splits/6.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/splits/6.pickle -------------------------------------------------------------------------------- /data/citeseer/splits/7.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/splits/7.pickle -------------------------------------------------------------------------------- /data/citeseer/splits/8.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/splits/8.pickle -------------------------------------------------------------------------------- /data/citeseer/splits/9.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/citeseer/splits/9.pickle -------------------------------------------------------------------------------- /data/contact-high-school/label-names-contact-high-school.txt: -------------------------------------------------------------------------------- 1 | 2BIO1 2 | 2BIO2 3 | 2BIO3 4 | MP*1 5 | MP*2 6 | PSI* 7 | PC 8 | PC* 9 | MP 10 | -------------------------------------------------------------------------------- /data/contact-high-school/node-labels-contact-high-school.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 9 3 | 3 4 | 3 5 | 8 6 | 8 7 | 3 8 | 3 9 | 7 10 | 7 11 | 7 12 | 8 13 | 8 14 | 1 15 | 1 16 | 3 17 | 3 18 | 8 19 | 8 20 | 8 21 | 9 22 | 9 23 | 4 24 | 4 25 | 9 26 | 9 27 | 9 28 | 3 29 | 3 30 | 2 31 | 2 32 | 3 33 | 3 34 | 6 35 | 6 36 | 3 37 | 3 38 | 3 39 | 9 40 | 9 41 | 3 42 | 3 43 | 1 44 | 8 45 | 8 46 | 8 47 | 3 48 | 3 49 | 5 50 | 5 51 | 4 52 | 4 53 | 5 54 | 5 55 | 1 56 | 1 57 | 2 58 | 2 59 | 5 60 | 5 61 | 3 62 | 5 63 | 5 64 | 3 65 | 3 66 | 3 67 | 4 68 | 4 69 | 4 70 | 3 71 | 9 72 | 5 73 | 5 74 | 9 75 | 9 76 | 3 77 | 2 78 | 2 79 | 2 80 | 9 81 | 9 82 | 1 83 | 1 84 | 2 85 | 3 86 | 3 87 | 1 88 | 1 89 | 8 90 | 8 91 | 3 92 | 3 93 | 9 94 | 3 95 | 4 96 | 4 97 | 3 98 | 5 99 | 5 100 | 5 101 | 3 102 | 9 103 | 9 104 | 8 105 | 8 106 | 8 107 | 3 108 | 3 109 | 9 110 | 1 111 | 1 112 | 8 113 | 8 114 | 3 115 | 3 116 | 3 117 | 3 118 | 5 119 | 4 120 | 4 121 | 3 122 | 1 123 | 1 124 | 1 125 | 5 126 | 5 127 | 3 128 | 9 129 | 3 130 | 3 131 | 9 132 | 2 133 | 7 134 | 8 135 | 1 136 | 7 137 | 7 138 | 2 139 | 2 140 | 7 141 | 7 142 | 7 143 | 9 144 | 7 145 | 7 146 | 4 147 | 6 148 | 6 149 | 9 150 | 7 151 | 9 152 | 9 153 | 9 154 | 9 155 | 9 156 | 4 157 | 4 158 | 4 159 | 4 160 | 4 161 | 2 162 | 4 163 | 2 164 | 4 165 | 4 166 | 7 167 | 9 168 | 4 169 | 4 170 | 5 171 | 5 172 | 7 173 | 5 174 | 5 175 | 2 176 | 2 177 | 5 178 | 2 179 | 2 180 | 5 181 | 2 182 | 2 183 | 5 184 | 5 185 | 5 186 | 2 187 | 5 188 | 5 189 | 5 190 | 4 191 | 2 192 | 2 193 | 2 194 | 5 195 | 5 196 | 5 197 | 8 198 | 2 199 | 6 200 | 6 201 | 5 202 | 7 203 | 6 204 | 6 205 | 7 206 | 2 207 | 6 208 | 6 209 | 2 210 | 2 211 | 8 212 | 8 213 | 6 214 | 6 215 | 6 216 | 8 217 | 8 218 | 8 219 | 8 220 | 2 221 | 2 222 | 8 223 | 6 224 | 8 225 | 1 226 | 8 227 | 6 228 | 8 229 | 8 230 | 8 231 | 5 232 | 1 233 | 2 234 | 6 235 | 7 236 | 1 237 | 1 238 | 1 239 | 1 240 | 1 241 | 1 242 | 6 243 | 8 244 | 6 245 | 1 246 | 1 247 | 1 248 | 6 249 | 8 250 | 6 251 | 8 252 | 1 253 | 6 254 | 6 255 | 6 256 | 6 257 | 6 258 | 7 259 | 8 260 | 5 261 | 1 262 | 8 263 | 6 264 | 1 265 | 7 266 | 1 267 | 1 268 | 7 269 | 7 270 | 4 271 | 9 272 | 7 273 | 7 274 | 5 275 | 4 276 | 7 277 | 1 278 | 7 279 | 9 280 | 7 281 | 7 282 | 6 283 | 4 284 | 1 285 | 7 286 | 1 287 | 7 288 | 7 289 | 2 290 | 7 291 | 7 292 | 7 293 | 7 294 | 6 295 | 8 296 | 6 297 | 6 298 | 8 299 | 7 300 | 7 301 | 7 302 | 2 303 | 7 304 | 5 305 | 7 306 | 8 307 | 7 308 | 6 309 | 2 310 | 6 311 | 6 312 | 1 313 | 7 314 | 4 315 | 7 316 | 7 317 | 5 318 | 9 319 | 4 320 | 5 321 | 9 322 | 7 323 | 9 324 | 2 325 | 1 326 | 6 327 | 4 328 | -------------------------------------------------------------------------------- /data/contact-high-school/parse.jl: -------------------------------------------------------------------------------- 1 | function read_single(filename::String) 2 | ret = Int64[] 3 | open(filename) do f 4 | for line in eachline(f) 5 | push!(ret, parse(Int64, line)) 6 | end 7 | end 8 | return ret 9 | end 10 | 11 | function read_node_map(filename::String) 12 | nm = Dict{Int64,Int64}() 13 | open(filename) do f 14 | for (i, line) in enumerate(eachline(f)) 15 | if i == 1; continue; end 16 | new, orig = [parse(Int64, v) for v in split(line)] 17 | nm[orig] = new 18 | end 19 | end 20 | return nm 21 | end 22 | 23 | function read_labels(filename::String, nm, n::Int64) 24 | labels = zeros(Int64, n) 25 | label_map = Dict{AbstractString,Int64}() 26 | 27 | open(filename) do f 28 | for line in eachline(f) 29 | data = split(line) 30 | orig_id = parse(Int64, data[1]) 31 | # Some nodes do not participate in any edge 32 | if !haskey(nm, orig_id); continue; end 33 | node = nm[orig_id] 34 | label = data[2] 35 | if !haskey(label_map, label) 36 | label_map[label] = length(label_map) + 1 37 | end 38 | labels[node] = label_map[label] 39 | end 40 | end 41 | 42 | return labels, label_map 43 | end 44 | 45 | function main() 46 | nverts = read_single("raw/contact-high-school-nverts.txt") 47 | simplices = read_single("raw/contact-high-school-simplices.txt") 48 | nm = read_node_map("raw/contact-high-school-nodemap.txt") 49 | labels, label_map = read_labels("raw/metadata_2013.txt", nm, maximum(simplices)) 50 | 51 | hedges = Set{Set{Int64}}() 52 | 53 | let curr_ind = 0 54 | for nvert in nverts 55 | simplex = simplices[(curr_ind + 1):(curr_ind + nvert)] 56 | push!(hedges, Set{Int64}(simplex)) 57 | curr_ind += nvert 58 | end 59 | end 60 | 61 | open("hyperedges-contact-high-school.txt", "w") do f 62 | for hedge in hedges 63 | write(f, join(sort(collect(hedge)), ',')) 64 | write(f, "\n") 65 | end 66 | end 67 | 68 | open("label-names-contact-high-school.txt", "w") do f 69 | output = sort([(v, k) for (k, v) in label_map]) 70 | for (v, k) in output 71 | write(f, "$k\n") 72 | end 73 | end 74 | 75 | open("node-labels-contact-high-school.txt", "w") do f 76 | for l in labels 77 | write(f, "$l\n") 78 | end 79 | end 80 | end 81 | -------------------------------------------------------------------------------- /data/cora-author/features.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/features.pickle -------------------------------------------------------------------------------- /data/cora-author/hypergraph.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/hypergraph.pickle -------------------------------------------------------------------------------- /data/cora-author/labels.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/labels.pickle -------------------------------------------------------------------------------- /data/cora-author/splits/1.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/splits/1.pickle -------------------------------------------------------------------------------- /data/cora-author/splits/10.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/splits/10.pickle -------------------------------------------------------------------------------- /data/cora-author/splits/2.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/splits/2.pickle -------------------------------------------------------------------------------- /data/cora-author/splits/3.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/splits/3.pickle -------------------------------------------------------------------------------- /data/cora-author/splits/4.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/splits/4.pickle -------------------------------------------------------------------------------- /data/cora-author/splits/5.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/splits/5.pickle -------------------------------------------------------------------------------- /data/cora-author/splits/6.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/splits/6.pickle -------------------------------------------------------------------------------- /data/cora-author/splits/7.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/splits/7.pickle -------------------------------------------------------------------------------- /data/cora-author/splits/8.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/splits/8.pickle -------------------------------------------------------------------------------- /data/cora-author/splits/9.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-author/splits/9.pickle -------------------------------------------------------------------------------- /data/cora-cit/features.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/features.pickle -------------------------------------------------------------------------------- /data/cora-cit/hypergraph.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/hypergraph.pickle -------------------------------------------------------------------------------- /data/cora-cit/labels.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/labels.pickle -------------------------------------------------------------------------------- /data/cora-cit/splits/1.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/splits/1.pickle -------------------------------------------------------------------------------- /data/cora-cit/splits/10.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/splits/10.pickle -------------------------------------------------------------------------------- /data/cora-cit/splits/2.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/splits/2.pickle -------------------------------------------------------------------------------- /data/cora-cit/splits/3.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/splits/3.pickle -------------------------------------------------------------------------------- /data/cora-cit/splits/4.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/splits/4.pickle -------------------------------------------------------------------------------- /data/cora-cit/splits/5.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/splits/5.pickle -------------------------------------------------------------------------------- /data/cora-cit/splits/6.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/splits/6.pickle -------------------------------------------------------------------------------- /data/cora-cit/splits/7.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/splits/7.pickle -------------------------------------------------------------------------------- /data/cora-cit/splits/8.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/splits/8.pickle -------------------------------------------------------------------------------- /data/cora-cit/splits/9.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/cora-cit/splits/9.pickle -------------------------------------------------------------------------------- /data/dblp/features.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/features.pickle -------------------------------------------------------------------------------- /data/dblp/hypergraph.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/hypergraph.pickle -------------------------------------------------------------------------------- /data/dblp/labels.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/labels.pickle -------------------------------------------------------------------------------- /data/dblp/splits/1.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/splits/1.pickle -------------------------------------------------------------------------------- /data/dblp/splits/10.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/splits/10.pickle -------------------------------------------------------------------------------- /data/dblp/splits/2.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/splits/2.pickle -------------------------------------------------------------------------------- /data/dblp/splits/3.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/splits/3.pickle -------------------------------------------------------------------------------- /data/dblp/splits/4.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/splits/4.pickle -------------------------------------------------------------------------------- /data/dblp/splits/5.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/splits/5.pickle -------------------------------------------------------------------------------- /data/dblp/splits/6.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/splits/6.pickle -------------------------------------------------------------------------------- /data/dblp/splits/7.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/splits/7.pickle -------------------------------------------------------------------------------- /data/dblp/splits/8.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/splits/8.pickle -------------------------------------------------------------------------------- /data/dblp/splits/9.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/dblp/splits/9.pickle -------------------------------------------------------------------------------- /data/foodweb/additional_data/foodweb_species.txt: -------------------------------------------------------------------------------- 1 | 2um Spherical Phytoplankt 2 | Synedococcus 3 | Oscillatoria 4 | Small Diatoms (<20um) 5 | Big Diatoms (>20um) 6 | Dinoflagellates 7 | Other Phytoplankton 8 | Benthic Phytoplankton 9 | Thalassia 10 | Halodule 11 | Syringodium 12 | Roots 13 | Drift Algae 14 | Epiphytes 15 | Free Bacteria 16 | Water Flagellates 17 | Water Cilitaes 18 | Acartia Tonsa 19 | Oithona nana 20 | Paracalanus 21 | Other Copepoda 22 | Meroplankton 23 | Other Zooplankton 24 | Benthic Flagellates 25 | Benthic Ciliates 26 | Meiofauna 27 | Sponges 28 | Coral 29 | Other Cnidaridae 30 | Echinoderma 31 | Bivalves 32 | Detritivorous Gastropods 33 | Epiphytic Gastropods 34 | Predatory Gastropods 35 | Detritivorous Polychaetes 36 | Predatory Polychaetes 37 | Suspension Feeding Polych 38 | Macrobenthos 39 | Benthic Crustaceans 40 | Detritivorous Amphipods 41 | Herbivorous Amphipods 42 | Isopods 43 | Herbivorous Shrimp 44 | Predatory Shrimp 45 | Pink Shrimp 46 | Thor Floridanus 47 | Lobster 48 | Detritivorous Crabs 49 | Omnivorous Crabs 50 | Predatory Crabs 51 | Callinectus sapidus 52 | Stone Crab 53 | Sharks 54 | Rays 55 | Tarpon 56 | Bonefish 57 | Sardines 58 | Anchovy 59 | Bay Anchovy 60 | Lizardfish 61 | Catfish 62 | Eels 63 | Toadfish 64 | Brotalus 65 | Halfbeaks 66 | Needlefish 67 | Other Killifish 68 | Goldspotted killifish 69 | Rainwater killifish 70 | Snook 71 | Sailfin Molly 72 | Silverside 73 | Other Horsefish 74 | Gulf Pipefish 75 | Dwarf Seahorse 76 | Grouper 77 | Jacks 78 | Pompano 79 | Other Snapper 80 | Gray Snapper 81 | Mojarra 82 | Grunt 83 | Porgy 84 | Pinfish 85 | Scianids 86 | Spotted Seatrout 87 | Red Drum 88 | Spadefish 89 | Parrotfish 90 | Mackerel 91 | Mullet 92 | Barracuda 93 | Blennies 94 | Code Goby 95 | Clown Goby 96 | Flatfish 97 | Filefishes 98 | Puffer 99 | Other Pelagic Fishes 100 | Other Demersal Fishes 101 | Loon 102 | Greeb 103 | Pelican 104 | Comorant 105 | Big Herons & Egrets 106 | Small Herons & Egrets 107 | Ibis 108 | Roseate Spoonbill 109 | Herbivorous Ducks 110 | Omnivorous Ducks 111 | Predatory Ducks 112 | Raptors 113 | Gruiformes 114 | Small Shorebirds 115 | Gulls & Terns 116 | Kingfisher 117 | Crocodiles 118 | Loggerhead Turtle 119 | Green Turtle 120 | Hawksbill Turtle 121 | Dolphin 122 | Manatee 123 | Water POC 124 | Benthic POC 125 | DOC 126 | Input 127 | Output 128 | Respiration 129 | -------------------------------------------------------------------------------- /data/foodweb/node-labels-foodweb.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 1 4 | 1 5 | 1 6 | 1 7 | 1 8 | 1 9 | 1 10 | 1 11 | 1 12 | 1 13 | 1 14 | 1 15 | 1 16 | 1 17 | 1 18 | 2 19 | 2 20 | 2 21 | 2 22 | 2 23 | 2 24 | 2 25 | 2 26 | 2 27 | 2 28 | 2 29 | 2 30 | 2 31 | 2 32 | 2 33 | 2 34 | 2 35 | 2 36 | 2 37 | 2 38 | 2 39 | 2 40 | 2 41 | 2 42 | 2 43 | 2 44 | 2 45 | 2 46 | 2 47 | 2 48 | 2 49 | 2 50 | 2 51 | 2 52 | 2 53 | 3 54 | 3 55 | 3 56 | 3 57 | 3 58 | 3 59 | 3 60 | 3 61 | 3 62 | 3 63 | 3 64 | 3 65 | 3 66 | 3 67 | 3 68 | 3 69 | 3 70 | 3 71 | 3 72 | 3 73 | 3 74 | 3 75 | 3 76 | 3 77 | 3 78 | 3 79 | 3 80 | 3 81 | 3 82 | 3 83 | 3 84 | 3 85 | 3 86 | 3 87 | 3 88 | 3 89 | 3 90 | 3 91 | 3 92 | 3 93 | 3 94 | 3 95 | 3 96 | 3 97 | 3 98 | 3 99 | 3 100 | 3 101 | 3 102 | 3 103 | 3 104 | 3 105 | 3 106 | 3 107 | 3 108 | 3 109 | 3 110 | 3 111 | 3 112 | 3 113 | 3 114 | 3 115 | 3 116 | 3 117 | 3 118 | 3 119 | 3 120 | 3 121 | 3 122 | 3 123 | -------------------------------------------------------------------------------- /data/mag-dual/node-label-identities.txt: -------------------------------------------------------------------------------- 1 | KDD 2 | WWW 3 | ICML 4 | NeurIPS 5 | STOC 6 | FOCS 7 | CVPR 8 | ICCV 9 | VLDB 10 | SIGMOD -------------------------------------------------------------------------------- /data/pubmed/features.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/features.pickle -------------------------------------------------------------------------------- /data/pubmed/hypergraph.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/hypergraph.pickle -------------------------------------------------------------------------------- /data/pubmed/labels.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/labels.pickle -------------------------------------------------------------------------------- /data/pubmed/splits/1.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/splits/1.pickle -------------------------------------------------------------------------------- /data/pubmed/splits/10.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/splits/10.pickle -------------------------------------------------------------------------------- /data/pubmed/splits/2.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/splits/2.pickle -------------------------------------------------------------------------------- /data/pubmed/splits/3.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/splits/3.pickle -------------------------------------------------------------------------------- /data/pubmed/splits/4.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/splits/4.pickle -------------------------------------------------------------------------------- /data/pubmed/splits/5.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/splits/5.pickle -------------------------------------------------------------------------------- /data/pubmed/splits/6.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/splits/6.pickle -------------------------------------------------------------------------------- /data/pubmed/splits/7.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/splits/7.pickle -------------------------------------------------------------------------------- /data/pubmed/splits/8.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/splits/8.pickle -------------------------------------------------------------------------------- /data/pubmed/splits/9.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/COMPiLELab/HyperND/1e5dc49acc9ac31aff443131a6341955a3d64187/data/pubmed/splits/9.pickle -------------------------------------------------------------------------------- /packages.jl: -------------------------------------------------------------------------------- 1 | using Pkg 2 | 3 | dependencies = [ 4 | "Distances", 5 | "LightGraphs", 6 | "PyCall", 7 | "ScikitLearn", 8 | "DataFrames", 9 | "CSV", 10 | "MLDatasets", 11 | "MAT", 12 | "DataStructures", 13 | "StatsBase", 14 | "InvertedIndices", 15 | "Suppressor", 16 | "BSON" 17 | ] 18 | 19 | Pkg.add(dependencies) 20 | Pkg.add(PackageSpec(url="https://github.com/JackDunnNZ/UCIData.jl")) 21 | --------------------------------------------------------------------------------