| | --- |
| | license: mit |
| | tags: |
| | - pytorch |
| | - safetensors |
| | - threshold-logic |
| | - neuromorphic |
| | --- |
| | |
| | # threshold-isone8 |
| |
|
| | Check if 8-bit input equals 1 (binary 00000001). |
| |
|
| | ## Function |
| |
|
| | isone8(a7..a0) = 1 if input == 1, else 0 |
| |
|
| | Where input = 128*a7 + 64*a6 + ... + 2*a1 + a0 |
| | |
| | ## Architecture |
| | |
| | Single neuron pattern matcher for binary 00000001: |
| | |
| | - Weights: [-1, -1, -1, -1, -1, -1, -1, +1] |
| | - Bias: -1 |
| | |
| | Fires when all upper bits are 0 and LSB is 1. |
| | |
| | ## Parameters |
| | |
| | | | | |
| | |---|---| |
| | | Inputs | 8 | |
| | | Outputs | 1 | |
| | | Neurons | 1 | |
| | | Layers | 1 | |
| | | Parameters | 9 | |
| | | Magnitude | 9 | |
| | |
| | ## Usage |
| | |
| | ```python |
| | from safetensors.torch import load_file |
| | import torch |
| | |
| | w = load_file('model.safetensors') |
| | |
| | def isone8(a7, a6, a5, a4, a3, a2, a1, a0): |
| | inp = torch.tensor([float(a7), float(a6), float(a5), float(a4), |
| | float(a3), float(a2), float(a1), float(a0)]) |
| | return int((inp @ w['neuron.weight'].T + w['neuron.bias'] >= 0).item()) |
| | |
| | print(isone8(0, 0, 0, 0, 0, 0, 0, 1)) # 1 (input = 1) |
| | print(isone8(0, 0, 0, 0, 0, 0, 1, 0)) # 0 (input = 2) |
| | ``` |
| | |
| | ## License |
| | |
| | MIT |
| | |