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,80 @@
|
|
|
1
|
+
"""Encoder wrappers used by network IDSs (Euler, Argus, LARES).
|
|
2
|
+
|
|
3
|
+
- `NodeIdEmbedding` concatenates a learned embedding of each node's identity to its features,
|
|
4
|
+
equivalent to the one-hot node ID features of Euler, Argus and LARES followed by a linear
|
|
5
|
+
layer. With `all_nodes`, all the nodes of the dataset are embedded in every graph, as Euler
|
|
6
|
+
and Argus do (nodes absent from the graph are isolated and only get their ID embedding):
|
|
7
|
+
every node then has an embedding trained at each graph, e.g. by uniform negative edges.
|
|
8
|
+
Otherwise, only the nodes of each graph are embedded, and nodes unseen during training keep
|
|
9
|
+
an untrained embedding.
|
|
10
|
+
- `SnapshotGRU` runs a GRU over the successive embeddings of each node, one step per graph
|
|
11
|
+
(i.e. per time window or batch), as Euler and Argus do over snapshots. The hidden state of
|
|
12
|
+
each node is kept across graphs and detached after each graph (truncated backpropagation
|
|
13
|
+
through time, whereas Euler backpropagates through all the snapshots of the training set).
|
|
14
|
+
The embedding of a node is its new hidden state projected by a linear layer ("detector" mode
|
|
15
|
+
of Euler).
|
|
16
|
+
|
|
17
|
+
When the encoder embeds other nodes than those of the batch (`all_nodes`), its output carries
|
|
18
|
+
the IDs of the embedded nodes (`n_id`) and the edges of the batch in this node space
|
|
19
|
+
(`edge_index`), used by the model to gather the embeddings of edges and by objectives.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import torch
|
|
23
|
+
import torch.nn as nn
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class NodeIdEmbedding(nn.Module):
|
|
27
|
+
def __init__(self, encoder, num_nodes, dim, all_nodes=False):
|
|
28
|
+
super().__init__()
|
|
29
|
+
self.encoder = encoder
|
|
30
|
+
self.embedding = nn.Embedding(num_nodes, dim)
|
|
31
|
+
self.all_nodes = all_nodes
|
|
32
|
+
|
|
33
|
+
def forward(self, x, original_n_id, edge_index, **kwargs):
|
|
34
|
+
if not self.all_nodes:
|
|
35
|
+
x = torch.cat([x, self.embedding(original_n_id.long())], dim=-1)
|
|
36
|
+
return self.encoder(x=x, original_n_id=original_n_id, edge_index=edge_index, **kwargs)
|
|
37
|
+
|
|
38
|
+
# All the nodes of the dataset, in the ID space of the dataset
|
|
39
|
+
n_id = original_n_id.long()
|
|
40
|
+
num_nodes = self.embedding.num_embeddings
|
|
41
|
+
x_all = x.new_zeros((num_nodes, x.size(1)))
|
|
42
|
+
x_all[n_id] = x
|
|
43
|
+
x_all = torch.cat([x_all, self.embedding.weight], dim=-1)
|
|
44
|
+
all_n_id = torch.arange(num_nodes, device=x.device)
|
|
45
|
+
global_edge_index = n_id[edge_index]
|
|
46
|
+
res = dict(
|
|
47
|
+
self.encoder(x=x_all, original_n_id=all_n_id, edge_index=global_edge_index, **kwargs)
|
|
48
|
+
)
|
|
49
|
+
res["n_id"] = all_n_id
|
|
50
|
+
res["edge_index"] = global_edge_index
|
|
51
|
+
return res
|
|
52
|
+
|
|
53
|
+
def reset_state(self):
|
|
54
|
+
if hasattr(self.encoder, "reset_state"):
|
|
55
|
+
self.encoder.reset_state()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class SnapshotGRU(nn.Module):
|
|
59
|
+
def __init__(self, encoder, num_nodes, in_dim, out_dim, hidden_dim=None, dropout=0.0):
|
|
60
|
+
super().__init__()
|
|
61
|
+
hidden_dim = hidden_dim or out_dim
|
|
62
|
+
self.encoder = encoder
|
|
63
|
+
self.dropout = nn.Dropout(dropout)
|
|
64
|
+
self.gru = nn.GRUCell(in_dim, hidden_dim)
|
|
65
|
+
self.out = nn.Linear(hidden_dim, out_dim)
|
|
66
|
+
self.register_buffer("state", torch.zeros(num_nodes, hidden_dim))
|
|
67
|
+
|
|
68
|
+
def forward(self, original_n_id, **kwargs):
|
|
69
|
+
res = dict(self.encoder(original_n_id=original_n_id, **kwargs))
|
|
70
|
+
# Nodes embedded by the encoder (all the nodes of the dataset with `all_nodes`)
|
|
71
|
+
n_id = res.get("n_id", original_n_id).long()
|
|
72
|
+
h_new = self.gru(self.dropout(torch.tanh(res["h"])), self.state[n_id])
|
|
73
|
+
self.state[n_id] = h_new.detach()
|
|
74
|
+
res["h"] = self.out(h_new)
|
|
75
|
+
return res
|
|
76
|
+
|
|
77
|
+
def reset_state(self):
|
|
78
|
+
self.state.zero_()
|
|
79
|
+
if hasattr(self.encoder, "reset_state"):
|
|
80
|
+
self.encoder.reset_state()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""TextRCNN over the sequence of the last snapshot embeddings (ProGrapher's anomaly detector).
|
|
2
|
+
|
|
3
|
+
Each graph (time window) is a snapshot embedded as a whole by graph2vec (`batch.graph_emb`, see
|
|
4
|
+
`featurization.used_method=graph2vec`). Like `snapshot_gru`, the encoder keeps a state across
|
|
5
|
+
graphs: the embeddings of the last `sequence_length` snapshots seen, in the order of the graphs
|
|
6
|
+
(chronological, as graphs are iterated by time window). From this sequence, it predicts the
|
|
7
|
+
embedding of the current snapshot, which the `predict_snapshot_embedding` objective compares with
|
|
8
|
+
its actual embedding.
|
|
9
|
+
|
|
10
|
+
The TextRCNN of ProGrapher (Lai et al., AAAI 2015) represents each snapshot S_i of the sequence by
|
|
11
|
+
x_i = [left(S_i); E(S_i); right(S_i)], the left and right contexts being computed by a
|
|
12
|
+
bidirectional RNN, projects it with y_i = tanh(W x_i + b), max-pools the y_i over the sequence,
|
|
13
|
+
and maps the result to the predicted embedding with a fully-connected layer.
|
|
14
|
+
|
|
15
|
+
The state is filled with the actual embeddings of the snapshots (teacher forcing), reset before
|
|
16
|
+
each training epoch, and carried from the training graphs to the validation and test graphs, as
|
|
17
|
+
inference follows training. With fewer previous snapshots than `sequence_length` (e.g. at the
|
|
18
|
+
beginning of training), the sequence is shorter; the first snapshot is predicted from a zero
|
|
19
|
+
embedding.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import torch
|
|
23
|
+
import torch.nn as nn
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TextRCNN(nn.Module):
|
|
27
|
+
def __init__(self, emb_dim, hid_dim, num_layers, sequence_length, dropout=0.0, rnn_type="lstm"):
|
|
28
|
+
super().__init__()
|
|
29
|
+
rnn_classes = {"lstm": nn.LSTM, "gru": nn.GRU, "rnn": nn.RNN}
|
|
30
|
+
if rnn_type not in rnn_classes:
|
|
31
|
+
raise ValueError(f"Invalid TextRCNN rnn_type {rnn_type}, expected one of {list(rnn_classes)}")
|
|
32
|
+
rnn_kwargs = {"nonlinearity": "relu"} if rnn_type == "rnn" else {}
|
|
33
|
+
self.rnn = rnn_classes[rnn_type](
|
|
34
|
+
emb_dim,
|
|
35
|
+
hid_dim,
|
|
36
|
+
num_layers=num_layers,
|
|
37
|
+
bidirectional=True,
|
|
38
|
+
batch_first=True,
|
|
39
|
+
dropout=dropout if num_layers > 1 else 0.0,
|
|
40
|
+
**rnn_kwargs,
|
|
41
|
+
)
|
|
42
|
+
self.proj = nn.Linear(2 * hid_dim + emb_dim, hid_dim)
|
|
43
|
+
self.dropout = nn.Dropout(dropout)
|
|
44
|
+
self.fc = nn.Linear(hid_dim, emb_dim)
|
|
45
|
+
self.emb_dim = emb_dim
|
|
46
|
+
self.sequence_length = sequence_length
|
|
47
|
+
self.history = []
|
|
48
|
+
|
|
49
|
+
def predict(self, sequence):
|
|
50
|
+
"""Predicts the next embedding from a (B, k, d) sequence of snapshot embeddings."""
|
|
51
|
+
context, _ = self.rnn(sequence) # (B, k, 2 * hid): left and right contexts
|
|
52
|
+
y = torch.tanh(self.proj(torch.cat([context, sequence], dim=-1))) # (B, k, hid)
|
|
53
|
+
pooled = y.max(dim=1).values # (B, hid)
|
|
54
|
+
return self.fc(self.dropout(pooled)) # (B, d)
|
|
55
|
+
|
|
56
|
+
def forward(self, batch, edge_index, **kwargs):
|
|
57
|
+
target = getattr(batch, "graph_emb", None)
|
|
58
|
+
if target is None:
|
|
59
|
+
raise ValueError(
|
|
60
|
+
"The `textrcnn` encoder predicts the graph2vec embedding of each snapshot: it "
|
|
61
|
+
"requires `featurization.used_method=graph2vec`."
|
|
62
|
+
)
|
|
63
|
+
target = target.float().view(1, -1)
|
|
64
|
+
|
|
65
|
+
if self.history:
|
|
66
|
+
sequence = torch.cat([h.to(target.device) for h in self.history], dim=0)
|
|
67
|
+
else:
|
|
68
|
+
sequence = target.new_zeros((1, self.emb_dim))
|
|
69
|
+
pred = self.predict(sequence.unsqueeze(0)) # (1, d)
|
|
70
|
+
|
|
71
|
+
# The actual embedding of the snapshot is the last element of the next sequences
|
|
72
|
+
self.history.append(target.detach())
|
|
73
|
+
if len(self.history) > self.sequence_length:
|
|
74
|
+
self.history.pop(0)
|
|
75
|
+
|
|
76
|
+
# The prediction is a graph-level output: edges get it as their src and dst embeddings
|
|
77
|
+
num_edges = edge_index.size(1)
|
|
78
|
+
h_edges = pred.expand(num_edges, -1)
|
|
79
|
+
return {"h": pred, "h_src": h_edges, "h_dst": h_edges}
|
|
80
|
+
|
|
81
|
+
def reset_state(self):
|
|
82
|
+
self.history = []
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
import torch.nn as nn
|
|
3
|
+
|
|
4
|
+
from pidsmaker.encoders import GRU
|
|
5
|
+
from pidsmaker.hetero import _compute_hetero_features
|
|
6
|
+
from pidsmaker.experiments.uncertainty import IdentityWrapper
|
|
7
|
+
|
|
8
|
+
class TGNEncoder(nn.Module):
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
encoder,
|
|
12
|
+
memory,
|
|
13
|
+
time_encoder,
|
|
14
|
+
in_dim,
|
|
15
|
+
memory_dim,
|
|
16
|
+
out_dim,
|
|
17
|
+
use_node_feats_in_gnn,
|
|
18
|
+
edge_features,
|
|
19
|
+
device,
|
|
20
|
+
use_memory,
|
|
21
|
+
use_time_enc,
|
|
22
|
+
edge_dim,
|
|
23
|
+
use_time_order_encoding,
|
|
24
|
+
project_src_dst,
|
|
25
|
+
is_hetero,
|
|
26
|
+
node_map,
|
|
27
|
+
edge_map,
|
|
28
|
+
tgn_pre_encoder,
|
|
29
|
+
use_residual_norm,
|
|
30
|
+
dropout,
|
|
31
|
+
):
|
|
32
|
+
super(TGNEncoder, self).__init__()
|
|
33
|
+
self.encoder = encoder
|
|
34
|
+
self.memory = memory
|
|
35
|
+
self.device = device
|
|
36
|
+
|
|
37
|
+
self.edge_features = edge_features
|
|
38
|
+
if "time_encoding" in self.edge_features:
|
|
39
|
+
self.time_encoder = time_encoder
|
|
40
|
+
|
|
41
|
+
self.use_memory = use_memory
|
|
42
|
+
self.use_time_enc = use_time_enc
|
|
43
|
+
|
|
44
|
+
self.use_node_feats_in_gnn = use_node_feats_in_gnn
|
|
45
|
+
self.project_src_dst = project_src_dst
|
|
46
|
+
if not self.use_memory or self.use_node_feats_in_gnn:
|
|
47
|
+
if self.project_src_dst:
|
|
48
|
+
self.src_linear = nn.Linear(in_dim, memory_dim)
|
|
49
|
+
self.dst_linear = nn.Linear(in_dim, memory_dim)
|
|
50
|
+
else:
|
|
51
|
+
self.linear = nn.Linear(in_dim, memory_dim)
|
|
52
|
+
|
|
53
|
+
self.use_time_order_encoding = use_time_order_encoding
|
|
54
|
+
if self.use_time_order_encoding:
|
|
55
|
+
self.gru = GRU(edge_dim, edge_dim, device)
|
|
56
|
+
|
|
57
|
+
self.is_hetero = is_hetero
|
|
58
|
+
self.node_map = node_map
|
|
59
|
+
self.edge_map = edge_map
|
|
60
|
+
self.tgn_pre_encoder = tgn_pre_encoder if tgn_pre_encoder is not None else IdentityWrapper()
|
|
61
|
+
|
|
62
|
+
self.use_residual_norm = use_residual_norm
|
|
63
|
+
if use_residual_norm:
|
|
64
|
+
self.norm_local = nn.LayerNorm(out_dim)
|
|
65
|
+
self.dropout = nn.Dropout(dropout)
|
|
66
|
+
# The projected features have size `memory_dim`, while the GNN outputs `out_dim`
|
|
67
|
+
self.residual_proj = (
|
|
68
|
+
nn.Linear(memory_dim, out_dim) if memory_dim != out_dim else nn.Identity()
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
def forward(self, batch, inference=False, **kwargs):
|
|
72
|
+
# First batch of a day with `tgn_last_neighbor.reset_state_every_day`
|
|
73
|
+
if getattr(batch, "reset_tgn_state", False) and (self.use_memory or self.use_time_enc):
|
|
74
|
+
self.memory.reset_state()
|
|
75
|
+
|
|
76
|
+
n_id = batch.n_id_tgn # NOTE: this one may need to be updated with no __inc__, or memory is get for unknown nodes
|
|
77
|
+
edge_index = batch.edge_index_tgn
|
|
78
|
+
# Not built when unused (with memory and without `use_node_feats_in_gnn`)
|
|
79
|
+
x = getattr(batch, "x_tgn", None)
|
|
80
|
+
|
|
81
|
+
# NOTE: these are shape (N,) not (E,)
|
|
82
|
+
x_s = getattr(batch, "x_from_tgn", None)
|
|
83
|
+
x_d = getattr(batch, "x_to_tgn", None)
|
|
84
|
+
|
|
85
|
+
x_proj = None
|
|
86
|
+
if (not self.use_memory) or self.use_node_feats_in_gnn:
|
|
87
|
+
if self.project_src_dst:
|
|
88
|
+
x_s = self.tgn_pre_encoder(x_s)
|
|
89
|
+
x_d = self.tgn_pre_encoder(x_d)
|
|
90
|
+
x_proj = self.src_linear(x_s) + self.dst_linear(x_d)
|
|
91
|
+
else:
|
|
92
|
+
x_tok = self.tgn_pre_encoder(x)
|
|
93
|
+
x_proj = self.linear(x_tok)
|
|
94
|
+
|
|
95
|
+
if self.use_memory:
|
|
96
|
+
h, last_update = self.memory(n_id)
|
|
97
|
+
if self.use_node_feats_in_gnn:
|
|
98
|
+
h = h + x_proj
|
|
99
|
+
else:
|
|
100
|
+
h = x_proj
|
|
101
|
+
|
|
102
|
+
# Edge features
|
|
103
|
+
edge_feats = []
|
|
104
|
+
if "edge_type_triplet" in self.edge_features or "edge_type" in self.edge_features:
|
|
105
|
+
edge_feats.append(batch.edge_type_tgn)
|
|
106
|
+
if "msg" in self.edge_features:
|
|
107
|
+
edge_feats.append(batch.msg_tgn)
|
|
108
|
+
if "edge_attrs" in self.edge_features:
|
|
109
|
+
edge_feats.append(batch.edge_attr_feats_tgn)
|
|
110
|
+
if "time_encoding" in self.edge_features: # or self.use_time_enc
|
|
111
|
+
if not self.use_memory:
|
|
112
|
+
last_update = self.memory.get_last_update(n_id)
|
|
113
|
+
curr_t = batch.t_tgn
|
|
114
|
+
rel_t = last_update[edge_index[0]] - curr_t
|
|
115
|
+
rel_t_enc = self.time_encoder(rel_t.to(h.dtype))
|
|
116
|
+
edge_feats.append(rel_t_enc)
|
|
117
|
+
edge_feats = torch.cat(edge_feats, dim=-1) if len(edge_feats) > 0 else None
|
|
118
|
+
|
|
119
|
+
if self.use_time_order_encoding:
|
|
120
|
+
if len(edge_feats) > 0: # GRU doesn't work with empty sequences
|
|
121
|
+
edge_feats = self.gru(edge_feats)
|
|
122
|
+
self.gru.detach_state()
|
|
123
|
+
|
|
124
|
+
node_type = batch.node_type_tgn
|
|
125
|
+
edge_type = batch.edge_type_tgn
|
|
126
|
+
node_type_argmax = node_type.max(dim=1).indices
|
|
127
|
+
|
|
128
|
+
# Hetero stuff
|
|
129
|
+
if self.is_hetero:
|
|
130
|
+
edge_type_argmax = edge_type.max(dim=1).indices
|
|
131
|
+
|
|
132
|
+
x_dict, edge_index_dict = _compute_hetero_features(
|
|
133
|
+
edge_index=edge_index,
|
|
134
|
+
x=h,
|
|
135
|
+
node_type_argmax=node_type_argmax,
|
|
136
|
+
edge_type_argmax=edge_type_argmax,
|
|
137
|
+
node_map=self.node_map,
|
|
138
|
+
edge_map=self.edge_map,
|
|
139
|
+
)
|
|
140
|
+
else:
|
|
141
|
+
x_dict, edge_index_dict = None, None
|
|
142
|
+
|
|
143
|
+
tgn_kwargs = {
|
|
144
|
+
"x": h,
|
|
145
|
+
"edge_index": edge_index,
|
|
146
|
+
"edge_feats": edge_feats,
|
|
147
|
+
"node_type": node_type,
|
|
148
|
+
"edge_types": edge_type,
|
|
149
|
+
"original_n_id": n_id,
|
|
150
|
+
"x_dict": x_dict,
|
|
151
|
+
"edge_index_dict": edge_index_dict,
|
|
152
|
+
"node_type_argmax": node_type_argmax,
|
|
153
|
+
}
|
|
154
|
+
kwargs = {**kwargs, **tgn_kwargs}
|
|
155
|
+
h = self.encoder(**kwargs)["h"]
|
|
156
|
+
|
|
157
|
+
# Apply residual normalization to local encoder output
|
|
158
|
+
if self.use_residual_norm:
|
|
159
|
+
h = self.norm_local(self.dropout(h) + self.residual_proj(x_proj))
|
|
160
|
+
|
|
161
|
+
if "neg_dst_tgn" in batch:
|
|
162
|
+
# Embeddings of the negative destinations of the edges (`negative_destinations`)
|
|
163
|
+
batch.h_neg_tgn = h[batch.neg_dst_tgn]
|
|
164
|
+
h_src = h[batch.reindexed_edge_index_tgn[0]]
|
|
165
|
+
h_dst = h[batch.reindexed_edge_index_tgn[1]]
|
|
166
|
+
|
|
167
|
+
# in the neigh loader, n_id is original n_id and the n_id of neighbors, here we remove neighbors and keep original node IDs
|
|
168
|
+
h = h[batch.reindexed_original_n_id_tgn]
|
|
169
|
+
|
|
170
|
+
# Update memory and neighbor loader with ground-truth state.
|
|
171
|
+
if self.use_memory or self.use_time_enc:
|
|
172
|
+
# The raw message is only used by the TGN memory (TimeEncodingMemory ignores it,
|
|
173
|
+
# and `msg` is not kept in the batches when unused)
|
|
174
|
+
raw_msg = batch.msg if self.use_memory else None
|
|
175
|
+
# The nodes of the edges, computed in the batching (`torch.unique` waits for the GPU)
|
|
176
|
+
n_id_edges = None if "neg_dst_tgn" in batch else getattr(batch, "original_n_id", None)
|
|
177
|
+
self.memory.update_state(batch.src, batch.dst, batch.t, raw_msg, n_id=n_id_edges)
|
|
178
|
+
|
|
179
|
+
# Detaching memory is only useful for backprop in training
|
|
180
|
+
if self.use_memory and not inference:
|
|
181
|
+
self.memory.detach()
|
|
182
|
+
|
|
183
|
+
return {"h": h, "h_src": h_src, "h_dst": h_dst, "x_proj": x_proj}
|
|
184
|
+
|
|
185
|
+
def reset_state(self):
|
|
186
|
+
if self.use_memory or self.use_time_enc: # if memory is used
|
|
187
|
+
self.memory.reset_state() # Flushes memory.
|
|
188
|
+
|
|
189
|
+
def to_device(self, device):
|
|
190
|
+
self.device = device
|
|
191
|
+
if hasattr(self, "gru"):
|
|
192
|
+
self.gru.device = device
|
|
193
|
+
return self
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
import functools
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
import yaml
|
|
6
|
+
|
|
7
|
+
from pidsmaker.config import get_yml_file, merge_cfg_and_check_syntax, update_task_paths_to_restart
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_tuning_sweep_cfg(cfg):
|
|
11
|
+
# Priority to a manual path.
|
|
12
|
+
if cfg._tuning_file_path != "":
|
|
13
|
+
splitted_path = cfg._tuning_file_path.split("/")
|
|
14
|
+
path = "/".join(splitted_path[:-1])
|
|
15
|
+
filename = splitted_path[-1]
|
|
16
|
+
yml_file = get_yml_file(filename=filename, folder=f"experiments/tuning/{path}/")
|
|
17
|
+
|
|
18
|
+
else:
|
|
19
|
+
if cfg._tuning_mode == "hyperparameters":
|
|
20
|
+
# First looks for a specific yml file in the dataset folder. If not present, takes the default tuning config.
|
|
21
|
+
yml_file = get_yml_file(
|
|
22
|
+
filename=f"tuning_{cfg._model}",
|
|
23
|
+
folder=f"experiments/tuning/systems/{cfg.dataset.name.lower()}/",
|
|
24
|
+
)
|
|
25
|
+
if not os.path.exists(yml_file):
|
|
26
|
+
yml_file = get_yml_file(
|
|
27
|
+
filename="tuning_default_baselines",
|
|
28
|
+
folder="experiments/tuning/systems/default/",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
elif cfg._tuning_mode == "featurization":
|
|
32
|
+
yml_file = get_yml_file(
|
|
33
|
+
filename="tuning_featurization_methods", folder="experiments/tuning/components/"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
else:
|
|
37
|
+
raise ValueError(f"Invalid tuning mode {cfg._tuning_mode}")
|
|
38
|
+
|
|
39
|
+
if not os.path.exists(yml_file):
|
|
40
|
+
raise FileNotFoundError("Missing tuning yml file")
|
|
41
|
+
|
|
42
|
+
with open(yml_file, "r") as file:
|
|
43
|
+
tuning_config = yaml.safe_load(file)
|
|
44
|
+
return tuning_config
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def set_nested_attr(d, attr, value):
|
|
48
|
+
return functools.reduce(
|
|
49
|
+
lambda c, k: c[k] if k in c else None, attr.split(".")[:-1], d
|
|
50
|
+
).__setitem__(attr.split(".")[-1], value)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def fuse_cfg_with_sweep_cfg(cfg, sweep_cfg):
|
|
54
|
+
cfg = copy.deepcopy(cfg)
|
|
55
|
+
for key, value in sweep_cfg.items():
|
|
56
|
+
# special keys
|
|
57
|
+
if key == "embedding_techniques":
|
|
58
|
+
if value == "no_featurization":
|
|
59
|
+
yml_file = get_yml_file(value, folder="tuned_components/")
|
|
60
|
+
merge_cfg_and_check_syntax(cfg, yml_file)
|
|
61
|
+
|
|
62
|
+
else:
|
|
63
|
+
method = "_".join(value.split("_")[:-1])
|
|
64
|
+
split = value.split("_")[-1]
|
|
65
|
+
if split not in ["train", "all"]:
|
|
66
|
+
raise ValueError(f"Invalid split {split} for embedding technique")
|
|
67
|
+
|
|
68
|
+
yml_file = get_yml_file(method, folder="tuned_components/")
|
|
69
|
+
merge_cfg_and_check_syntax(cfg, yml_file)
|
|
70
|
+
|
|
71
|
+
# Train or Train+Test embedding method training
|
|
72
|
+
cfg.featurization.training_split = split
|
|
73
|
+
|
|
74
|
+
# If a model doesn't use embedding in features, we add them to benchmark
|
|
75
|
+
if "node_emb" not in cfg.batching.node_features:
|
|
76
|
+
cfg.batching.node_features += ",node_emb"
|
|
77
|
+
|
|
78
|
+
elif key == "orthrus_node_label_features":
|
|
79
|
+
if value == True:
|
|
80
|
+
cfg.construction.node_label_features.subject = "type, path, cmd_line"
|
|
81
|
+
cfg.construction.node_label_features.file = "type, path"
|
|
82
|
+
cfg.construction.node_label_features.netflow = "type, remote_ip, remote_port"
|
|
83
|
+
|
|
84
|
+
# default cfg path
|
|
85
|
+
else:
|
|
86
|
+
set_nested_attr(cfg, key, value)
|
|
87
|
+
|
|
88
|
+
# Special cases
|
|
89
|
+
if cfg.training.node_out_dim == -1:
|
|
90
|
+
cfg.training.node_out_dim = cfg.training.node_hid_dim
|
|
91
|
+
elif cfg.training.node_out_dim == -2:
|
|
92
|
+
cfg.training.node_out_dim = cfg.training.node_hid_dim // 2
|
|
93
|
+
|
|
94
|
+
if cfg.training.encoder.tgn.tgn_memory_dim == -1:
|
|
95
|
+
cfg.training.encoder.tgn.tgn_memory_dim = cfg.training.node_hid_dim
|
|
96
|
+
if cfg.training.encoder.tgn.tgn_time_dim == -1:
|
|
97
|
+
cfg.training.encoder.tgn.tgn_time_dim = cfg.training.node_hid_dim
|
|
98
|
+
|
|
99
|
+
# We modified the cfg so we have to update the task paths accordingly
|
|
100
|
+
update_task_paths_to_restart(cfg)
|
|
101
|
+
|
|
102
|
+
return cfg
|