| license: mit | |
| tags: | |
| - pytorch | |
| - safetensors | |
| - threshold-logic | |
| - neuromorphic | |
| # threshold-and | |
| A 2-of-2 threshold gate. Both inputs must be active to reach the firing threshold. | |
| ## Circuit | |
| ``` | |
| x y | |
| β β | |
| βββ¬ββ | |
| βΌ | |
| βββββββββ | |
| β w: 1,1β | |
| β b: -2 β | |
| βββββββββ | |
| β | |
| βΌ | |
| AND(x,y) | |
| ``` | |
| ## Mechanism | |
| Each input contributes +1 to the sum. The bias of -2 means exactly two contributions are required to reach zero: | |
| | x | y | sum | output | | |
| |---|---|-----|--------| | |
| | 0 | 0 | -2 | 0 | | |
| | 0 | 1 | -1 | 0 | | |
| | 1 | 0 | -1 | 0 | | |
| | 1 | 1 | 0 | 1 | | |
| The bias acts as a vote threshold. With bias -2, you need 2 votes. | |
| ## Parameters | |
| | | | | |
| |---|---| | |
| | Weights | [1, 1] | | |
| | Bias | -2 | | |
| | Total | 3 parameters | | |
| ## Optimality | |
| Exhaustive enumeration of all 129 weight configurations at magnitudes 0-4 confirms this circuit is **already at minimum magnitude (4)**. There is exactly one valid configuration at magnitude 4, and no valid configurations exist below it. | |
| ## Properties | |
| - Linearly separable (unlike XOR) | |
| - Commutative, associative, idempotent | |
| - Generalizes to n-input AND with weights all 1, bias -n | |
| ## Usage | |
| ```python | |
| from safetensors.torch import load_file | |
| import torch | |
| w = load_file('model.safetensors') | |
| def and_gate(x, y): | |
| inputs = torch.tensor([float(x), float(y)]) | |
| return int((inputs * w['weight']).sum() + w['bias'] >= 0) | |
| ``` | |
| ## Files | |
| ``` | |
| threshold-and/ | |
| βββ model.safetensors | |
| βββ model.py | |
| βββ config.json | |
| βββ README.md | |
| ``` | |
| ## License | |
| MIT | |