{"id":22229822,"url":"https://github.com/graph-com/neural_higher-order_pattern_prediction","last_synced_at":"2025-07-27T19:32:07.322Z","repository":{"id":43476509,"uuid":"375541795","full_name":"Graph-COM/Neural_Higher-order_Pattern_Prediction","owner":"Graph-COM","description":null,"archived":false,"fork":false,"pushed_at":"2022-03-04T18:42:28.000Z","size":27026,"stargazers_count":13,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T06:51:15.734Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Graph-COM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-10T02:07:17.000Z","updated_at":"2024-11-22T15:08:44.000Z","dependencies_parsed_at":"2022-09-17T17:51:55.044Z","dependency_job_id":null,"html_url":"https://github.com/Graph-COM/Neural_Higher-order_Pattern_Prediction","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Graph-COM/Neural_Higher-order_Pattern_Prediction","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FNeural_Higher-order_Pattern_Prediction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FNeural_Higher-order_Pattern_Prediction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FNeural_Higher-order_Pattern_Prediction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FNeural_Higher-order_Pattern_Prediction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Graph-COM","download_url":"https://codeload.github.com/Graph-COM/Neural_Higher-order_Pattern_Prediction/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FNeural_Higher-order_Pattern_Prediction/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267413763,"owners_count":24083487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T01:12:31.076Z","updated_at":"2025-07-27T19:32:02.313Z","avatar_url":"https://github.com/Graph-COM.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Neural Higher-order Pattern (Motif) Prediction in Temporal Networks\n\n# Overview\nDynamic systems that consist of a set of interacting elements can be abstracted as temporal networks. Recently, higher-order patterns that involve multiple interacting nodes have been found crucial to indicate domain-specific laws of different temporal networks. This posts us the challenge of designing more sophisticated hypergraph models for these higher-order patterns and the associated new learning algorithms. Here, we propose the first model, named HIT, for higher-order pattern prediction in temporal hypergraphs. Particularly, we focus on predicting three types of common but important interaction patterns involving three interacting elements in temporal networks, which could be extended to even higher-order patterns. HIT extracts the structural representation of anode triplet of interest on the temporal hypergraph and uses it to tell what type of, when, and why the interaction expansion could happen in this triplet. HIT could achieve significant improvement (averaged 20% AUC gain to identify the interaction type, uniformly more accurate time estimation) compared to both heuristic and other neural-network-based baselines on 5 real-world large temporal hypergraphs. Moreover, HIT provides a certain degree of interpretability by identifying the most discriminatory structural features on the temporal hypergraphs for predicting different higher-order patterns.\n\n![overview](./image/data2.png)\n\n# Requirements\n* `python = 3.7`, `PyTorch = 1.4`, please refer to their official websites for installation details.\n* Other dependencies:\n```{bash}\npandas==0.24.2\ntqdm==4.41.1\nnumpy==1.16.4\nscikit_learn==0.22.1\nmatploblib==3.3.2\n```\nRefer to `environment.yml` for more details.\n\n# Run the code\n## Preprocess the dataset\n#### Option 1: Use our data\n\nPreprocess dataset\n```{bash}\nmkdir processed\npython preprocess.py -d tags-ask-ubuntu\n```\n\nThis code is to preprocess the dataset, including zero-padding the node features and edge features.\n\n#### Option 2: Use your own data\nFirst download the dataset, for example https://www.cs.cornell.edu/~arb/data/\n```{bash}\nunzip dataset.zip\nmkdir processed\npython preprocess.py -d \u003cdataset\u003e\n```\n\nBefore running the code, check if ./log exists. If not, \n\n```{bash}\nmkdir log\n```\n\nWe also prepare the threads-ask-ubuntu dataset for the demo(about 500MB), which can be found [here](https://drive.google.com/file/d/1DIi85QTdmTwOMPtoYYDdFNE9fx8pOCtx/view?usp=sharing). After download the dataset, moved the triplet.npy to the folder ./saved_triplets/threads-ask-ubuntu/threads-ask-ubuntu_0.4_0.1/ . Then you can run the code with the following tasks, e.g.,\n```{bash}\npython main.py -d threads-ask-ubuntu\n```\n\ntriplet.npy should contains all different closures, triangles, wedges and edges given t and T_W. However, it will be too large to save them all. Thus we only choose part of them and trained our model based on the sampling datasets. Based on the experiment, this will not affect the performance too much. More detailed information regarding how we sample the data can be found in cut_dataset.py .\n\nAfter preprocessing the dataset, we can run the code for three different questions.\n## For Q1 type prediction\nThe task aims to solve the Q1 in the paper. What type of high-order interaction will most likely appear among u,v,w within (t, t + T_W]?\n\n```{bash}\nexport OMP_NUM_THREADS=1\npython main.py -d tags-ask-ubuntu\n```\n\nThe output will be in the log file. We will both report the AUC and the confusion matrix.\n\n## For Q2 time prediction\nThe task aims to solve the Q2 in the paper. For a triplet ({u, v}, w, t), given an interaction pattern in {Wedge, Triangle, Closure}, when will u, v, w first form such\na pattern?\n\n```{bash}\nexport OMP_NUM_THREADS=1\nmkdir time_prediction_output\npython main.py -d tags-ask-ubuntu --time_prediction --time_prediction_type \u003ctime_prediction_type\u003e\n```\n## Optional arguments\n```{txt}\n    --time_prediction_type For interpretation, we have 3 tasks. 1: Closure; 2: Triangle; 3: Wedge;  Default 0 means no time_prediction\n```\n\nThe output will be in the ./time_prediction_output/ \u003cdataset\u003e_\u003ctime_prediction_type\u003e.txt.\nWe report the NLL loss and MSE for training, validating, and testing sets.\n\n\n## For Q3 interpretation\n```{bash}\nexport OMP_NUM_THREADS=1\nmkdir interpretation_output\npython main.py -d tags-ask-ubuntu --interpretation --interpretation_type 1\n```\n\n## Optional arguments\n```{txt}\n    --interpretation_type: Interpretation type: For interpretation, we have 3 tasks. 1: Closure vs Triangle; 2: Closure + Triangle vs Wedge; 3: Wedge and Edge; Default 0 means no interpretation\n```\nThe output will be in the ./interpretation_output/ \u003cdataset\u003e_\u003cinterpretation_type\u003e.txt.\nWe report all the pattern we sample, with the times of each pattern appears in the first class and the total times it appears in both classes, and their ratio. We also report the mean score and variance of each pattern.\n\n\n# Note\n\nFinding edges, wedges, triangles, and closures process is in th utils.py. Since the finding process is time-consuming, the code will automatically save all the edges, wedges, triangles, closures in the saved_triplets. So the code doesn't need to run the process again in the future experiments.\n\n# Some Results\n\n## What type of interaction between w and u,v will appear if there is any? \n\nOur model achieves the following performance. The performance is 1-vs-1 AUC (mean±std) of higher-order pattern prediction.\n\n| Model name         |     tags-math-sx    |  tags-ask-ubuntu  |   congress-bills   |       DAWN       |   threads-ask-ubuntu  |\n| ------------------ | ------------------- | ----------------- | ------------------ | ---------------- | --------------------- |\n| HIT                |     74.07 ± 0.46    |    78.83 ± 0.43   |    79.83 ± 0.61    |   78.92 ± 0.61   |      84.22 ± 0.68     |\n\n## When will such a type of interaction appear?\n\nAll the baselines share the same maximum-likelihood decoder for Q2 as HIT defined in Sec.4.2. We use NLL (Eq.5) as the evaluating metrics, which is superior in evaluating how different models learn the underlying distributions of the time.\n\n![when](./image/when.png)\n\n## Why will such a type of interaction appear?\n\nOur model indicates that Closures are more likely to happen than Triangles when the temporal random walks(TRWs) start from u,v (or w) and jump to some nodes that are directly connected to w (or u,v).  This means that u, v, w tend to form a Closure pattern if both u,w and v,w have common neighbors before.\n\nCompared with Closures and Triangles, Wedges are more likely to occur when the TRWs start from u (or v,w) and jump to some nodes that are still far away from the other two nodes\n\nIf u and v have strong connections, i.e., the TRWs jump around u and v, they are more likely to become an Edge instread of a Wedge.\n\n![how](./image/how.png)\n\n# Main code and functions\n    \n## preprocess.py\nthe preprocess of data. Transform the hypergraph to the graph.\n\n## main.py \nthe main code, including finding patterns and train/validate/test the model.\n\n## train.py\nthe main training code.\n\n## module.py\ndifferent modules, including the HIT class, classifiers, self-attention pooling, and sum pooling.\n\n## utils.py\nfunctions, including early stopper, ROC score function, and Dataset class.\n    \n## find_pattern.py\nprepare for the HIT model, finding high-order patterns \n\n## parser.py\nparsers\n\n# Citation\nPlease cite our paper if you like or use our work for your research, thank you very much!\n```\n@inproceedings{liu2021neural,\n  title={Neural Predicting Higher-order Patterns in Temporal Networks},\n  author={Liu, Yunyu and Ma, Jianzhu and Li, Pan},\n  booktitle={WWW},\n  year={2022}\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraph-com%2Fneural_higher-order_pattern_prediction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraph-com%2Fneural_higher-order_pattern_prediction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraph-com%2Fneural_higher-order_pattern_prediction/lists"}