phanerozoic commited on
Commit
2e4fb7c
Β·
verified Β·
1 Parent(s): 936d6fe

Rename from tiny-6OutOf8-verified

Browse files
Files changed (4) hide show
  1. README.md +80 -0
  2. config.json +22 -0
  3. model.py +45 -0
  4. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - pytorch
5
+ - safetensors
6
+ - threshold-logic
7
+ - neuromorphic
8
+ ---
9
+
10
+ # threshold-6outof8
11
+
12
+ Supermajority detector. Fires when 6 or more of 8 inputs are set (75%+).
13
+
14
+ ## Circuit
15
+
16
+ ```
17
+ xβ‚€ x₁ xβ‚‚ x₃ xβ‚„ xβ‚… x₆ x₇
18
+ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
19
+ β””β”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”Όβ”€β”€β”΄β”€β”€β”΄β”€β”€β”΄β”€β”€β”˜
20
+ β–Ό
21
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
22
+ β”‚ w: all 1β”‚
23
+ β”‚ b: -6 β”‚
24
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
25
+ β”‚
26
+ β–Ό
27
+ HW β‰₯ 6
28
+ ```
29
+
30
+ ## Mechanism
31
+
32
+ - Sum = (number of 1s) - 6
33
+ - Fires when Hamming weight β‰₯ 6
34
+
35
+ A 75% threshold. Tolerates up to 2 missing inputs.
36
+
37
+ ## k-out-of-8 Family
38
+
39
+ | Circuit | Bias | Fires when |
40
+ |---------|------|------------|
41
+ | ... | ... | ... |
42
+ | 5-out-of-8 | -5 | HW β‰₯ 5 |
43
+ | **6-out-of-8** | **-6** | **HW β‰₯ 6 (this)** |
44
+ | 7-out-of-8 | -7 | HW β‰₯ 7 |
45
+ | 8-out-of-8 | -8 | HW = 8 |
46
+
47
+ ## Parameters
48
+
49
+ | | |
50
+ |---|---|
51
+ | Weights | [1, 1, 1, 1, 1, 1, 1, 1] |
52
+ | Bias | -6 |
53
+ | Total | 9 parameters |
54
+
55
+ ## Usage
56
+
57
+ ```python
58
+ from safetensors.torch import load_file
59
+ import torch
60
+
61
+ w = load_file('model.safetensors')
62
+
63
+ def at_least_6(bits):
64
+ inputs = torch.tensor([float(b) for b in bits])
65
+ return int((inputs * w['weight']).sum() + w['bias'] >= 0)
66
+ ```
67
+
68
+ ## Files
69
+
70
+ ```
71
+ threshold-6outof8/
72
+ β”œβ”€β”€ model.safetensors
73
+ β”œβ”€β”€ model.py
74
+ β”œβ”€β”€ config.json
75
+ └── README.md
76
+ ```
77
+
78
+ ## License
79
+
80
+ MIT
config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "threshold_network",
3
+ "task": "6_out_of_8_threshold",
4
+ "architecture": "8 -> 1",
5
+ "input_size": 8,
6
+ "output_size": 1,
7
+ "num_neurons": 1,
8
+ "num_parameters": 9,
9
+ "threshold": 6,
10
+ "activation": "heaviside",
11
+ "weight_constraints": "integer",
12
+ "verification": {
13
+ "method": "coq_proof",
14
+ "exhaustive": true,
15
+ "inputs_tested": 256
16
+ },
17
+ "accuracy": {
18
+ "all_inputs": "256/256",
19
+ "percentage": 100.0
20
+ },
21
+ "github": "https://github.com/CharlesCNorton/coq-circuits"
22
+ }
model.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Threshold Network for 6-out-of-8 Gate
3
+
4
+ A formally verified single-neuron threshold network.
5
+ Outputs 1 when at least 6 of the 8 inputs are true.
6
+ """
7
+
8
+ import torch
9
+ from safetensors.torch import load_file
10
+
11
+
12
+ class Threshold6OutOf8:
13
+ """
14
+ 6-out-of-8 threshold gate.
15
+
16
+ Circuit: output = (sum of inputs - 6 >= 0)
17
+ Fires when hamming weight >= 6.
18
+ """
19
+
20
+ def __init__(self, weights_dict):
21
+ self.weight = weights_dict['weight']
22
+ self.bias = weights_dict['bias']
23
+
24
+ def __call__(self, bits):
25
+ inputs = torch.tensor([float(b) for b in bits])
26
+ weighted_sum = (inputs * self.weight).sum() + self.bias
27
+ return (weighted_sum >= 0).float()
28
+
29
+ @classmethod
30
+ def from_safetensors(cls, path="model.safetensors"):
31
+ return cls(load_file(path))
32
+
33
+
34
+ if __name__ == "__main__":
35
+ weights = load_file("model.safetensors")
36
+ model = Threshold6OutOf8(weights)
37
+
38
+ print("6-out-of-8 Gate Tests:")
39
+ print("-" * 35)
40
+ for hw in range(9):
41
+ bits = [1]*hw + [0]*(8-hw)
42
+ out = int(model(bits).item())
43
+ expected = 1 if hw >= 6 else 0
44
+ status = "OK" if out == expected else "FAIL"
45
+ print(f"HW={hw}: {out} [{status}]")
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6a60631af49bc478f9652cf48d2abe1632040c9e4a905e029efbf49a2c5a7021
3
+ size 164