Downloads · 30 days
9
20% of all-time downloads
phanerozoic/threshold-exactly2outof4
threshold-exactly2outof4 is a machine learning model from phanerozoic. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Downloads · 30 days
9
20% of all-time downloads
All-time downloads
46
Public
Parameters
13
Likes
0
Public
Click a slice to open those files.
.py2 KB · 52%
From the Hugging Face model README
Exactly 2 of 4 inputs high.
exactly2outof4(a, b, c, d) = 1 if (a + b + c + d) == 2, else 0
| a | b | c | d | sum | out |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 0 | 1 | 1 | 2 | 1 |
| 0 | 1 | 0 | 1 | 2 | 1 |
| 1 | 0 | 0 | 1 | 2 | 1 |
| 0 | 1 | 1 | 0 | 2 | 1 |
| 1 | 0 | 1 | 0 | 2 | 1 |
| 1 | 1 | 0 | 0 | 2 | 1 |
| 0 | 1 | 1 | 1 | 3 | 0 |
| 1 | 1 | 1 | 1 | 4 | 0 |
Layer 1:
N1: [1,1,1,1] b=-2 (fires when sum >= 2)
N2: [-1,-1,-1,-1] b=2 (fires when sum <= 2)
Layer 2:
AND: [1,1] b=-2 (fires when both N1 and N2 fire)
| Inputs | 4 |
| Outputs | 1 |
| Neurons | 3 |
| Layers | 2 |
| Parameters | 13 |
| Magnitude | 16 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def exactly2of4(a, b, c, d):
inp = torch.tensor([float(a), float(b), float(c), float(d)])
l1 = (inp @ w['layer1.weight'].T + w['layer1.bias'] >= 0).float()
out = (l1 @ w['layer2.weight'].T + w['layer2.bias'] >= 0).float()
return int(out.item())
print(exactly2of4(0, 0, 1, 1)) # 1
print(exactly2of4(0, 1, 1, 1)) # 0
MIT