| ---
|
| license: mit
|
| tags:
|
| - pytorch
|
| - safetensors
|
| - threshold-logic
|
| - neuromorphic
|
| - voting
|
| ---
|
|
|
| # threshold-4outof6
|
|
|
| At-least-4-of-6 threshold gate. Fires when 4 or more of the 6 inputs are high.
|
|
|
| ## Function
|
|
|
| ```
|
| 4outof6(x0, x1, x2, x3, x4, x5) = 1 if (x0 + x1 + x2 + x3 + x4 + x5) >= 4
|
| ```
|
|
|
| ## Truth Table (selected)
|
|
|
| | Hamming Weight | Output |
|
| |:--------------:|:------:|
|
| | 0 | 0 |
|
| | 1 | 0 |
|
| | 2 | 0 |
|
| | 3 | 0 |
|
| | 4 | 1 |
|
| | 5 | 1 |
|
| | 6 | 1 |
|
|
|
| ## Mechanism
|
|
|
| Single threshold neuron with uniform weights. The bias of -4 sets the firing threshold:
|
|
|
| - Sum = (number of 1s) + (-4)
|
| - Fires when sum >= 0, i.e., when Hamming weight >= 4
|
|
|
| ## k-out-of-6 Family
|
|
|
| | Circuit | Bias | Fires when |
|
| |---------|------|------------|
|
| | 1-out-of-6 | -1 | HW >= 1 |
|
| | 2-out-of-6 | -2 | HW >= 2 |
|
| | 3-out-of-6 | -3 | HW >= 3 (majority) |
|
| | 4-out-of-6 | -4 | HW >= 4 |
|
| | 5-out-of-6 | -5 | HW >= 5 |
|
| | 6-out-of-6 | -6 | HW = 6 (AND) |
|
|
|
| ## Parameters
|
|
|
| | | |
|
| |---|---|
|
| | Weights | [1, 1, 1, 1, 1, 1] |
|
| | Bias | -4 |
|
| | Inputs | 6 |
|
| | Outputs | 1 |
|
| | Neurons | 1 |
|
| | Layers | 1 |
|
| | Parameters | 7 |
|
| | Magnitude | 10 |
|
|
|
| ## Usage
|
|
|
| ```python
|
| from safetensors.torch import load_file
|
| import torch
|
|
|
| w = load_file('model.safetensors')
|
|
|
| def at_least_4_of_6(bits):
|
| inputs = torch.tensor([float(b) for b in bits])
|
| return int((inputs @ w['neuron.weight'].T + w['neuron.bias'] >= 0).item())
|
|
|
| print(at_least_4_of_6([1, 1, 1, 1, 0, 0, 0])) # 0 or 1 depending on k
|
| ```
|
|
|
| ## License
|
|
|
| MIT
|
|
|