File size: 1,445 Bytes
ed72eb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---

license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
- decoder
---


# threshold-4to16decoder

4-to-16 binary decoder. Converts 4-bit binary input to one-hot 16-bit output.

## Function

decode(a3, a2, a1, a0) -> [y0..y15] where yi=1 iff input=i

## One-Hot Encoding

| Input | a3a2a1a0 | Output |
|------:|:--------:|--------|
| 0 | 0000 | 1000000000000000 |
| 1 | 0001 | 0100000000000000 |
| 5 | 0101 | 0000010000000000 |
| 10 | 1010 | 0000000000100000 |
| 15 | 1111 | 0000000000000001 |

## Architecture

Single layer with 16 neurons. Each neuron yi is a pattern matcher for i:
- Weight +1 for bit positions that should be 1
- Weight -1 for bit positions that should be 0
- Bias = -(number of 1 bits in i)

All neurons run in parallel - no dependencies.

## Parameters

| | |
|---|---|
| Inputs | 4 |
| Outputs | 16 |
| Neurons | 16 |
| Layers | 1 |
| Parameters | 80 |
| Magnitude | 96 |

## Usage

```python

from safetensors.torch import load_file

import torch



w = load_file('model.safetensors')



def decode_4to16(a3, a2, a1, a0):

    inp = torch.tensor([float(a3), float(a2), float(a1), float(a0)])

    return [int((inp * w[f'y{i}.weight']).sum() + w[f'y{i}.bias'] >= 0)

            for i in range(16)]



# Input 10 -> output 10 is hot

outputs = decode_4to16(1, 0, 1, 0)

print(outputs)  # [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0]

```

## License

MIT