| | ---
|
| | license: mit
|
| | tags:
|
| | - pytorch
|
| | - safetensors
|
| | - threshold-logic
|
| | - neuromorphic
|
| | - voting
|
| | ---
|
| |
|
| | # threshold-2outof6
|
| |
|
| | At-least-2-of-6 threshold gate. Fires when 2 or more of the 6 inputs are high.
|
| |
|
| | ## Function
|
| |
|
| | ```
|
| | 2outof6(x0, x1, x2, x3, x4, x5) = 1 if (x0 + x1 + x2 + x3 + x4 + x5) >= 2
|
| | ```
|
| |
|
| | ## Truth Table (selected)
|
| |
|
| | | Hamming Weight | Output |
|
| | |:--------------:|:------:|
|
| | | 0 | 0 |
|
| | | 1 | 0 |
|
| | | 2 | 1 |
|
| | | 3 | 1 |
|
| | | 4 | 1 |
|
| | | 5 | 1 |
|
| | | 6 | 1 |
|
| |
|
| | ## Mechanism
|
| |
|
| | Single threshold neuron with uniform weights. The bias of -2 sets the firing threshold:
|
| |
|
| | - Sum = (number of 1s) + (-2)
|
| | - Fires when sum >= 0, i.e., when Hamming weight >= 2
|
| |
|
| | ## 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 | -2 |
|
| | | Inputs | 6 |
|
| | | Outputs | 1 |
|
| | | Neurons | 1 |
|
| | | Layers | 1 |
|
| | | Parameters | 7 |
|
| | | Magnitude | 8 |
|
| |
|
| | ## Usage
|
| |
|
| | ```python
|
| | from safetensors.torch import load_file
|
| | import torch
|
| |
|
| | w = load_file('model.safetensors')
|
| |
|
| | def at_least_2_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_2_of_6([1, 1, 0, 0, 0, 0])) # 1
|
| | ```
|
| |
|
| | ## License
|
| |
|
| | MIT
|
| |
|