Download tests/test_graph_feature_classifiers.py from Dhruv1000/tracegrpo: direct link, hf CLI and curl.
- Browser
- Download file 901 Bytes
-
https://huggingface.co/Dhruv1000/tracegrpo/resolve/main/tests/test_graph_feature_classifiers.py
- Command line
-
hf download hf://Dhruv1000/tracegrpo/tests/test_graph_feature_classifiers.py
-
curl -L -o test_graph_feature_classifiers.py https://huggingface.co/Dhruv1000/tracegrpo/resolve/main/tests/test_graph_feature_classifiers.py
901 Bytes
| import numpy as np | |
| from scripts.eval_graph_feature_classifier import metrics as graph_metrics | |
| from scripts.run_graph_text_stack import score as stack_metrics | |
| def test_graph_metrics_compute_both_class_accuracies(): | |
| y = np.array([0, 1, 0, 1], dtype=np.int8) | |
| pred = np.array([0, 1, 1, 0], dtype=np.int8) | |
| result = graph_metrics(y, pred, pair_count=2) | |
| assert result["accuracy"] == 0.5 | |
| assert result["safe_accuracy"] == 0.5 | |
| assert result["vulnerable_accuracy"] == 0.5 | |
| assert result["pair_pass_at_1"] == 0.5 | |
| def test_stack_metric_flags_safe_collapse(): | |
| y = np.array([0, 1, 0, 1], dtype=np.int8) | |
| pred = np.zeros(4, dtype=np.int8) | |
| result = stack_metrics(y, pred, n_pairs=2) | |
| assert result["safe_accuracy"] == 1.0 | |
| assert result["vulnerable_accuracy"] == 0.0 | |
| assert result["predicted_vulnerable_fraction"] == 0.0 | |
| assert result["pair_pass_at_1"] == 0.0 | |