File size: 2,092 Bytes
c9689b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
- error-correction
- ecc
---

# threshold-sec-ded

SEC-DED (8,4) decoder: Single Error Correct, Double Error Detect. Extends Hamming(7,4) with overall parity for double-error detection.

## Circuit

```
codeword[7:0] ──► SEC-DED ──┬──► data[3:0]     (corrected)
                           β”œβ”€β”€β–Ί error         (error detected)
                           └──► uncorrectable (double error)
```

## Codeword Format

```
Position: 7  6  5  4  3  2  1  0
Bit:      d3 d2 d1 p3 d0 p2 p1 p0

p0 = overall parity (all bits)
p1 = parity of positions 1,3,5,7
p2 = parity of positions 2,3,6,7
p3 = parity of positions 4,5,6,7
d0-d3 = data bits
```

## Error Handling

| Syndrome | Overall Parity | Status |
|----------|----------------|--------|
| 0 | 0 | No error |
| β‰ 0 | 1 | Single error (correctable) |
| β‰ 0 | 0 | Double error (detected only) |
| 0 | 1 | Single error in p0 (correctable) |

## Architecture

| Component | Function | Neurons |
|-----------|----------|---------|
| Syndrome calc (s1,s2,s3) | XOR trees | ~63 |
| Overall parity | XOR tree | ~21 |
| Error logic | AND/OR | ~7 |
| Data correction | Conditional XOR | ~12 |

**Total: 95 neurons, 300 parameters, 4 layers**

## Capabilities

- **Correct**: Any single-bit error
- **Detect**: Any double-bit error
- **Miss**: Triple+ errors may be miscorrected

## Test Coverage

- 16 no-error cases: All pass
- 128 single-error cases: All corrected
- 448 double-error cases: All detected

## Usage

```python
from safetensors.torch import load_file

w = load_file('model.safetensors')

# Example: data=5 (0101)
# Encoded: 01010110 (with parity bits)
# Flip bit 3: 01011110
# Decoder: corrects to data=5, error=1, uncorrectable=0
```

## Applications

- ECC RAM (Error-Correcting Code memory)
- Data storage systems
- Communication channels
- Safety-critical systems

## Files

```
threshold-sec-ded/
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ create_safetensors.py
β”œβ”€β”€ config.json
└── README.md
```

## License

MIT