forgeproof-cli 0.2.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.
Files changed (89) hide show
  1. forge_gate/__init__.py +44 -0
  2. forge_gate/_deprecated_cli.py +16 -0
  3. forgeproof/__init__.py +3 -0
  4. forgeproof/catalog.py +110 -0
  5. forgeproof/cli.py +560 -0
  6. forgeproof/config.py +339 -0
  7. forgeproof/data/gate_catalog.json +66 -0
  8. forgeproof/data/host_sets.json +7 -0
  9. forgeproof/debug_caller.py +271 -0
  10. forgeproof/debug_core.py +368 -0
  11. forgeproof/fixture_engine.py +81 -0
  12. forgeproof/fixtures/__init__.py +19 -0
  13. forgeproof/fixtures/decision_tree_id3.py +90 -0
  14. forgeproof/fixtures/gradient_descent_momentum.py +73 -0
  15. forgeproof/fixtures/kmeans_clustering.py +98 -0
  16. forgeproof/fixtures/knn_classifier.py +79 -0
  17. forgeproof/fixtures/linear_regression_gd.py +77 -0
  18. forgeproof/fixtures/logistic_regression.py +85 -0
  19. forgeproof/fixtures/naive_bayes_text.py +114 -0
  20. forgeproof/fixtures/perceptron.py +84 -0
  21. forgeproof/fixtures/polynomial_regression.py +67 -0
  22. forgeproof/fixtures/ridge_regression_normal_eq.py +75 -0
  23. forgeproof/ledger.py +633 -0
  24. forgeproof/lens_tools/__init__.py +11 -0
  25. forgeproof/lens_tools/guard_lens.py +1250 -0
  26. forgeproof/lens_tools/invariant_contracts/linear_regression_gd.json +74 -0
  27. forgeproof/lens_tools/invariant_contracts/polynomial_regression.json +86 -0
  28. forgeproof/lens_tools/invariant_contracts/ridge_regression_normal_eq.json +86 -0
  29. forgeproof/lens_tools/invariant_gate.py +199 -0
  30. forgeproof/lens_tools/metamorphic/__init__.py +9 -0
  31. forgeproof/lens_tools/metamorphic/relations.py +962 -0
  32. forgeproof/lens_tools/metamorphic/runner.py +112 -0
  33. forgeproof/lens_tools/twin_consensus.py +395 -0
  34. forgeproof/lenses.py +923 -0
  35. forgeproof/paths.py +56 -0
  36. forgeproof/reference/ORIGIN.md +29 -0
  37. forgeproof/reference/decision_tree_id3.py +197 -0
  38. forgeproof/reference/gradient_descent_momentum.py +141 -0
  39. forgeproof/reference/kmeans_clustering.py +139 -0
  40. forgeproof/reference/knn_classifier.py +118 -0
  41. forgeproof/reference/linear_regression_gd.py +106 -0
  42. forgeproof/reference/logistic_regression.py +141 -0
  43. forgeproof/reference/naive_bayes_text.py +152 -0
  44. forgeproof/reference/perceptron.py +123 -0
  45. forgeproof/reference/polynomial_regression.py +125 -0
  46. forgeproof/reference/ridge_regression_normal_eq.py +165 -0
  47. forgeproof/runner.py +147 -0
  48. forgeproof/scout/__init__.py +7 -0
  49. forgeproof/scout/behaviour.py +365 -0
  50. forgeproof/scout/box.py +581 -0
  51. forgeproof/scout/cards.py +180 -0
  52. forgeproof/scout/contract.py +37 -0
  53. forgeproof/scout/corpus.py +104 -0
  54. forgeproof/scout/embed.py +217 -0
  55. forgeproof/scout/engines/__init__.py +1 -0
  56. forgeproof/scout/engines/chaos.py +454 -0
  57. forgeproof/scout/engines/chaos_port.py +1331 -0
  58. forgeproof/scout/engines/chaos_runner.py +178 -0
  59. forgeproof/scout/engines/executor_port.py +239 -0
  60. forgeproof/scout/envfit.py +54 -0
  61. forgeproof/scout/experience.py +161 -0
  62. forgeproof/scout/fetchproxy.py +368 -0
  63. forgeproof/scout/ghcache.py +395 -0
  64. forgeproof/scout/ghpool.py +253 -0
  65. forgeproof/scout/ghsearch.py +248 -0
  66. forgeproof/scout/ids.py +82 -0
  67. forgeproof/scout/intent_lens.py +170 -0
  68. forgeproof/scout/learn.py +583 -0
  69. forgeproof/scout/meaning_lens.py +231 -0
  70. forgeproof/scout/outcomes.py +42 -0
  71. forgeproof/scout/plant.py +327 -0
  72. forgeproof/scout/ratify.py +214 -0
  73. forgeproof/scout/report.py +448 -0
  74. forgeproof/scout/rule2.py +177 -0
  75. forgeproof/scout/shape.py +107 -0
  76. forgeproof/scout/shape_lens.py +71 -0
  77. forgeproof/scout/signature.py +52 -0
  78. forgeproof/scout/slots.py +39 -0
  79. forgeproof/scout/upstream_facts.py +536 -0
  80. forgeproof/unsupported.py +83 -0
  81. forgeproof/verifier.py +208 -0
  82. forgeproof/view_coverage.py +166 -0
  83. forgeproof_cli-0.2.0.dist-info/METADATA +285 -0
  84. forgeproof_cli-0.2.0.dist-info/RECORD +89 -0
  85. forgeproof_cli-0.2.0.dist-info/WHEEL +5 -0
  86. forgeproof_cli-0.2.0.dist-info/entry_points.txt +3 -0
  87. forgeproof_cli-0.2.0.dist-info/licenses/LICENSE +201 -0
  88. forgeproof_cli-0.2.0.dist-info/licenses/NOTICE +23 -0
  89. forgeproof_cli-0.2.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env python3
