<jupyter_start><jupyter_text>Train Model On Synthetic Data<jupyter_code># Set is_cuda to be true if available
if torch.cuda.is_available():
    set_parameter("parameters_ipynb_synthetic.ini", "general", "is_cuda", "True")
else:
    set_parameter("parameters_ipynb_synthetic.ini", "general", "is_cuda", "False")
# Train a model using natural training
set_parameter("parameters_ipynb_synthetic.ini", "general", "training_method", "natural")
set_parameter("parameters_ipynb_synthetic.ini", "general", "evasion_method", "natural")
%run framework.py parameters_ipynb_synthetic.ini
# Train a model using rfgsm inner maximization
set_parameter("parameters_ipynb_synthetic.ini", "general", "training_method", "rfgsm_k")
set_parameter("parameters_ipynb_synthetic.ini", "general", "evasion_method", "rfgsm_k")

%run framework.py parameters_ipynb_synthetic.ini
ls trained_models/
natural_model_path = "trained_models/[training:natural|evasion:natural]_synthetic_data_tutorial-model.pt"
rfgsm_model_path = "trained_models/[training:rfgsm_k|evasion:rfgsm_k]_synthetic_data_tutorial-model.pt"<jupyter_output><empty_output><jupyter_text>Generate Adversarial Vectors<jupyter_code># Generate adversarial vectors using the naturally trained model trained previously
%run generate_adversarial/generate_adversarial_vectors.py generate_adversarial/generate_adversarial_parameters_ipynb_synthetic.ini
adversarial_vector_location = "adversarial_vectors/natural"<jupyter_output><empty_output><jupyter_text>Loss Progression Graphs (Figure 3 in Paper)<jupyter_code># Set is_cuda to be true if available
if torch.cuda.is_available():
    set_parameter("loss_graphs/loss_progression_parameters_ipynb_synthetic.ini", "general", "is_cuda", "True")
else:
    set_parameter("loss_graphs/loss_progression_parameters_ipynb_synthetic.ini", "general", "is_cuda", "False")
# Use the naturally-trained model with rfgsm as the adversarial method
set_parameter("loss_graphs/loss_progression_parameters_ipynb_synthetic.ini", "general", "model_weights_path", natural_model_path)
set_parameter("loss_graphs/loss_progression_parameters_ipynb_synthetic.ini", "general", "training_method", "natural")
set_parameter("loss_graphs/loss_progression_parameters_ipynb_synthetic.ini", "general", "evasion_method", "rfgsm_k")

%run loss_graphs/generate_loss_figures.py loss_graphs/loss_progression_parameters_ipynb_synthetic.ini loss_progression_example
# Use the rfgsm-trained model with rfgsm as the adversarial method
set_parameter("loss_graphs/loss_progression_parameters_ipynb_synthetic.ini", "general", "model_weights_path", rfgsm_model_path)
set_parameter("loss_graphs/loss_progression_parameters_ipynb_synthetic.ini", "general", "training_method", "rfgsm_k")
set_parameter("loss_graphs/loss_progression_parameters_ipynb_synthetic.ini", "general", "evasion_method", "rfgsm_k")

%run loss_graphs/generate_loss_figures.py loss_graphs/loss_progression_parameters_ipynb_synthetic.ini loss_progression_example<jupyter_output><empty_output><jupyter_text>Histograms (Figure 4 in Paper)<jupyter_code># Set is_cuda to be true if available
if torch.cuda.is_available():
    set_parameter("loss_graphs/histogram_parameters_ipynb_synthetic.ini", "general", "is_cuda", "True")
else:
    set_parameter("loss_graphs/histogram_parameters_ipynb_synthetic.ini", "general", "is_cuda", "False")
# Use the naturally-trained model with rfgsm as the adversarial method
set_parameter("loss_graphs/histogram_parameters_ipynb_synthetic.ini", "general", "model_weights_path", natural_model_path)
%run loss_graphs/generate_loss_figures.py loss_graphs/histogram_parameters_ipynb_synthetic.ini loss_progression_example
# Use the rfgsm-trained model with rfgsm as the adversarial method
set_parameter("loss_graphs/histogram_parameters_ipynb_synthetic.ini", "general", "model_weights_path", rfgsm_model_path)
%run loss_graphs/generate_loss_figures.py loss_graphs/histogram_parameters_ipynb_synthetic.ini loss_progression_example<jupyter_output><empty_output><jupyter_text>Loss Landscapes (Figure 5 in Paper)<jupyter_code># Set is_cuda to be true if available
if torch.cuda.is_available():
    set_parameter("loss_3d_visualization/loss_visual_params_ipynb_synthetic.ini", "general", "is_cuda", "True")
else:
    set_parameter("loss_3d_visualization/loss_visual_params_ipynb_synthetic.ini", "general", "is_cuda", "False")
# Natural model with all adversarial examples for loss calculation

set_parameter("loss_3d_visualization/loss_visual_params_ipynb_synthetic.ini", "general", "model_weights_path", natural_model_path)
set_parameter("loss_3d_visualization/loss_visual_params_ipynb_synthetic.ini", "general", "training_method", "natural")

%run loss_3d_visualization/loss_visualization.py loss_3d_visualization/loss_visual_params_ipynb_synthetic.ini synthetic_data_example
# Using only malicious and benign vectors for loss calculation
%run loss_3d_visualization/loss_visualization.py loss_3d_visualization/loss_visual_params_ipynb_synthetic.ini synthetic_data_example natural
# rfgsm model with all adversarial examples for loss calculation

set_parameter("loss_3d_visualization/loss_visual_params_ipynb_synthetic.ini", "general", "model_weights_path", rfgsm_model_path)
set_parameter("loss_3d_visualization/loss_visual_params_ipynb_synthetic.ini", "general", "training_method", "rfgsm_k")

%run loss_3d_visualization/loss_visualization.py loss_3d_visualization/loss_visual_params_ipynb_synthetic.ini synthetic_data_example
# Using rfgsm_k generated vectors along with benign and malicious for loss calculation
%run loss_3d_visualization/loss_visualization.py loss_3d_visualization/loss_visual_params_ipynb_synthetic.ini synthetic_data_example rfgsm_k<jupyter_output><empty_output><jupyter_text>Self-Organizing Maps (Figure 5 in Paper)  Training<jupyter_code># Set is_cuda to be false for somoclu due to conda installation
set_parameter("som/som_parameters_training_ipynb_synthetic.ini", "general", "is_cuda", "False")
# Train the som using all vectors
%run som/train_som.py som/som_parameters_training_ipynb_synthetic.ini
som_pickle_file = "malicious_benign_dfgsm_rfgsm_bga_bca_100_points_25_epochs_50_by_50.pkl"<jupyter_output><empty_output><jupyter_text>Decision Boundary<jupyter_code># Set is_cuda to be true if available
if torch.cuda.is_available():
    set_parameter("som/som_parameters_map_ipynb_synthetic.ini", "general", "is_cuda", "True")
else:
    set_parameter("som/som_parameters_map_ipynb_synthetic.ini", "general", "is_cuda", "False")
%run som/som_decision_map.py som/som_parameters_map_ipynb_synthetic.ini<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09097824433287692, 'fraction_numerical': 0.004107713372889092, 'mean_word_length': 10.996350364963504, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '411000', 'license': 'MIT', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2175, 'n_words': 365, 'path': 'jupyter_tutorial.ipynb', 'repo_name': 'ALFA-group/adv-malware-viz', 'size': '6573'}