{"id":39915756,"url":"https://github.com/Raminghorbanii/PATE","last_synced_at":"2026-01-27T05:01:10.996Z","repository":{"id":240730931,"uuid":"802521792","full_name":"Raminghorbanii/PATE","owner":"Raminghorbanii","description":"Official repository for “PATE: Proximity-Aware Time series anomaly Evaluation”.","archived":false,"fork":false,"pushed_at":"2024-12-19T14:12:56.000Z","size":299,"stargazers_count":17,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-11-06T05:23:55.967Z","etag":null,"topics":["anomaly-detection","evaluation","evaluation-metrics","outlier-detection","time-series"],"latest_commit_sha":null,"homepage":"","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/Raminghorbanii.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-18T14:28:01.000Z","updated_at":"2025-11-05T18:07:45.000Z","dependencies_parsed_at":"2024-05-29T14:49:46.862Z","dependency_job_id":"cd496271-f423-4df3-99a0-657c622cf8f9","html_url":"https://github.com/Raminghorbanii/PATE","commit_stats":null,"previous_names":["raminghorbanii/pate"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Raminghorbanii/PATE","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raminghorbanii%2FPATE","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raminghorbanii%2FPATE/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raminghorbanii%2FPATE/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raminghorbanii%2FPATE/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Raminghorbanii","download_url":"https://codeload.github.com/Raminghorbanii/PATE/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raminghorbanii%2FPATE/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28803641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T03:44:14.111Z","status":"ssl_error","status_checked_at":"2026-01-27T03:43:33.507Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["anomaly-detection","evaluation","evaluation-metrics","outlier-detection","time-series"],"created_at":"2026-01-18T17:00:30.377Z","updated_at":"2026-01-27T05:01:10.990Z","avatar_url":"https://github.com/Raminghorbanii.png","language":"Python","funding_links":[],"categories":["2024"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg width=\"300\" src=\"https://raw.githubusercontent.com/Raminghorbanii/PATE/master/docs/PATE_logo.png\"/\u003e\n\u003c/p\u003e\n\n\n\u003ch1 align=\"center\"\u003ePATE: Proximity-Aware Time series anomaly Evaluation\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://kdd.org/kdd2024/\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/ACM%20KDD%202024-Accepted-blue.svg\" alt=\"ACM KDD 2024 Accepted\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://arxiv.org/abs/2405.12096\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Preprint version-Arxiv-green.svg\" alt=\"Preprint Version\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nThis repository contains the code for PATE (Proximity-Aware Time series anomaly Evaluation measure), a novel evaluation metric for assessing anomaly detection in time series data. PATE introduces proximity-based weighting and computes a weighted version of the area under the Precision-Recall curve, offering a more accurate and fair evaluation by considering the temporal relationship between predicted and actual anomalies. The methodology is detailed in our paper, showcasing its effectiveness through experiments with both synthetic and real-world datasets.\n \n\n## Quick Start\n\n### Installation\nInstall PATE for immediate use in your projects:\n\n```bash\npip install PATE\n```\n\n## How to use PATE? \nUtilizing PATE is straightforward. Begin by importing the PATE module in your Python script:\n\n```bash\nfrom pate.PATE_metric import PATE\n```\n\nPrepare your input as arrays of anomaly scores (continues or binary) and binary labels. PATE allows for comprehensive customization of parameters, enabling easy toggling between PATE and PATE-F1 evaluations. Please refer to the main code documentation for a full list of configurable options.\n\nExample usage of PATE and PATE-F1:\n\n```bash\npate = PATE(labels, anomaly_scores, binary_scores = False)\npate_f1 = PATE(labels, binary_anomaly_scores, binary_scores = True)\n```\n\n### Basic Example\n\n```python \nimport numpy as np\nfrom pate.PATE_metric import PATE\n\n# Example data setup\nlabels = np.array([0, 1, 0, 1, 0])\nscores = np.array([0.1, 0.8, 0.1, 0.9, 0.2])\n\n# Initialize PATE and compute the metric\npate = PATE(labels, scores, binary_scores = False)\nprint(pate)\n```\n\n---\n\n## Advanced Setup and Experiments\nFor researchers interested in reproducing the experiments or exploring the evaluation metric further with various data sets:\n\n\n### Environment Setup\nTo use PATE, start by creating and activating a new Conda environment using the following commands:\n\n```bash\nconda create --name pate_env python=3.8\nconda activate pate_env\n```\n\n### Install Dependencies\nInstall the required Python packages via:\n\n```bash\ngit clone https://github.com/raminghorbanii/PATE\ncd PATE\npip install -r synthetic_exp_requirements.txt\n```\n\n## Conducting Experiments\n\n### with Synthetic Data\n\nTo run experiments on synthetic data, navigate to the experiments/Synthetic_Data_Experiments directory and execute the main Python script.\nThis script allows for the modification of various scenarios, comparing PATE and PATE-F1 against other established metrics.\n\n\n```bash\ncd experiments/Synthetic_Data_Experiments\npython main_synthetic_data.py\n```\n\nExample of how you use PATE using synthetic data (Binary detector):\n\n```python\n\nfrom utils_Synthetic_exp import evaluate_all_metrics, synthetic_generator\n\nlabel_anomaly_ranges = [[40,59]] # You can selec multiple ranges for anomaly. Here we selected one range with the size of 20 points (A_k) \npredicted_ranges = [[30, 49]]  # You can selec multiple ranges for predictions. Here we selected the range the same as Scenario 2, proposed in the original paper. \nvus_zone_size = e_buffer = d_buffer = 20 \n\nexperiment_results = synthetic_generator(label_anomaly_ranges, predicted_ranges, vus_zone_size, e_buffer, d_buffer)\npredicted_array = experiment_results[\"predicted_array\"]\nlabel_array = experiment_results[\"label_array\"]\n\n\nscore_list_simple = evaluate_all_metrics(predicted_array, label_array, vus_zone_size, e_buffer, d_buffer)\nprint(score_list_simple)\n\n\n```\n\n\n```bash\n\nOutput:\n\n'original_F1Score': 0.5,\n'pa_precision': 0.67,\n'pa_recall': 1.0,\n'pa_f_score': 0.8,\n'Rbased_precision': 0.6,\n'Rbased_recall': 0.6,\n'Rbased_f1score': 0.6,\n'eTaPR_precision': 0.75,\n'eTaPR_recall': 0.75,\n'eTaPR_f1_score': 0.75,\n'Affiliation precision': 0.97,\n'Affiliation recall': 0.99,\n'Affliation F1score': 0.98,\n'VUS_ROC': 0.79,\n'VUS_PR': 0.72,\n'AUC': 0.74,\n'AUC_PR': 0.51,\n\n'PATE': 0.76,\n'PATE-F1': 0.75}\n\n```\n\n### with Real-World Data\nFor real-world data experiments, ensure all additional required packages are installed.\n\n```bash\npip install -r Real_exp_requirements.txt\n```\n\n#### Download the Dataset\nThe datasets for these experiments can be downloaded from the following link:\n\nDataset Link: https://www.thedatum.org/datasets/TSB-UAD-Public.zip \n\nRef: This dataset is made available through the GitHub page of the project \"An End-to-End Benchmark Suite for Univariate Time-Series Anomaly Detection (TSB-UAD)\": https://github.com/TheDatumOrg/TSB-UAD\n\n#### Running the Experiments\n\nAfter downloading, place the unzipped dataset in the same directory. If you store the data in a different location, ensure you update the directory paths in the code to match.\n\nNavigate to the experiments/RealWorld_Data_Experiments directory to run an experiment. Execute one of the example Python scripts by entering the following command:\n\n```bash\ncd experiments/RealWorld_Data_Experiments\npython Example1.py\n```\nTwo different examples are provided. These examples allow for modifications and customizations, enabling detailed exploration of various data aspects.\n\n\n---\n\n## Setting Buffer Size in PATE\n\nGiven the context of time series data, selecting a buffer size for a fair evaluation of anomaly detectors' performance is unavoidable. The buffer parameter of PATE can be set using the following strategies:\n\n- *Expert Knowledge*: Best suited for customized, specific, and real-world applications where expert knowledge is available, or when one has enough experience with the data at hand. Experts can directly specify buffer sizes that are optimized for the particular use case.\n\n- *ACF Analysis*: Automatically determines the optimal buffer size by analyzing the autocorrelation within the data. This function is available in PATE_utils.py.\n\n- *Range of Buffer Sizes*: PATE is flexible and can evaluate performance across all combinations of pre and post buffer sizes, allowing for a comprehensive assessment without expert input. One can start with a maximum buffer size, and PATE automatically divides it into a specified number of ranges (determined by the user).\n\n- *Default Setting*: Utilizes the input window size of the anomaly detector, a standard, practical buffer size that aligns with the general scale of the data being analyzed. This option is useful when no specific adjustments are needed or when minimal configuration is desired.\n\nThis guidance ensures that you can effectively implement these buffer size selection strategies in PATE for optimal results.\n\n\n---\n\n## Citation\nIf you find our work is useful in your research, please consider raising a star  :star:  and citing:\n\n```\n@article{ghorbani2024pate,\n  title={PATE: Proximity-Aware Time series anomaly Evaluation},\n  author={Ghorbani, Ramin and Reinders, Marcel JT and Tax, David MJ},\n  journal={arXiv preprint arXiv:2405.12096},\n  year={2024}\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRaminghorbanii%2FPATE","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRaminghorbanii%2FPATE","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRaminghorbanii%2FPATE/lists"}