2
+ """Gate fixture for kmeans_clustering.
3
+
4
+ PASS is decided by clustering quality properties, not by matching the AURA
5
+ oracle's exact centroid coordinates.
6
+ """
7
+ import random
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _pkg = Path(__file__).resolve().parents[2]
12
+ if str(_pkg) not in sys.path:
13
+ sys.path.insert(0, str(_pkg))
14
+
15
+ from forgeproof.catalog import reference_path
16
+ from forgeproof.fixture_engine import approx_eq, emit, get_fn, load_module
17
+
18
+
19
+ def euclidean_distance(p1, p2):
20
+ return sum((p1[i] - p2[i]) ** 2 for i in range(len(p1))) ** 0.5
21
+
22
+
23
+ def intra_cluster_distance(X, centroids, assignments):
24
+ total = 0.0
25
+ for i in range(len(X)):
26
+ c = assignments[i]
27
+ total += euclidean_distance(X[i], centroids[c])
28
+ return total / len(X) if X else 0.0
29
+
30
+
31
+ def main():
32
+ if len(sys.argv) < 2:
33
+ print("usage: kmeans_clustering.py <user_file.py>", file=sys.stderr)
34
+ sys.exit(2)
35
+
36
+ user_path = sys.argv[1]
37
+ aura_path = str(reference_path("kmeans_clustering"))
38
+
39
+ user_mod = load_module(user_path, "user_impl")
40
+ aura_mod = load_module(aura_path, "aura_impl")
41
+
42
+ user_kmeans = get_fn(user_mod, "kmeans")
43
+ aura_kmeans = get_fn(aura_mod, "kmeans")
44
+
45
+ random.seed(42)
46
+ n_per_cluster = 20
47
+ X = []
48
+ for _ in range(n_per_cluster):
49
+ X.append([random.gauss(0, 0.5), random.gauss(0, 0.5)])
50
+ for _ in range(n_per_cluster):
51
+ X.append([random.gauss(5, 0.5), random.gauss(0, 0.5)])
52
+ for _ in range(n_per_cluster):
53
+ X.append([random.gauss(2.5, 0.5), random.gauss(4, 0.5)])
54
+
55
+ user_centroids, user_assignments = user_kmeans(X, k=3, max_iterations=100)
56
+ aura_centroids, aura_assignments = aura_kmeans(X, k=3, max_iterations=100)
57
+
58
+ user_intra = intra_cluster_distance(X, user_centroids, user_assignments)
59
+ aura_intra = intra_cluster_distance(X, aura_centroids, aura_assignments)
60
+
61
+ user_centroid_dists = []
62
+ for i in range(3):
63
+ for j in range(i + 1, 3):
64
+ user_centroid_dists.append(euclidean_distance(user_centroids[i], user_centroids[j]))
65
+ aura_centroid_dists = []
66
+ for i in range(3):
67
+ for j in range(i + 1, 3):
68
+ aura_centroid_dists.append(euclidean_distance(aura_centroids[i], aura_centroids[j]))
69
+
70
+ canonical_match = (
71
+ approx_eq(user_intra, aura_intra, rel_tol=0.1)
72
+ and approx_eq(min(user_centroid_dists), min(aura_centroid_dists), rel_tol=0.1)
73
+ )
74
+
75
+ metrics = {
76
+ "intra_cluster_distance": round(user_intra, 6),
77
+ "min_centroid_separation": round(min(user_centroid_dists), 6),
78
+ "canonical_match": canonical_match,
79
+ }
80
+
81
+ ok = (
82
+ user_intra < 2.0
83
+ and min(user_centroid_dists) > 2.0
84
+ )
85
+
86
+ status = "PASS" if ok else "FAIL"
87
+ reason = "k-means quality properties hold" if ok else "k-means quality properties fail"
88
+
89
+ emit({
90
+ "status": status,
91
+ "pattern": "kmeans_clustering",
92
+ "reason": reason,
93
+ "metrics": metrics,
94
+ })
95
+
96
+
97
+ if __name__ == "__main__":
98
+ main()
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env python3
2
+ """Gate fixture for knn_classifier.
3
+
4
+ PASS is decided by classification accuracy on a separable synthetic dataset,
5
+ not by matching the AURA oracle's exact predictions.
6
+ """
7
+ import random
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _pkg = Path(__file__).resolve().parents[2]
12
+ if str(_pkg) not in sys.path:
13
+ sys.path.insert(0, str(_pkg))
14
+
15
+ from forgeproof.catalog import reference_path
16
+ from forgeproof.fixture_engine import approx_eq, emit, get_fn, load_module
17
+
18
+
19
+ def main():
20
+ if len(sys.argv) < 2:
21
+ print("usage: knn_classifier.py <user_file.py>", file=sys.stderr)
22
+ sys.exit(2)
23
+
24
+ user_path = sys.argv[1]
25
+ aura_path = str(reference_path("knn_classifier"))
26
+
27
+ user_mod = load_module(user_path, "user_impl")
28
+ aura_mod = load_module(aura_path, "aura_impl")
29
+
30
+ user_fn = get_fn(user_mod, "knn_predict_batch")
31
+ aura_fn = get_fn(aura_mod, "knn_predict_batch")
32
+
33
+ random.seed(42)
34
+ n_train = 80
35
+ X_train, y_train = [], []
36
+ for _ in range(n_train):
37
+ label = random.choice([0, 1])
38
+ if label == 0:
39
+ X_train.append([random.gauss(0, 1.2), random.gauss(0, 1.2)])
40
+ else:
41
+ X_train.append([random.gauss(2.5, 1.2), random.gauss(0, 1.2)])
42
+ y_train.append(label)
43
+
44
+ n_test = 40
45
+ X_test, y_test = [], []
46
+ for _ in range(n_test):
47
+ label = random.choice([0, 1])
48
+ if label == 0:
49
+ X_test.append([random.gauss(0, 1.0), random.gauss(0, 1.0)])
50
+ else:
51
+ X_test.append([random.gauss(2.5, 1.0), random.gauss(0, 1.0)])
52
+ y_test.append(label)
53
+
54
+ user_preds = user_fn(X_test, X_train, y_train, k=5)
55
+ aura_preds = aura_fn(X_test, X_train, y_train, k=5)
56
+
57
+ user_accuracy = sum(user_preds[i] == y_test[i] for i in range(n_test)) / n_test
58
+ aura_accuracy = sum(aura_preds[i] == y_test[i] for i in range(n_test)) / n_test
59
+
60
+ canonical_match = approx_eq(user_accuracy, aura_accuracy, rel_tol=1e-5)
61
+
62
+ metrics = {
63
+ "accuracy": round(user_accuracy, 6),
64
+ "oracle_accuracy": round(aura_accuracy, 6),
65
+ "canonical_match": canonical_match,
66
+ }
67
+
68
+ ok = user_accuracy >= 0.75
69
+
70
+ emit({
71
+ "status": "PASS" if ok else "FAIL",
72
+ "pattern": "knn_classifier",
73
+ "reason": "kNN accuracy property holds" if ok else "kNN accuracy property fails",
74
+ "metrics": metrics,
75
+ })
76
+
77
+
78
+ if __name__ == "__main__":
79
+ main()
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env python3
2
+ """Gate fixture for linear_regression_gd.
3
+
4
+ PASS is decided by correctness properties against ground-truth data, not by
5
+ matching the AURA oracle's exact numerical path.
6
+ """
7
+ import random
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _pkg = Path(__file__).resolve().parents[2]
12
+ if str(_pkg) not in sys.path:
13
+ sys.path.insert(0, str(_pkg))
14
+
15
+ from forgeproof.catalog import reference_path
16
+ from forgeproof.fixture_engine import approx_eq, emit, get_fn, load_module
17
+
18
+
19
+ def main():
20
+ if len(sys.argv) < 2:
21
+ print("usage: linear_regression_gd.py <user_file.py>", file=sys.stderr)
22
+ sys.exit(2)
23
+
24
+ user_path = sys.argv[1]
25
+ aura_path = str(reference_path("linear_regression_gd"))
26
+
27
+ user_mod = load_module(user_path, "user_impl")
28
+ aura_mod = load_module(aura_path, "aura_impl")
29
+
30
+ user_fn = get_fn(user_mod, "linear_regression_gd")
31
+ aura_fn = get_fn(aura_mod, "linear_regression_gd")
32
+
33
+ random.seed(42)
34
+ n_samples = 30
35
+ X = [[random.uniform(-5, 5), random.uniform(-5, 5)] for _ in range(n_samples)]
36
+ y = [2.0 * X[i][0] + 3.0 * X[i][1] + random.gauss(0, 0.5) for i in range(n_samples)]
37
+
38
+ user_weights, user_bias = user_fn(X, y, learning_rate=0.01, iterations=200)
39
+ aura_weights, aura_bias = aura_fn(X, y, learning_rate=0.01, iterations=200)
40
+
41
+ # Compute R² using user weights
42
+ predictions = [user_bias + sum(user_weights[j] * X[i][j] for j in range(2)) for i in range(n_samples)]
43
+ mean_y = sum(y) / len(y)
44
+ ss_res = sum((predictions[i] - y[i]) ** 2 for i in range(n_samples))
45
+ ss_tot = sum((y[i] - mean_y) ** 2 for i in range(n_samples))
46
+ r2 = 1.0 - (ss_res / ss_tot) if ss_tot > 0 else 0.0
47
+
48
+ # Property check: the underlying data was generated from y ≈ 2*x1 + 3*x2.
49
+ canonical_match = (
50
+ approx_eq(user_weights, aura_weights, rel_tol=1e-3)
51
+ and approx_eq(user_bias, aura_bias, rel_tol=1e-3)
52
+ )
53
+
54
+ metrics = {
55
+ "r2": round(r2, 6),
56
+ "weight_0": round(user_weights[0], 6),
57
+ "weight_1": round(user_weights[1], 6),
58
+ "bias": round(user_bias, 6),
59
+ "canonical_match": canonical_match,
60
+ }
61
+
62
+ ok = (
63
+ r2 > 0.8
64
+ and abs(user_weights[0] - 2.0) < 0.5
65
+ and abs(user_weights[1] - 3.0) < 0.5
66
+ )
67
+
68
+ emit({
69
+ "status": "PASS" if ok else "FAIL",
70
+ "pattern": "linear_regression_gd",
71
+ "reason": "Linear regression quality properties hold" if ok else "Linear regression quality properties fail",
72
+ "metrics": metrics,
73
+ })
74
+
75
+
76
+ if __name__ == "__main__":
77
+ main()
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env python3
2
+ """Gate fixture for logistic_regression.
3
+
4
+ PASS is decided by classification quality and correctness properties, not by
5
+ matching the AURA oracle's exact numerical path.
6
+ """
7
+ import random
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _pkg = Path(__file__).resolve().parents[2]
12
+ if str(_pkg) not in sys.path:
13
+ sys.path.insert(0, str(_pkg))
14
+
15
+ from forgeproof.catalog import reference_path
16
+ from forgeproof.fixture_engine import approx_eq, emit, get_fn, load_module
17
+
18
+
19
+ def main():
20
+ if len(sys.argv) < 2:
21
+ print("usage: logistic_regression.py <user_file.py>", file=sys.stderr)
22
+ sys.exit(2)
23
+
24
+ user_path = sys.argv[1]
25
+ aura_path = str(reference_path("logistic_regression"))
26
+
27
+ user_mod = load_module(user_path, "user_impl")
28
+ aura_mod = load_module(aura_path, "aura_impl")
29
+
30
+ user_fit = get_fn(user_mod, "logistic_regression_fit")
31
+ user_predict = get_fn(user_mod, "logistic_regression_predict")
32
+ aura_fit = get_fn(aura_mod, "logistic_regression_fit")
33
+ aura_predict = get_fn(aura_mod, "logistic_regression_predict")
34
+
35
+ random.seed(42)
36
+ n_samples = 80
37
+ X, y = [], []
38
+ for _ in range(n_samples):
39
+ label = random.choice([0, 1])
40
+ if label == 0:
41
+ X.append([random.gauss(-1.5, 1.2), random.gauss(-1.5, 1.2)])
42
+ else:
43
+ X.append([random.gauss(1.5, 1.2), random.gauss(1.5, 1.2)])
44
+ y.append(label)
45
+
46
+ # Add class overlap via label noise (~8% flips) so the task is not trivially
47
+ # separable. A correct implementation scores ~0.85; broken ones drop to ~0.5.
48
+ for idx in random.sample(range(n_samples), n_samples // 12):
49
+ y[idx] = 1 - y[idx]
50
+
51
+ user_w, user_b = user_fit(X, y, learning_rate=0.1, iterations=200)
52
+ aura_w, aura_b = aura_fit(X, y, learning_rate=0.1, iterations=200)
53
+
54
+ user_preds = user_predict(X, user_w, user_b)
55
+ aura_preds = aura_predict(X, aura_w, aura_b)
56
+
57
+ user_accuracy = sum(user_preds[i] == y[i] for i in range(n_samples)) / n_samples
58
+ aura_accuracy = sum(aura_preds[i] == y[i] for i in range(n_samples)) / n_samples
59
+
60
+ canonical_match = (
61
+ approx_eq(user_accuracy, aura_accuracy, rel_tol=1e-5)
62
+ and approx_eq(user_w, aura_w, rel_tol=1e-2)
63
+ and approx_eq(user_b, aura_b, rel_tol=1e-2)
64
+ )
65
+
66
+ metrics = {
67
+ "accuracy": round(user_accuracy, 6),
68
+ "oracle_accuracy": round(aura_accuracy, 6),
69
+ "weight_0": round(user_w[0], 6),
70
+ "weight_1": round(user_w[1], 6),
71
+ "canonical_match": canonical_match,
72
+ }
73
+
74
+ ok = user_accuracy >= 0.75
75
+
76
+ emit({
77
+ "status": "PASS" if ok else "FAIL",
78
+ "pattern": "logistic_regression",
79
+ "reason": "Logistic regression accuracy property holds" if ok else "Logistic regression accuracy property fails",
80
+ "metrics": metrics,
81
+ })
82
+
83
+
84
+ if __name__ == "__main__":
85
+ main()
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env python3
2
+ """Gate fixture for naive_bayes_text.
3
+
4
+ PASS is decided by text-classification quality properties, not by matching the
5
+ AURA oracle's exact probability tables.
6
+ """
7
+ import random
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _pkg = Path(__file__).resolve().parents[2]
12
+ if str(_pkg) not in sys.path:
13
+ sys.path.insert(0, str(_pkg))
14
+
15
+ from forgeproof.catalog import reference_path
16
+ from forgeproof.fixture_engine import approx_eq, emit, get_fn, load_module
17
+
18
+
19
+ def main():
20
+ if len(sys.argv) < 2:
21
+ print("usage: naive_bayes_text.py <user_file.py>", file=sys.stderr)
22
+ sys.exit(2)
23
+
24
+ user_path = sys.argv[1]
25
+ aura_path = str(reference_path("naive_bayes_text"))
26
+
27
+ user_mod = load_module(user_path, "user_impl")
28
+ aura_mod = load_module(aura_path, "aura_impl")
29
+
30
+ user_train = get_fn(user_mod, "naive_bayes_train")
31
+ user_predict = get_fn(user_mod, "naive_bayes_predict")
32
+ aura_train = get_fn(aura_mod, "naive_bayes_train")
33
+ aura_predict = get_fn(aura_mod, "naive_bayes_predict")
34
+
35
+ random.seed(42)
36
+ spam_words = ["cheap", "free", "buy", "offer", "click", "win", "prize"]
37
+ ham_words = ["meeting", "report", "data", "project", "deadline", "team", "review"]
38
+ shared_words = ["the", "and", "of", "to", "a", "for"]
39
+
40
+ texts, labels = [], []
41
+ for _ in range(12):
42
+ label = 1
43
+ words = []
44
+ for _ in range(random.randint(4, 6)):
45
+ r = random.random()
46
+ if r < 0.55:
47
+ words.append(random.choice(spam_words))
48
+ elif r < 0.80:
49
+ words.append(random.choice(shared_words))
50
+ else:
51
+ # Cross-class noise: ham-looking word in a spam doc.
52
+ words.append(random.choice(ham_words))
53
+ texts.append(words)
54
+ labels.append(label)
55
+ for _ in range(12):
56
+ label = 0
57
+ words = []
58
+ for _ in range(random.randint(4, 6)):
59
+ r = random.random()
60
+ if r < 0.55:
61
+ words.append(random.choice(ham_words))
62
+ elif r < 0.80:
63
+ words.append(random.choice(shared_words))
64
+ else:
65
+ # Cross-class noise: spam-looking word in a ham doc.
66
+ words.append(random.choice(spam_words))
67
+ texts.append(words)
68
+ labels.append(label)
69
+
70
+ user_priors, user_probs = user_train(texts, labels)
71
+ aura_priors, aura_probs = aura_train(texts, labels)
72
+
73
+ correct = 0
74
+ for i in range(len(texts)):
75
+ if user_predict(texts[i], user_priors, user_probs) == labels[i]:
76
+ correct += 1
77
+ user_accuracy = correct / len(texts)
78
+
79
+ aura_correct = 0
80
+ for i in range(len(texts)):
81
+ if aura_predict(texts[i], aura_priors, aura_probs) == labels[i]:
82
+ aura_correct += 1
83
+ aura_accuracy = aura_correct / len(texts)
84
+
85
+ pred_spam = user_predict(["cheap", "free", "buy"], user_priors, user_probs)
86
+ pred_ham = user_predict(["meeting", "data", "report"], user_priors, user_probs)
87
+
88
+ priors_match = approx_eq(user_priors, aura_priors, rel_tol=1e-4)
89
+ probs_match = approx_eq(user_probs, aura_probs, rel_tol=1e-4)
90
+
91
+ metrics = {
92
+ "accuracy": round(user_accuracy, 6),
93
+ "oracle_accuracy": round(aura_accuracy, 6),
94
+ "pred_spam": pred_spam,
95
+ "pred_ham": pred_ham,
96
+ "canonical_match": priors_match and probs_match,
97
+ }
98
+
99
+ ok = (
100
+ user_accuracy >= 0.75
101
+ and pred_spam == 1
102
+ and pred_ham == 0
103
+ )
104
+
105
+ emit({
106
+ "status": "PASS" if ok else "FAIL",
107
+ "pattern": "naive_bayes_text",
108
+ "reason": "Naive Bayes text classification properties hold" if ok else "Naive Bayes text classification properties fail",
109
+ "metrics": metrics,
110
+ })
111
+
112
+
113
+ if __name__ == "__main__":
114
+ main()
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env python3
2
+ """Gate fixture for perceptron.
3
+
4
+ PASS is decided by classification accuracy on a linearly separable synthetic
5
+ dataset, not by matching the AURA oracle's exact weight vector.
6
+ """
7
+ import random
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _pkg = Path(__file__).resolve().parents[2]
12
+ if str(_pkg) not in sys.path:
13
+ sys.path.insert(0, str(_pkg))
14
+
15
+ from forgeproof.catalog import reference_path
16
+ from forgeproof.fixture_engine import approx_eq, emit, get_fn, load_module
17
+
18
+
19
+ def main():
20
+ if len(sys.argv) < 2:
21
+ print("usage: perceptron.py <user_file.py>", file=sys.stderr)
22
+ sys.exit(2)
23
+
24
+ user_path = sys.argv[1]
25
+ aura_path = str(reference_path("perceptron"))
26
+
27
+ user_mod = load_module(user_path, "user_impl")
28
+ aura_mod = load_module(aura_path, "aura_impl")
29
+
30
+ user_fit = get_fn(user_mod, "perceptron_fit")
31
+ user_predict = get_fn(user_mod, "perceptron_predict")
32
+ aura_fit = get_fn(aura_mod, "perceptron_fit")
33
+ aura_predict = get_fn(aura_mod, "perceptron_predict")
34
+
35
+ random.seed(42)
36
+ n_samples = 80
37
+ X, y = [], []
38
+ for _ in range(n_samples):
39
+ label = random.choice([0, 1])
40
+ x1 = random.uniform(-3, 3)
41
+ # Overlapping classes around the boundary x2 = x1. A correct perceptron
42
+ # scores ~0.88; a broken one that ignores the data scores ~0.55.
43
+ noise = random.gauss(0, 0.8)
44
+ if label == 0:
45
+ x2 = x1 - 0.9 + noise
46
+ else:
47
+ x2 = x1 + 0.9 + noise
48
+ X.append([x1, x2])
49
+ y.append(label)
50
+
51
+ user_w, user_b = user_fit(X, y, learning_rate=1.0, max_iterations=100)
52
+ aura_w, aura_b = aura_fit(X, y, learning_rate=1.0, max_iterations=100)
53
+
54
+ user_preds = user_predict(X, user_w, user_b)
55
+ aura_preds = user_predict(X, aura_w, aura_b)
56
+
57
+ user_accuracy = sum(user_preds[i] == y[i] for i in range(n_samples)) / n_samples
58
+ aura_accuracy = sum(aura_preds[i] == y[i] for i in range(n_samples)) / n_samples
59
+
60
+ canonical_match = (
61
+ approx_eq(user_accuracy, aura_accuracy, rel_tol=1e-5)
62
+ and approx_eq(user_w, aura_w, rel_tol=1e-2)
63
+ )
64
+
65
+ metrics = {
66
+ "accuracy": round(user_accuracy, 6),
67
+ "oracle_accuracy": round(aura_accuracy, 6),
68
+ "weight_0": round(user_w[0], 6),
69
+ "weight_1": round(user_w[1], 6),
70
+ "canonical_match": canonical_match,
71
+ }
72
+
73
+ ok = user_accuracy >= 0.75
74
+
75
+ emit({
76
+ "status": "PASS" if ok else "FAIL",
77
+ "pattern": "perceptron",
78
+ "reason": "Perceptron accuracy property holds" if ok else "Perceptron accuracy property fails",
79
+ "metrics": metrics,
80
+ })
81
+
82
+
83
+ if __name__ == "__main__":
84
+ main()
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env python3
2
+ """Gate fixture for polynomial_regression.
3
+
4
+ PASS is decided by how well recovered coefficients match the planted ground-truth
5
+ polynomial, not by matching the AURA oracle's exact numerical path.
6
+ """
7
+ import random
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _pkg = Path(__file__).resolve().parents[2]
12
+ if str(_pkg) not in sys.path:
13
+ sys.path.insert(0, str(_pkg))
14
+
15
+ from forgeproof.catalog import reference_path
16
+ from forgeproof.fixture_engine import approx_eq, emit, get_fn, load_module
17
+
18
+
19
+ def main():
20
+ if len(sys.argv) < 2:
21
+ print("usage: polynomial_regression.py <user_file.py>", file=sys.stderr)
22
+ sys.exit(2)
23
+
24
+ user_path = sys.argv[1]
25
+ aura_path = str(reference_path("polynomial_regression"))
26
+
27
+ user_mod = load_module(user_path, "user_impl")
28
+ aura_mod = load_module(aura_path, "aura_impl")
29
+
30
+ user_fit = get_fn(user_mod, "fit_polynomial")
31
+ user_eval = get_fn(user_mod, "eval_poly")
32
+ aura_fit = get_fn(aura_mod, "fit_polynomial")
33
+ aura_eval = get_fn(aura_mod, "eval_poly")
34
+
35
+ random.seed(42)
36
+ true_coeffs = [2.0, 3.0, 0.5]
37
+ x_vals = [float(i) * 0.5 for i in range(20)]
38
+ y_vals = [user_eval(true_coeffs, x) + random.gauss(0, 0.1) for x in x_vals]
39
+
40
+ user_coeffs = user_fit(x_vals, y_vals, 2)
41
+ aura_coeffs = aura_fit(x_vals, y_vals, 2)
42
+
43
+ user_pred = [user_eval(user_coeffs, x) for x in x_vals]
44
+ mse = sum((user_pred[i] - y_vals[i]) ** 2 for i in range(len(y_vals))) / len(y_vals)
45
+
46
+ canonical_match = approx_eq(user_coeffs, aura_coeffs, rel_tol=1e-4)
47
+
48
+ metrics = {
49
+ "mse": round(mse, 6),
50
+ "coeff_0": round(user_coeffs[0], 6),
51
+ "coeff_1": round(user_coeffs[1], 6),
52
+ "coeff_2": round(user_coeffs[2], 6),
53
+ "canonical_match": canonical_match,
54
+ }
55
+
56
+ ok = all(abs(user_coeffs[i] - true_coeffs[i]) < 0.2 for i in range(3))
57
+
58
+ emit({
59
+ "status": "PASS" if ok else "FAIL",
60
+ "pattern": "polynomial_regression",
61
+ "reason": "Polynomial coefficients recover planted values" if ok else "Polynomial coefficients do not recover planted values",
62
+ "metrics": metrics,
63
+ })
64
+
65
+
66
+ if __name__ == "__main__":
67
+ main()
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env python3
2
+ """Gate fixture for ridge_regression_normal_eq.
3
+
4
+ PASS is decided by regression quality and recovery of the planted weights, not
5
+ by matching the AURA oracle's exact numerical path.
6
+ """
7
+ import random
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _pkg = Path(__file__).resolve().parents[2]
12
+ if str(_pkg) not in sys.path:
13
+ sys.path.insert(0, str(_pkg))
14
+
15
+ from forgeproof.catalog import reference_path
16
+ from forgeproof.fixture_engine import approx_eq, emit, get_fn, load_module
17
+
18
+
19
+ def main():
20
+ if len(sys.argv) < 2:
21
+ print("usage: ridge_regression_normal_eq.py <user_file.py>", file=sys.stderr)
22
+ sys.exit(2)
23
+
24
+ user_path = sys.argv[1]
25
+ aura_path = str(reference_path("ridge_regression_normal_eq"))
26
+
27
+ user_mod = load_module(user_path, "user_impl")
28
+ aura_mod = load_module(aura_path, "aura_impl")
29
+
30
+ user_ridge = get_fn(user_mod, "ridge_regression_normal_eq")
31
+ user_predict = get_fn(user_mod, "ridge_regression_predict")
32
+ aura_ridge = get_fn(aura_mod, "ridge_regression_normal_eq")
33
+ aura_predict = get_fn(aura_mod, "ridge_regression_predict")
34
+
35
+ random.seed(42)
36
+ n_samples = 30
37
+ n_features = 3
38
+ X = [[random.uniform(-5, 5) for _ in range(n_features)] for _ in range(n_samples)]
39
+ true_weights = [2.0, 3.0, -1.0]
40
+ y = [sum(true_weights[j] * X[i][j] for j in range(n_features)) + random.gauss(0, 0.5)
41
+ for i in range(n_samples)]
42
+
43
+ user_weights = user_ridge(X, y, lambda_reg=0.01)
44
+ aura_weights = aura_ridge(X, y, lambda_reg=0.01)
45
+
46
+ user_preds = user_predict(X, user_weights)
47
+ ss_res = sum((user_preds[i] - y[i]) ** 2 for i in range(n_samples))
48
+ ss_tot = sum((y[i] - sum(y) / len(y)) ** 2 for i in range(n_samples))
49
+ r2 = 1.0 - (ss_res / ss_tot) if ss_tot > 0 else 0.0
50
+
51
+ canonical_match = approx_eq(user_weights, aura_weights, rel_tol=1e-4)
52
+
53
+ metrics = {
54
+ "r2": round(r2, 6),
55
+ "weight_0": round(user_weights[0], 6),
56
+ "weight_1": round(user_weights[1], 6),
57
+ "weight_2": round(user_weights[2], 6),
58
+ "canonical_match": canonical_match,
59
+ }
60
+
61
+ ok = (
62
+ r2 > 0.8
63
+ and all(abs(user_weights[i] - true_weights[i]) < 1.0 for i in range(n_features))
64
+ )
65
+
66
+ emit({
67
+ "status": "PASS" if ok else "FAIL",
68
+ "pattern": "ridge_regression_normal_eq",
69
+ "reason": "Ridge regression quality and weight-recovery properties hold" if ok else "Ridge regression quality or weight-recovery properties fail",
70
+ "metrics": metrics,
71
+ })
72
+
73
+
74
+ if __name__ == "__main__":
75
+ main()