File size: 1,263 Bytes
9cb1889
 
 
 
 
 
 
 
 
 
 
6c0bc0c
9cb1889
 
 
6c0bc0c
 
 
 
 
 
 
 
 
 
 
 
 
9cb1889
 
 
6c0bc0c
 
 
 
9cb1889
6c0bc0c
9cb1889
6c0bc0c
9cb1889
 
 
 
 
6c0bc0c
9cb1889
 
 
 
 
 
 
 
 
 
 
 
 
 
6c0bc0c
 
9cb1889
 
6c0bc0c
 
 
9cb1889
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
---

# threshold-isone4

Check if 4-bit input equals 1 (binary 0001).

## Function

isone4(a3, a2, a1, a0) = 1 if input == 1, else 0

Where input = 8*a3 + 4*a2 + 2*a1 + a0

## Truth Table

| a3 | a2 | a1 | a0 | decimal | out |
|----|----|----|----|---------| ----|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 |
| 0 | 0 | 1 | 0 | 2 | 0 |
| 0 | 0 | 1 | 1 | 3 | 0 |
| ... | ... | ... | ... | ... | 0 |

## Architecture

Single neuron pattern matcher for binary 0001:

- Weights: [-1, -1, -1, +1]
- Bias: -1

Fires when: -a3 - a2 - a1 + a0 - 1 >= 0

This requires a3=0, a2=0, a1=0, a0=1 (exactly the pattern 0001).

## Parameters

| | |
|---|---|
| Inputs | 4 |
| Outputs | 1 |
| Neurons | 1 |
| Layers | 1 |
| Parameters | 5 |
| Magnitude | 5 |

## Usage

```python
from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def isone4(a3, a2, a1, a0):
    inp = torch.tensor([float(a3), float(a2), float(a1), float(a0)])
    return int((inp @ w['neuron.weight'].T + w['neuron.bias'] >= 0).item())

print(isone4(0, 0, 0, 1))  # 1 (input = 1)
print(isone4(0, 0, 1, 0))  # 0 (input = 2)
print(isone4(0, 0, 0, 0))  # 0 (input = 0)
```

## License

MIT