pidsmaker 5.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pidsmaker/__init__.py +1 -0
- pidsmaker/cli.py +81 -0
- pidsmaker/config/__init__.py +2 -0
- pidsmaker/config/config.py +2100 -0
- pidsmaker/config/pipeline.py +1824 -0
- pidsmaker/config/schemas.py +1032 -0
- pidsmaker/datasets.py +323 -0
- pidsmaker/debug_tests.py +30 -0
- pidsmaker/decoders/__init__.py +5 -0
- pidsmaker/decoders/custom_edge_mlp_decoder.py +17 -0
- pidsmaker/decoders/custom_mlp_decoder.py +10 -0
- pidsmaker/decoders/edge_linear_decoder.py +16 -0
- pidsmaker/decoders/inner_product_decoder.py +18 -0
- pidsmaker/decoders/nodlink_decoder.py +56 -0
- pidsmaker/detection/__init__.py +0 -0
- pidsmaker/detection/evaluation_methods/__init__.py +9 -0
- pidsmaker/detection/evaluation_methods/edge_evaluation.py +255 -0
- pidsmaker/detection/evaluation_methods/evaluation_utils.py +1788 -0
- pidsmaker/detection/evaluation_methods/host_two_stage_evaluation.py +115 -0
- pidsmaker/detection/evaluation_methods/node_evaluation.py +459 -0
- pidsmaker/detection/evaluation_methods/node_tw_evaluation.py +196 -0
- pidsmaker/detection/evaluation_methods/plot.py +192 -0
- pidsmaker/detection/evaluation_methods/queue_evaluation.py +456 -0
- pidsmaker/detection/evaluation_methods/tw_evaluation.py +93 -0
- pidsmaker/detection/flash_detection.py +162 -0
- pidsmaker/detection/magic_knn.py +190 -0
- pidsmaker/detection/node_scoring.py +52 -0
- pidsmaker/detection/threatrace_detection.py +65 -0
- pidsmaker/detection/training_methods/__init__.py +1 -0
- pidsmaker/detection/training_methods/inference_loop.py +287 -0
- pidsmaker/detection/training_methods/ocrapt_early_stop.py +165 -0
- pidsmaker/detection/training_methods/threatrace_training.py +168 -0
- pidsmaker/detection/training_methods/training_loop.py +383 -0
- pidsmaker/encoders/__init__.py +22 -0
- pidsmaker/encoders/argus_encoder.py +69 -0
- pidsmaker/encoders/custom_mlp.py +75 -0
- pidsmaker/encoders/custom_mlp_encoder.py +10 -0
- pidsmaker/encoders/egraphsage_encoder.py +56 -0
- pidsmaker/encoders/gat.py +67 -0
- pidsmaker/encoders/gcn.py +27 -0
- pidsmaker/encoders/gin.py +48 -0
- pidsmaker/encoders/glstm.py +298 -0
- pidsmaker/encoders/graph_attention.py +63 -0
- pidsmaker/encoders/gru.py +29 -0
- pidsmaker/encoders/hetero/__init__.py +4 -0
- pidsmaker/encoders/hetero/ancestor_encoder.py +98 -0
- pidsmaker/encoders/hetero/entity_encoder.py +33 -0
- pidsmaker/encoders/hetero/event_encoder.py +81 -0
- pidsmaker/encoders/hetero/hetero_graph_transformer.py +40 -0
- pidsmaker/encoders/lares_encoder.py +68 -0
- pidsmaker/encoders/linear_encoder.py +16 -0
- pidsmaker/encoders/magic_encoder.py +161 -0
- pidsmaker/encoders/rcaid_encoder.py +81 -0
- pidsmaker/encoders/rgcn.py +75 -0
- pidsmaker/encoders/sage.py +51 -0
- pidsmaker/encoders/shadewatcher_encoder.py +149 -0
- pidsmaker/encoders/sum_aggregation.py +20 -0
- pidsmaker/encoders/temporal_wrappers.py +80 -0
- pidsmaker/encoders/textrcnn.py +82 -0
- pidsmaker/encoders/tgn_encoder.py +193 -0
- pidsmaker/experiments/tuning.py +102 -0
- pidsmaker/experiments/uncertainty.py +261 -0
- pidsmaker/factory.py +1456 -0
- pidsmaker/featurization/__init__.py +0 -0
- pidsmaker/featurization/feat_inference_methods/__init__.py +7 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_HFH.py +30 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_TRW.py +65 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_alacarte.py +14 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_doc2vec.py +53 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_fasttext.py +37 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_flash.py +69 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_graph2vec.py +84 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_ocrapt_features.py +95 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_pretrained.py +1728 -0
- pidsmaker/featurization/feat_inference_methods/feat_inference_word2vec.py +55 -0
- pidsmaker/featurization/featurization_methods/__init__.py +0 -0
- pidsmaker/featurization/featurization_methods/build_trw.py +66 -0
- pidsmaker/featurization/featurization_methods/featurization_alacarte.py +747 -0
- pidsmaker/featurization/featurization_methods/featurization_doc2vec.py +98 -0
- pidsmaker/featurization/featurization_methods/featurization_fasttext.py +74 -0
- pidsmaker/featurization/featurization_methods/featurization_flash.py +201 -0
- pidsmaker/featurization/featurization_methods/featurization_graph2vec.py +242 -0
- pidsmaker/featurization/featurization_methods/featurization_trw.py +114 -0
- pidsmaker/featurization/featurization_methods/featurization_word2vec.py +89 -0
- pidsmaker/featurization/featurization_utils.py +275 -0
- pidsmaker/featurization/utils/build_random_walks.py +66 -0
- pidsmaker/featurization/utils/trw.py +203 -0
- pidsmaker/hetero.py +81 -0
- pidsmaker/losses.py +170 -0
- pidsmaker/main.py +478 -0
- pidsmaker/mimicry.py +284 -0
- pidsmaker/model.py +382 -0
- pidsmaker/objectives/__init__.py +16 -0
- pidsmaker/objectives/autoencode_edge_emb.py +43 -0
- pidsmaker/objectives/deep_graph_infomax.py +94 -0
- pidsmaker/objectives/detect_few_shot.py +21 -0
- pidsmaker/objectives/one_class.py +75 -0
- pidsmaker/objectives/predict_edge_contrastive.py +165 -0
- pidsmaker/objectives/predict_edge_supervised.py +77 -0
- pidsmaker/objectives/predict_edge_type.py +28 -0
- pidsmaker/objectives/predict_masked_struct.py +49 -0
- pidsmaker/objectives/predict_node_type.py +36 -0
- pidsmaker/objectives/predict_process_tag.py +169 -0
- pidsmaker/objectives/predict_snapshot_embedding.py +97 -0
- pidsmaker/objectives/reconstruct_edge_emb.py +16 -0
- pidsmaker/objectives/reconstruct_masked_feat.py +51 -0
- pidsmaker/objectives/reconstruct_node_emb.py +13 -0
- pidsmaker/objectives/reconstruct_node_feat.py +13 -0
- pidsmaker/objectives/validation_wrapper.py +55 -0
- pidsmaker/preprocessing/__init__.py +0 -0
- pidsmaker/preprocessing/build_graph_methods/__init__.py +1 -0
- pidsmaker/preprocessing/build_graph_methods/build_default_graphs.py +825 -0
- pidsmaker/preprocessing/build_graph_methods/build_magic_graphs.py +216 -0
- pidsmaker/preprocessing/cleaning.py +258 -0
- pidsmaker/preprocessing/transformation_methods/__init__.py +2 -0
- pidsmaker/preprocessing/transformation_methods/attack_generation/synthetic_attack_naive.py +194 -0
- pidsmaker/preprocessing/transformation_methods/transformation_dag.py +28 -0
- pidsmaker/preprocessing/transformation_methods/transformation_merge_edges.py +136 -0
- pidsmaker/preprocessing/transformation_methods/transformation_rcaid_pseudo_graph.py +510 -0
- pidsmaker/preprocessing/transformation_methods/transformation_undirected.py +24 -0
- pidsmaker/preprocessing/transformation_methods/transformation_utils.py +36 -0
- pidsmaker/pretrained/__init__.py +5 -0
- pidsmaker/pretrained/data/__init__.py +4 -0
- pidsmaker/pretrained/data/behavior_signatures.py +548 -0
- pidsmaker/pretrained/data/canonical_tokens.py +1035 -0
- pidsmaker/pretrained/data/edge_filter.py +381 -0
- pidsmaker/pretrained/data/entity_classes.py +476 -0
- pidsmaker/pretrained/data/sampler.py +926 -0
- pidsmaker/pretrained/data/tokenizer_bpe.py +1659 -0
- pidsmaker/pretrained/detect.py +1427 -0
- pidsmaker/pretrained/embedding_generator.py +252 -0
- pidsmaker/pretrained/finetune.py +1434 -0
- pidsmaker/pretrained/models/__init__.py +20 -0
- pidsmaker/pretrained/models/behavior.py +348 -0
- pidsmaker/pretrained/models/bert.py +286 -0
- pidsmaker/pretrained/models/deepwalk.py +128 -0
- pidsmaker/pretrained/models/dgi.py +120 -0
- pidsmaker/pretrained/models/gae.py +114 -0
- pidsmaker/pretrained/models/gnn_distill.py +475 -0
- pidsmaker/pretrained/models/graphmae.py +373 -0
- pidsmaker/pretrained/models/hf_pretrained.py +213 -0
- pidsmaker/pretrained/models/llama.py +110 -0
- pidsmaker/pretrained/models/modernbert.py +567 -0
- pidsmaker/pretrained/models/roberta.py +147 -0
- pidsmaker/pretrained/models/rope_utils.py +99 -0
- pidsmaker/pretrained/models/ropebert.py +322 -0
- pidsmaker/pretrained/models/spider.py +204 -0
- pidsmaker/pretrained/models/tgn.py +770 -0
- pidsmaker/pretrained/pretrain/__init__.py +3 -0
- pidsmaker/pretrained/pretrain/pretrain_behavior_cluster.py +513 -0
- pidsmaker/pretrained/pretrain/pretrain_common.py +585 -0
- pidsmaker/pretrained/pretrain/pretrain_deepwalk.py +31 -0
- pidsmaker/pretrained/pretrain/pretrain_dgi.py +143 -0
- pidsmaker/pretrained/pretrain/pretrain_gae.py +143 -0
- pidsmaker/pretrained/pretrain/pretrain_gnn_distill.py +438 -0
- pidsmaker/pretrained/pretrain/pretrain_graphmae.py +151 -0
- pidsmaker/pretrained/pretrain/pretrain_hf.py +169 -0
- pidsmaker/pretrained/pretrain/pretrain_main.py +275 -0
- pidsmaker/pretrained/pretrain/pretrain_mlm.py +491 -0
- pidsmaker/pretrained/pretrain/pretrain_spider.py +502 -0
- pidsmaker/pretrained/training_utils.py +157 -0
- pidsmaker/process_reapr_gt.py +101 -0
- pidsmaker/resources/config/anomal_e.yml +25 -0
- pidsmaker/resources/config/argus.yml +56 -0
- pidsmaker/resources/config/attack_edges/cadets_e3.yml +435 -0
- pidsmaker/resources/config/attack_edges/cadets_e5.yml +407 -0
- pidsmaker/resources/config/attack_edges/theia_e3.yml +382 -0
- pidsmaker/resources/config/attack_edges/theia_e5.yml +387 -0
- pidsmaker/resources/config/attack_edges/trace_e3.yml +415 -0
- pidsmaker/resources/config/attack_edges/trace_e5.yml +417 -0
- pidsmaker/resources/config/default.yml +315 -0
- pidsmaker/resources/config/egraphsage.yml +95 -0
- pidsmaker/resources/config/euler.yml +104 -0
- pidsmaker/resources/config/eval/eval_set_clustering.json +3170 -0
- pidsmaker/resources/config/experiments/tuning/components/tuning_featurization_methods.yml +29 -0
- pidsmaker/resources/config/experiments/tuning/systems/clearscope_e5/tuning_orthrus.yml +14 -0
- pidsmaker/resources/config/experiments/tuning/systems/default/tuning_default_baselines.yml +13 -0
- pidsmaker/resources/config/experiments/tuning/systems/default/tuning_orthrus_fixed.yml +16 -0
- pidsmaker/resources/config/experiments/uncertainty/none.yml +5 -0
- pidsmaker/resources/config/experiments/uncertainty/run_n_times.yml +12 -0
- pidsmaker/resources/config/experiments/uncertainty/run_n_times_hyperparameters.yml +12 -0
- pidsmaker/resources/config/experiments/uncertainty/uncertainty.yml +22 -0
- pidsmaker/resources/config/flash.yml +79 -0
- pidsmaker/resources/config/jbeil.yml +65 -0
- pidsmaker/resources/config/kairos.yml +121 -0
- pidsmaker/resources/config/lares.yml +115 -0
- pidsmaker/resources/config/magic.yml +86 -0
- pidsmaker/resources/config/nodlink.yml +79 -0
- pidsmaker/resources/config/ocrapt.yml +91 -0
- pidsmaker/resources/config/orthrus.yml +126 -0
- pidsmaker/resources/config/orthrus_fixed.yml +17 -0
- pidsmaker/resources/config/pretrained/README.md +101 -0
- pidsmaker/resources/config/pretrained/cybergfm/cybergfm.yml +49 -0
- pidsmaker/resources/config/pretrained/pretrained.yml +190 -0
- pidsmaker/resources/config/pretrained/pretrained_flash.yml +9 -0
- pidsmaker/resources/config/pretrained/pretrained_kairos.yml +12 -0
- pidsmaker/resources/config/pretrained/pretrained_magic.yml +1 -0
- pidsmaker/resources/config/pretrained/pretrained_nodlink.yml +1 -0
- pidsmaker/resources/config/pretrained/pretrained_orthrus.yml +1 -0
- pidsmaker/resources/config/pretrained/pretrained_supervised.yml +13 -0
- pidsmaker/resources/config/pretrained/pretrained_threatrace.yml +8 -0
- pidsmaker/resources/config/pretrained/pretrained_velox.yml +14 -0
- pidsmaker/resources/config/prographer.yml +136 -0
- pidsmaker/resources/config/rcaid.yml +88 -0
- pidsmaker/resources/config/shadewatcher.yml +146 -0
- pidsmaker/resources/config/tests.yml +10 -0
- pidsmaker/resources/config/threatrace.yml +73 -0
- pidsmaker/resources/config/tuned_baselines/optc_net/tuned_argus.yml +4 -0
- pidsmaker/resources/config/tuned_baselines/optc_net/tuned_lares.yml +13 -0
- pidsmaker/resources/config/velox.yml +10 -0
- pidsmaker/resources/config/viz_config.yml +10 -0
- pidsmaker/resources/ground_truth/orthrus/E3-CADETS/node_Nginx_Backdoor_06.csv +8 -0
- pidsmaker/resources/ground_truth/orthrus/E3-CADETS/node_Nginx_Backdoor_11.csv +4 -0
- pidsmaker/resources/ground_truth/orthrus/E3-CADETS/node_Nginx_Backdoor_12.csv +43 -0
- pidsmaker/resources/ground_truth/orthrus/E3-CADETS/node_Nginx_Backdoor_13.csv +24 -0
- pidsmaker/resources/ground_truth/orthrus/E3-CLEARSCOPE/node_clearscope_e3_firefox_0411.csv +41 -0
- pidsmaker/resources/ground_truth/orthrus/E3-CLEARSCOPE/node_clearscope_e3_firefox_0412.csv +0 -0
- pidsmaker/resources/ground_truth/orthrus/E3-FIVEDIRECTIONS/node_fivedirections_e3_browser_0412.csv +1 -0
- pidsmaker/resources/ground_truth/orthrus/E3-FIVEDIRECTIONS/node_fivedirections_e3_excel_0409.csv +63 -0
- pidsmaker/resources/ground_truth/orthrus/E3-FIVEDIRECTIONS/node_fivedirections_e3_firefox_0411.csv +56 -0
- pidsmaker/resources/ground_truth/orthrus/E3-THEIA/node_Browser_Extension_Drakon_Dropper.csv +61 -0
- pidsmaker/resources/ground_truth/orthrus/E3-THEIA/node_Firefox_Backdoor_Drakon_In_Memory.csv +58 -0
- pidsmaker/resources/ground_truth/orthrus/E3-TRACE/node_trace_e3_firefox_0410.csv +11 -0
- pidsmaker/resources/ground_truth/orthrus/E3-TRACE/node_trace_e3_phishing_executable_0413.csv +11 -0
- pidsmaker/resources/ground_truth/orthrus/E3-TRACE/node_trace_e3_pine_0413.csv +14 -0
- pidsmaker/resources/ground_truth/orthrus/E5-CADETS/node_Nginx_Drakon_APT.csv +19 -0
- pidsmaker/resources/ground_truth/orthrus/E5-CADETS/node_Nginx_Drakon_APT_17.csv +107 -0
- pidsmaker/resources/ground_truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_appstarter_0515.csv +26 -0
- pidsmaker/resources/ground_truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_firefox_0517.csv +1 -0
- pidsmaker/resources/ground_truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_lockwatch_0517.csv +17 -0
- pidsmaker/resources/ground_truth/orthrus/E5-CLEARSCOPE/node_clearscope_e5_tester_0517.csv +8 -0
- pidsmaker/resources/ground_truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_bits_0515.csv +54 -0
- pidsmaker/resources/ground_truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_copykatz_0509.csv +87 -0
- pidsmaker/resources/ground_truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_dns_0517.csv +11 -0
- pidsmaker/resources/ground_truth/orthrus/E5-FIVEDIRECTIONS/node_fivedirections_e5_drakon_0517.csv +6 -0
- pidsmaker/resources/ground_truth/orthrus/E5-THEIA/node_THEIA_1_Firefox_Drakon_APT_BinFmt_Elevate_Inject.csv +70 -0
- pidsmaker/resources/ground_truth/orthrus/E5-TRACE/node_Trace_Firefox_Drakon.csv +71 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_edr/atlasv2_edr_m1.csv +1 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_edr/atlasv2_edr_m2.csv +1 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_edr/atlasv2_edr_m3.csv +1 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_edr/atlasv2_edr_m4.csv +5 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_edr/atlasv2_edr_m5.csv +23 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_edr/atlasv2_edr_m6.csv +18 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_edr/atlasv2_edr_s1.csv +1 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_edr/atlasv2_edr_s2.csv +1 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_edr/atlasv2_edr_s3.csv +16 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_edr/atlasv2_edr_s4.csv +22 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_h1/node_h1_m1.csv +126 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_h1/node_h1_m2.csv +105 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_h1/node_h1_m3.csv +94 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_h1/node_h1_m4.csv +139 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_h1/node_h1_m5.csv +228 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_h1/node_h1_m6.csv +131 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_h1/node_h1_s1.csv +118 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_h1/node_h1_s2.csv +89 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_h1/node_h1_s3.csv +133 -0
- pidsmaker/resources/ground_truth/orthrus/atlasv2_h1/node_h1_s4.csv +135 -0
- pidsmaker/resources/ground_truth/orthrus/carbanakv2_edr/carbanakv2_edr.csv +2453 -0
- pidsmaker/resources/ground_truth/orthrus/h051/node_h051_0925.csv +114 -0
- pidsmaker/resources/ground_truth/orthrus/h201/node_h201_0923.csv +2905 -0
- pidsmaker/resources/ground_truth/orthrus/h501/node_h501_0924.csv +749 -0
- pidsmaker/resources/ground_truth/orthrus/readme.md +98 -0
- pidsmaker/resources/ground_truth/reapr/E3-CADETS/node_Nginx_Backdoor_06.csv +3 -0
- pidsmaker/resources/ground_truth/reapr/E3-CADETS/node_Nginx_Backdoor_12.csv +655 -0
- pidsmaker/resources/ground_truth/reapr/E3-CADETS/node_Nginx_Backdoor_13.csv +770 -0
- pidsmaker/resources/ground_truth/reapr/E3-FIVEDIRECTIONS/node_fivedirections_e3_excel_0409.csv +0 -0
- pidsmaker/resources/ground_truth/reapr/E3-FIVEDIRECTIONS/node_fivedirections_e3_firefox_0411.csv +18 -0
- pidsmaker/resources/ground_truth/reapr/E3-THEIA/node_Browser_Extension_Drakon_Dropper.csv +42 -0
- pidsmaker/resources/ground_truth/reapr/E3-THEIA/node_Firefox_Backdoor_Drakon_In_Memory.csv +81 -0
- pidsmaker/resources/ground_truth/reapr/E3-TRACE/node_trace_e3_firefox_0410.csv +37 -0
- pidsmaker/resources/ground_truth/reapr/E3-TRACE/node_trace_e3_phishing_executable_0413.csv +9 -0
- pidsmaker/resources/ground_truth/reapr/E3-TRACE/node_trace_e3_pine_0413.csv +40 -0
- pidsmaker/resources/ground_truth/threatrace/E3-CADETS/ground_truth.txt +12858 -0
- pidsmaker/resources/ground_truth/threatrace/E3-FIVEDIRECTIONS/ground_truth.txt +18420 -0
- pidsmaker/resources/ground_truth/threatrace/E3-THEIA/ground_truth.txt +25363 -0
- pidsmaker/resources/ground_truth/threatrace/E3-TRACE/ground_truth.txt +68265 -0
- pidsmaker/resources/ground_truth/threatrace/README.md +123 -0
- pidsmaker/tasks/__init__.py +10 -0
- pidsmaker/tasks/batching.py +47 -0
- pidsmaker/tasks/construction.py +31 -0
- pidsmaker/tasks/evaluation.py +241 -0
- pidsmaker/tasks/feat_inference.py +413 -0
- pidsmaker/tasks/featurization.py +43 -0
- pidsmaker/tasks/training.py +17 -0
- pidsmaker/tasks/transformation.py +306 -0
- pidsmaker/tasks/triage.py +143 -0
- pidsmaker/tgn.py +635 -0
- pidsmaker/tokenization/__init__.py +112 -0
- pidsmaker/tokenization/base.py +58 -0
- pidsmaker/tokenization/bpe_tokenizer.py +83 -0
- pidsmaker/tokenization/hf_tokenizer.py +61 -0
- pidsmaker/tokenization/hierarchical_tokenizer.py +44 -0
- pidsmaker/tokenization/label_tokenizer.py +24 -0
- pidsmaker/tokenization/nltk_tokenizer.py +84 -0
- pidsmaker/tokenization/substitution.py +295 -0
- pidsmaker/triage/__init__.py +0 -0
- pidsmaker/triage/tracing_methods/__init__.py +1 -0
- pidsmaker/triage/tracing_methods/depimpact.py +213 -0
- pidsmaker/triage/tracing_methods/depimpact_utils.py +537 -0
- pidsmaker/triage/tracing_methods/ocrapt_subgraph.py +267 -0
- pidsmaker/utils/__init__.py +0 -0
- pidsmaker/utils/cache_utils.py +256 -0
- pidsmaker/utils/console.py +282 -0
- pidsmaker/utils/data_utils.py +1742 -0
- pidsmaker/utils/database.py +150 -0
- pidsmaker/utils/dataset_utils.py +413 -0
- pidsmaker/utils/dataset_writer.py +570 -0
- pidsmaker/utils/graph_store.py +634 -0
- pidsmaker/utils/labelling.py +445 -0
- pidsmaker/utils/loss_files.py +193 -0
- pidsmaker/utils/process_tags.py +44 -0
- pidsmaker/utils/utils.py +712 -0
- pidsmaker/vizgen/__init__.py +1 -0
- pidsmaker/vizgen/backfill_manifests.py +100 -0
- pidsmaker/vizgen/dimensionality_reduction.py +249 -0
- pidsmaker/vizgen/embed_exporter.py +467 -0
- pidsmaker/vizgen/exporter.py +493 -0
- pidsmaker/vizgen/html_builder.py +936 -0
- pidsmaker/vizgen/web/__init__.py +1 -0
- pidsmaker/vizgen/web/export.py +62 -0
- pidsmaker/vizgen/web/static/css/app.css +250 -0
- pidsmaker/vizgen/web/static/index.html +182 -0
- pidsmaker/vizgen/web/static/js/app.js +627 -0
- pidsmaker/vizgen/web/static/js/campaign.js +123 -0
- pidsmaker/vizgen/web/static/js/data.js +119 -0
- pidsmaker/vizgen/web/static/js/dialogs.js +240 -0
- pidsmaker/vizgen/web/static/js/jobs.js +75 -0
- pidsmaker/vizgen/web/static/js/scene.js +651 -0
- pidsmaker/vizgen/web/static/js/ui.js +370 -0
- pidsmaker/vizgen/web/static/vendor/OrbitControls.js +1045 -0
- pidsmaker/vizgen/web/static/vendor/d3.v4.min.js +2 -0
- pidsmaker/vizgen/web/static/vendor/three.min.js +6 -0
- pidsmaker/vizgen/web/viz_server.py +2176 -0
- pidsmaker-5.0.0.dist-info/METADATA +597 -0
- pidsmaker-5.0.0.dist-info/RECORD +339 -0
- pidsmaker-5.0.0.dist-info/WHEEL +5 -0
- pidsmaker-5.0.0.dist-info/entry_points.txt +2 -0
- pidsmaker-5.0.0.dist-info/licenses/LICENSE +201 -0
- pidsmaker-5.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# ThreaTrace Ground Truth
|
|
2
|
+
|
|
3
|
+
Ground truth as published by **ThreaTrace** (`github.com/threaTrace-detector/threaTrace`,
|
|
4
|
+
`groundtruth/*.txt`), provided here as an alternative to the `orthrus` and `reapr`
|
|
5
|
+
ground truths. Select it with `--evaluation.ground_truth_version threatrace` on
|
|
6
|
+
the CLI (or `evaluation.ground_truth_version: threatrace` in a YAML config).
|
|
7
|
+
|
|
8
|
+
## Datasets
|
|
9
|
+
|
|
10
|
+
| Dataset | File | Unique nodes | Lines |
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
| CADETS_E3 | `E3-CADETS/ground_truth.txt` | 12,858 | 12,858 |
|
|
13
|
+
| THEIA_E3 | `E3-THEIA/ground_truth.txt` | 25,358 | 25,363 |
|
|
14
|
+
| TRACE_E3 | `E3-TRACE/ground_truth.txt` | 68,172 | 68,265 |
|
|
15
|
+
| FIVEDIRECTIONS_E3 | `E3-FIVEDIRECTIONS/ground_truth.txt` | 762 | 18,420 |
|
|
16
|
+
|
|
17
|
+
The upstream files (all DARPA TC E3) contain duplicate lines; FIVEDIRECTIONS in
|
|
18
|
+
particular is 18,420 lines but only 762 unique UUIDs. The loader deduplicates.
|
|
19
|
+
|
|
20
|
+
ThreaTrace only releases ground truth for these four E3 datasets. CLEARSCOPE (E3) and
|
|
21
|
+
all E5 datasets have no ThreaTrace ground truth and must use `orthrus`/`reapr`.
|
|
22
|
+
|
|
23
|
+
## Format
|
|
24
|
+
|
|
25
|
+
A single flat list of node UUIDs, one per line — no labels, no per-attack split, no
|
|
26
|
+
time windows:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
9EF37E2E-3E80-11E8-A5CB-3FA3753A265A
|
|
30
|
+
A4DD7C60-3E80-11E8-A5CB-3FA3753A265A
|
|
31
|
+
...
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This differs from `orthrus`/`reapr`, which provide one CSV per attack
|
|
35
|
+
(`uuid, label, node_id`) with an explicit time window per attack.
|
|
36
|
+
|
|
37
|
+
## Labeling philosophy vs. orthrus
|
|
38
|
+
|
|
39
|
+
ThreaTrace labels the **entire attack neighborhood**, whereas `orthrus` labels only the
|
|
40
|
+
precise attack-chain nodes. The two are an order of magnitude apart and overlap little:
|
|
41
|
+
|
|
42
|
+
| Dataset | orthrus attack nodes | ThreaTrace nodes | orthrus ∩ ThreaTrace | ThreaTrace-only |
|
|
43
|
+
|---|---|---|---|---|
|
|
44
|
+
| CADETS_E3 | 76 (4 attacks) | 12,858 | 21 (28%) | 12,837 |
|
|
45
|
+
| THEIA_E3 | 118 (2 attacks) | 25,358 | 25 (21%) | 25,333 |
|
|
46
|
+
|
|
47
|
+
Per orthrus attack, the fraction whose nodes appear in the ThreaTrace ground truth:
|
|
48
|
+
|
|
49
|
+
| Dataset | attack (day) | orthrus nodes | in ThreaTrace |
|
|
50
|
+
|---|---|---|---|
|
|
51
|
+
| CADETS_E3 | Nginx_Backdoor (04-06) | 8 | 0% |
|
|
52
|
+
| CADETS_E3 | Nginx_Backdoor (04-11)¹ | 4 | 0% |
|
|
53
|
+
| CADETS_E3 | Nginx_Backdoor (04-12) | 43 | 44% |
|
|
54
|
+
| CADETS_E3 | Nginx_Backdoor (04-13) | 24 | 17% |
|
|
55
|
+
| THEIA_E3 | Browser_Extension_Drakon (04-12) | 61 | 18% |
|
|
56
|
+
| THEIA_E3 | Firefox_Backdoor_Drakon (04-10) | 58 | 26% |
|
|
57
|
+
|
|
58
|
+
¹ Commented out in the dataset config (not used by velox). THEIA's two phishing attacks
|
|
59
|
+
are likewise commented out (one failed, one is network-only).
|
|
60
|
+
|
|
61
|
+
The 04-06 and 04-11 CADETS attacks have **no** overlap with the ThreaTrace ground truth
|
|
62
|
+
at the node level; ThreaTrace instead contributes ~12–25k additional
|
|
63
|
+
neighborhood nodes not present in orthrus.
|
|
64
|
+
|
|
65
|
+
## How velox consumes it
|
|
66
|
+
|
|
67
|
+
ThreaTrace has no per-attack split, so it is loaded as a **single combined attack** over
|
|
68
|
+
the dataset's full test period (`test_dates` → one `[start, end]` window). UUIDs absent
|
|
69
|
+
from the constructed graph are skipped and counted in the log. Loading is otherwise
|
|
70
|
+
transparent to the pipeline (`pidsmaker/utils/labelling.py`).
|
|
71
|
+
|
|
72
|
+
Mapped node counts (nodes whose UUID exists in the constructed graph):
|
|
73
|
+
|
|
74
|
+
| Dataset | Unique UUIDs | Mapped to graph | Absent |
|
|
75
|
+
|---|---|---|---|
|
|
76
|
+
| CADETS_E3 | 12,858 | 12,851 | 7 |
|
|
77
|
+
| THEIA_E3 | 25,358 | 25,354 | 4 |
|
|
78
|
+
| TRACE_E3 | 68,172 | 68,086 | 96 |
|
|
79
|
+
| FIVEDIRECTIONS_E3 | 762 | 424 | 338 |
|
|
80
|
+
|
|
81
|
+
velox has been run end-to-end (construction → training → evaluation) against the
|
|
82
|
+
ThreaTrace ground truth on CADETS_E3, THEIA_E3, and FIVEDIRECTIONS_E3. TRACE_E3's
|
|
83
|
+
ground truth loads correctly (68,086 mapped), but its full velox run needs more RAM
|
|
84
|
+
than a 94 GB host provides (construction expands 283M events / 39M process nodes
|
|
85
|
+
beyond memory), so run it on higher-memory hardware.
|
|
86
|
+
|
|
87
|
+
## Usage
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
python pidsmaker/main.py velox CADETS_E3 --evaluation.ground_truth_version threatrace
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Requires the dataset's database to be constructed (node tables present). CADETS_E3,
|
|
94
|
+
THEIA_E3, and FIVEDIRECTIONS_E3 are ready and run end-to-end. TRACE_E3's database is
|
|
95
|
+
also loaded, but a full run needs more RAM than a 94 GB host (283M events, 39M process
|
|
96
|
+
nodes) — run it on higher-memory hardware.
|
|
97
|
+
|
|
98
|
+
## Verifying a run
|
|
99
|
+
|
|
100
|
+
At the evaluation stage, `compute_tw_labels` logs one line per time window plus a summary
|
|
101
|
+
of how many distinct ground-truth nodes were labeled:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
7 ground-truth UUIDs not present in the graph (skipped)
|
|
105
|
+
Computing time-window labels...
|
|
106
|
+
TW 0 -> 7 malicious nodes + 3828 malicious edges
|
|
107
|
+
...
|
|
108
|
+
TW 231 -> 12831 malicious nodes + 32304 malicious edges
|
|
109
|
+
...
|
|
110
|
+
Total distinct malicious nodes across time windows: 12851 / 12851 ground-truth nodes
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The final `distinct / ground-truth` line is the quick correctness check: equal numbers
|
|
114
|
+
mean every in-graph GT node was labeled. It also distinguishes ThreaTrace from orthrus —
|
|
115
|
+
ThreaTrace spans the whole test period (hundreds of `TW k ->` lines), orthrus only the
|
|
116
|
+
attack windows (a handful). Expected distinct counts:
|
|
117
|
+
|
|
118
|
+
| Dataset | distinct / GT |
|
|
119
|
+
|---|---|
|
|
120
|
+
| CADETS_E3 | 12,851 / 12,851 |
|
|
121
|
+
| THEIA_E3 | 25,354 / 25,354 |
|
|
122
|
+
| FIVEDIRECTIONS_E3 | ≤424 / 424 |
|
|
123
|
+
| TRACE_E3 | 68,086 / 68,086 |
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
|
|
5
|
+
from pidsmaker.utils.data_utils import (
|
|
6
|
+
get_original_node_ids,
|
|
7
|
+
load_all_datasets,
|
|
8
|
+
set_original_node_ids,
|
|
9
|
+
)
|
|
10
|
+
from pidsmaker.utils.utils import get_device, log, set_seed
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_preprocessed_graphs(cfg):
|
|
14
|
+
if not cfg._save_graph_preprocessing:
|
|
15
|
+
return get_data(cfg)
|
|
16
|
+
|
|
17
|
+
log("Loading preprocessed graphs...")
|
|
18
|
+
out_dir = cfg.batching._preprocessed_graphs_dir
|
|
19
|
+
out_file = os.path.join(out_dir, "torch_graphs.pkl")
|
|
20
|
+
node_ids_file = os.path.join(out_dir, "original_node_ids.pkl")
|
|
21
|
+
# Original IDs of the compacted node IDs (`batching.compact_node_ids`)
|
|
22
|
+
set_original_node_ids(torch.load(node_ids_file) if os.path.exists(node_ids_file) else None)
|
|
23
|
+
return torch.load(out_file)
|
|
24
|
+
|
|
25
|
+
def get_data(cfg):
|
|
26
|
+
device = get_device(cfg)
|
|
27
|
+
return load_all_datasets(cfg, device)
|
|
28
|
+
|
|
29
|
+
def main(cfg):
|
|
30
|
+
set_seed(cfg)
|
|
31
|
+
|
|
32
|
+
if not cfg._save_graph_preprocessing:
|
|
33
|
+
log("Skipping task to save storage.")
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
train_data, val_data, test_data, max_node_num = get_data(cfg)
|
|
37
|
+
|
|
38
|
+
out_dir = cfg.batching._preprocessed_graphs_dir
|
|
39
|
+
out_file = os.path.join(out_dir, "torch_graphs.pkl")
|
|
40
|
+
os.makedirs(out_dir, exist_ok=True)
|
|
41
|
+
log(f"Saving preprocessed graphs to {out_file}...")
|
|
42
|
+
torch.save((train_data, val_data, test_data, max_node_num), out_file)
|
|
43
|
+
node_ids_file = os.path.join(out_dir, "original_node_ids.pkl")
|
|
44
|
+
if get_original_node_ids() is not None:
|
|
45
|
+
torch.save(get_original_node_ids(), node_ids_file)
|
|
46
|
+
elif os.path.exists(node_ids_file):
|
|
47
|
+
os.remove(node_ids_file)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from pidsmaker.config import update_cfg_for_multi_dataset
|
|
2
|
+
from pidsmaker.preprocessing.build_graph_methods import (
|
|
3
|
+
build_default_graphs,
|
|
4
|
+
build_magic_graphs,
|
|
5
|
+
)
|
|
6
|
+
from pidsmaker.utils.utils import get_multi_datasets
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main_from_config(cfg):
|
|
10
|
+
graph_method = cfg.construction.used_method
|
|
11
|
+
if graph_method == "default":
|
|
12
|
+
build_default_graphs.main(cfg)
|
|
13
|
+
elif graph_method == "magic":
|
|
14
|
+
build_default_graphs.main(cfg)
|
|
15
|
+
build_magic_graphs.main(cfg)
|
|
16
|
+
else:
|
|
17
|
+
raise ValueError(f"Unrecognized graph method: {graph_method}")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def main(cfg):
|
|
21
|
+
multi_datasets = get_multi_datasets(cfg)
|
|
22
|
+
if "none" in multi_datasets:
|
|
23
|
+
main_from_config(cfg)
|
|
24
|
+
|
|
25
|
+
# Multi-dataset mode
|
|
26
|
+
else:
|
|
27
|
+
for dataset in multi_datasets:
|
|
28
|
+
updated_cfg, should_restart = update_cfg_for_multi_dataset(cfg, dataset)
|
|
29
|
+
|
|
30
|
+
if should_restart["construction"]:
|
|
31
|
+
main_from_config(updated_cfg)
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
import wandb
|
|
5
|
+
|
|
6
|
+
from pidsmaker.detection.evaluation_methods import (
|
|
7
|
+
edge_evaluation,
|
|
8
|
+
host_two_stage_evaluation,
|
|
9
|
+
node_evaluation,
|
|
10
|
+
node_tw_evaluation,
|
|
11
|
+
queue_evaluation,
|
|
12
|
+
tw_evaluation,
|
|
13
|
+
)
|
|
14
|
+
from pidsmaker.detection.evaluation_methods.evaluation_utils import (
|
|
15
|
+
compute_tw_labels,
|
|
16
|
+
epoch_name,
|
|
17
|
+
listdir_sorted,
|
|
18
|
+
load_losses_per_time_window,
|
|
19
|
+
log_best_epoch,
|
|
20
|
+
log_epoch_summary,
|
|
21
|
+
pop_report,
|
|
22
|
+
)
|
|
23
|
+
from pidsmaker.utils import console
|
|
24
|
+
from pidsmaker.utils.utils import log
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _select_epoch_without_labels(cfg, epoch_dirs):
|
|
28
|
+
"""Epoch selected by a label-free `best_model_selection` (`last_epoch`, `best_val_score`)."""
|
|
29
|
+
method = cfg.evaluation.best_model_selection
|
|
30
|
+
by_epoch = sorted(epoch_dirs, key=lambda d: int(d.split("_")[-1]))
|
|
31
|
+
if method == "last_epoch":
|
|
32
|
+
return by_epoch[-1]
|
|
33
|
+
if method == "best_val_score":
|
|
34
|
+
scores = {}
|
|
35
|
+
for d in by_epoch:
|
|
36
|
+
path = os.path.join(cfg.training._edge_losses_dir, "val_scores", f"{d}.json")
|
|
37
|
+
if os.path.exists(path):
|
|
38
|
+
with open(path) as f:
|
|
39
|
+
scores[d] = json.load(f)["val_score"]
|
|
40
|
+
if not scores:
|
|
41
|
+
raise ValueError("No validation scores found to select the best epoch.")
|
|
42
|
+
return max(scores, key=scores.get)
|
|
43
|
+
raise ValueError(
|
|
44
|
+
f"evaluate_selected_epoch_only requires a label-free best_model_selection "
|
|
45
|
+
f"(last_epoch or best_val_score), got {method}"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def standard_evaluation(cfg, evaluation_fn, group_by_time_window=False):
|
|
50
|
+
test_losses_dir = os.path.join(cfg.training._edge_losses_dir, "test")
|
|
51
|
+
val_losses_dir = os.path.join(cfg.training._edge_losses_dir, "val")
|
|
52
|
+
|
|
53
|
+
if not os.path.exists(test_losses_dir) or cfg._from_weights:
|
|
54
|
+
sorted_files = ["model_epoch_0"]
|
|
55
|
+
else:
|
|
56
|
+
sorted_files = listdir_sorted(test_losses_dir)
|
|
57
|
+
if cfg.evaluation.evaluate_selected_epoch_only:
|
|
58
|
+
sorted_files = [_select_epoch_without_labels(cfg, sorted_files)]
|
|
59
|
+
|
|
60
|
+
# Pass the first epoch's CSV directory so compute_tw_labels enumerates the
|
|
61
|
+
# same files as node_evaluation, avoiding TW index mismatch when
|
|
62
|
+
# intra-graph batching splits graphs into multiple sub-batches.
|
|
63
|
+
first_epoch_losses_dir = os.path.join(test_losses_dir, sorted_files[0])
|
|
64
|
+
if group_by_time_window:
|
|
65
|
+
# TW-level evaluations re-group the loss files into the original time windows
|
|
66
|
+
tw_names, _ = load_losses_per_time_window(first_epoch_losses_dir, cfg)
|
|
67
|
+
tw_to_malicious_nodes = compute_tw_labels(cfg, tw_names=tw_names)
|
|
68
|
+
else:
|
|
69
|
+
tw_to_malicious_nodes = compute_tw_labels(cfg, losses_dir=first_epoch_losses_dir)
|
|
70
|
+
|
|
71
|
+
best_metrics = {
|
|
72
|
+
"val_score": float("-inf"),
|
|
73
|
+
"adp_score": float("-inf"),
|
|
74
|
+
"discrimination": float("-inf"),
|
|
75
|
+
"ap@10": float("-inf"),
|
|
76
|
+
"ap": float("-inf"),
|
|
77
|
+
"stats": None,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
out_dir = cfg.evaluation._precision_recall_dir
|
|
81
|
+
|
|
82
|
+
save_files_to_wandb = cfg._experiment != "uncertainty"
|
|
83
|
+
|
|
84
|
+
epoch_reports = {} # logged for the best epoch only
|
|
85
|
+
for model_epoch_dir in sorted_files:
|
|
86
|
+
print(flush=True)
|
|
87
|
+
log(console.style(epoch_name(model_epoch_dir), "bold"))
|
|
88
|
+
|
|
89
|
+
test_tw_path = os.path.join(test_losses_dir, model_epoch_dir)
|
|
90
|
+
val_tw_path = os.path.join(val_losses_dir, model_epoch_dir)
|
|
91
|
+
|
|
92
|
+
stats = evaluation_fn(
|
|
93
|
+
val_tw_path,
|
|
94
|
+
test_tw_path,
|
|
95
|
+
model_epoch_dir,
|
|
96
|
+
cfg,
|
|
97
|
+
tw_to_malicious_nodes=tw_to_malicious_nodes,
|
|
98
|
+
)
|
|
99
|
+
val_score_file = os.path.join(
|
|
100
|
+
cfg.training._edge_losses_dir, "val_scores", f"{model_epoch_dir}.json"
|
|
101
|
+
)
|
|
102
|
+
if os.path.exists(val_score_file):
|
|
103
|
+
with open(val_score_file) as f:
|
|
104
|
+
stats["val_score"] = json.load(f)["val_score"]
|
|
105
|
+
|
|
106
|
+
log_epoch_summary(stats)
|
|
107
|
+
|
|
108
|
+
stats["epoch"] = int(model_epoch_dir.split("_")[-1])
|
|
109
|
+
epoch_reports[stats["epoch"]] = pop_report(stats)
|
|
110
|
+
|
|
111
|
+
if save_files_to_wandb:
|
|
112
|
+
# stats["simple_scores_img"] = wandb.Image(os.path.join(out_dir, f"simple_scores_{model_epoch_dir}.png"))
|
|
113
|
+
|
|
114
|
+
scores = os.path.join(out_dir, f"scores_{model_epoch_dir}.png")
|
|
115
|
+
if os.path.exists(scores):
|
|
116
|
+
stats["scores_img"] = wandb.Image(scores)
|
|
117
|
+
|
|
118
|
+
# pr = os.path.join(out_dir, f"pr_curve_{model_epoch_dir}.png")
|
|
119
|
+
# if os.path.exists(pr):
|
|
120
|
+
# stats["precision_recall_img"] = wandb.Image(pr)
|
|
121
|
+
|
|
122
|
+
adp = os.path.join(out_dir, f"adp_curve_{model_epoch_dir}.png")
|
|
123
|
+
if os.path.exists(adp):
|
|
124
|
+
stats["adp_img"] = wandb.Image(adp)
|
|
125
|
+
|
|
126
|
+
# seen_scores = os.path.join(out_dir, f"seen_score_{model_epoch_dir}.png")
|
|
127
|
+
# if os.path.exists(seen_scores):
|
|
128
|
+
# stats["seen_scores_img"] = wandb.Image(seen_scores)
|
|
129
|
+
|
|
130
|
+
discrim = os.path.join(out_dir, f"discrim_curve_{model_epoch_dir}.png")
|
|
131
|
+
if os.path.exists(discrim):
|
|
132
|
+
stats["discrim_img"] = wandb.Image(discrim)
|
|
133
|
+
|
|
134
|
+
distrib = os.path.join(out_dir, f"distrib_{model_epoch_dir}.png")
|
|
135
|
+
if os.path.exists(distrib):
|
|
136
|
+
stats["distrib_img"] = wandb.Image(distrib)
|
|
137
|
+
|
|
138
|
+
wandb.log(stats)
|
|
139
|
+
|
|
140
|
+
best_metrics = best_metric_pick_best_epoch(stats, best_metrics, cfg)
|
|
141
|
+
|
|
142
|
+
if save_files_to_wandb and "neat_scores_img_file" in best_metrics["stats"]:
|
|
143
|
+
# We only store the scores for the best run
|
|
144
|
+
# wandb.save(best_metrics["stats"]["scores_file"], out_dir)
|
|
145
|
+
wandb.save(best_metrics["stats"]["neat_scores_img_file"], out_dir)
|
|
146
|
+
|
|
147
|
+
best_stats = best_metrics["stats"]
|
|
148
|
+
best_report = []
|
|
149
|
+
if best_stats is not None:
|
|
150
|
+
best_report = epoch_reports.get(best_stats.get("epoch"), [])
|
|
151
|
+
log_best_epoch(best_stats, cfg, best_report)
|
|
152
|
+
|
|
153
|
+
return best_metrics["stats"]
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def best_metric_pick_best_epoch(stats, best_metrics, cfg):
|
|
157
|
+
best_model_selection = cfg.evaluation.best_model_selection
|
|
158
|
+
|
|
159
|
+
# Last evaluated epoch (epochs are evaluated in increasing order)
|
|
160
|
+
if best_model_selection == "last_epoch":
|
|
161
|
+
if best_metrics["stats"] is None or stats["epoch"] >= best_metrics["stats"]["epoch"]:
|
|
162
|
+
best_metrics["stats"] = stats
|
|
163
|
+
return best_metrics
|
|
164
|
+
|
|
165
|
+
# Selection on the MCC of the predictions on the test set (as the code of LARES)
|
|
166
|
+
if best_model_selection == "best_mcc":
|
|
167
|
+
mcc = stats.get("mcc", float("-inf"))
|
|
168
|
+
mcc = float("-inf") if mcc != mcc else mcc
|
|
169
|
+
if best_metrics["stats"] is None or mcc > best_metrics.get("mcc", float("-inf")):
|
|
170
|
+
best_metrics["mcc"] = mcc
|
|
171
|
+
best_metrics["stats"] = stats
|
|
172
|
+
return best_metrics
|
|
173
|
+
|
|
174
|
+
# Selection on validation data only (e.g. link prediction AUC + AP of the validation edges)
|
|
175
|
+
if best_model_selection == "best_val_score":
|
|
176
|
+
if "val_score" not in stats:
|
|
177
|
+
raise ValueError(
|
|
178
|
+
"best_model_selection=best_val_score requires an objective computing a validation "
|
|
179
|
+
"score (e.g. predict_edge_contrastive)."
|
|
180
|
+
)
|
|
181
|
+
if best_metrics["stats"] is None or stats["val_score"] > best_metrics["val_score"]:
|
|
182
|
+
best_metrics["val_score"] = stats["val_score"]
|
|
183
|
+
best_metrics["stats"] = stats
|
|
184
|
+
return best_metrics
|
|
185
|
+
|
|
186
|
+
# ADP and discrimination are only computed by node/edge-level evaluations.
|
|
187
|
+
# Other evaluations (tw, node_tw) fall back to selecting the epoch with best AP.
|
|
188
|
+
if "adp_score" not in stats or "discrimination" not in stats:
|
|
189
|
+
stats_ap = stats.get("ap", float("nan"))
|
|
190
|
+
stats_ap = float("-inf") if stats_ap != stats_ap else stats_ap # nan => -inf
|
|
191
|
+
if best_metrics["stats"] is None or stats_ap > best_metrics["ap"]:
|
|
192
|
+
best_metrics["ap"] = stats_ap
|
|
193
|
+
best_metrics["stats"] = stats
|
|
194
|
+
return best_metrics
|
|
195
|
+
|
|
196
|
+
if best_model_selection == "best_adp":
|
|
197
|
+
condition = (stats["adp_score"] > best_metrics["adp_score"]) or (
|
|
198
|
+
stats["adp_score"] == best_metrics["adp_score"]
|
|
199
|
+
and stats["discrimination"] > best_metrics["discrimination"]
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
elif best_model_selection == "best_discrimination":
|
|
203
|
+
condition = stats["discrimination"] > best_metrics["discrimination"]
|
|
204
|
+
|
|
205
|
+
elif best_model_selection == "best_ap@10":
|
|
206
|
+
condition = (stats["ap@10"] > best_metrics["ap@10"]) or (
|
|
207
|
+
stats["ap@10"] == best_metrics["ap@10"]
|
|
208
|
+
and stats["discrimination"] > best_metrics["discrimination"]
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
else:
|
|
212
|
+
raise ValueError(f"Invalid best model selection {best_model_selection}")
|
|
213
|
+
|
|
214
|
+
if condition:
|
|
215
|
+
best_metrics["adp_score"] = stats["adp_score"]
|
|
216
|
+
best_metrics["discrimination"] = stats["discrimination"]
|
|
217
|
+
best_metrics["ap@10"] = stats.get("ap@10", float("-inf"))
|
|
218
|
+
best_metrics["stats"] = stats
|
|
219
|
+
return best_metrics
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def main(cfg):
|
|
223
|
+
method = cfg.evaluation.used_method.strip()
|
|
224
|
+
if method == "node_evaluation":
|
|
225
|
+
return standard_evaluation(cfg, evaluation_fn=node_evaluation.main)
|
|
226
|
+
elif method == "tw_evaluation":
|
|
227
|
+
return standard_evaluation(
|
|
228
|
+
cfg, evaluation_fn=tw_evaluation.main, group_by_time_window=True
|
|
229
|
+
)
|
|
230
|
+
elif method == "node_tw_evaluation":
|
|
231
|
+
return standard_evaluation(
|
|
232
|
+
cfg, evaluation_fn=node_tw_evaluation.main, group_by_time_window=True
|
|
233
|
+
)
|
|
234
|
+
elif method == "queue_evaluation":
|
|
235
|
+
return queue_evaluation.main(cfg)
|
|
236
|
+
elif method == "edge_evaluation":
|
|
237
|
+
return standard_evaluation(cfg, evaluation_fn=edge_evaluation.main)
|
|
238
|
+
elif method == "host_two_stage_evaluation":
|
|
239
|
+
return standard_evaluation(cfg, evaluation_fn=host_two_stage_evaluation.main)
|
|
240
|
+
else:
|
|
241
|
+
raise ValueError(f"Invalid evaluation method {cfg.evaluation.used_method}")
|