feat(BNNBot): Hebbian weight matrix with virtual bullet learning — 870→7 bit forward pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-17 23:49:59 +02:00
parent 50e3c6fae9
commit 22aefbddb6
3 changed files with 159 additions and 18 deletions
+27
View File
@@ -136,3 +136,30 @@ proc hammingDistance*(a, b: BinaryVector): int =
proc bitwiseAnd*(a, b: BinaryVector): BinaryVector =
for i in 0..<TOTAL_BITS:
result[i] = a[i] and b[i]
# Output encoding -------------------------------------------------------
const
OUTPUT_BITS* = 7
AIM_MIN* = -60.0
AIM_MAX* = 60.0
type OutputVector* = array[OUTPUT_BITS, uint8]
proc encodeOutput*(angle: float): OutputVector =
let clamped = clamp(angle, AIM_MIN, AIM_MAX)
let intVal = int((clamped - AIM_MIN) / (AIM_MAX - AIM_MIN) * 127.0)
let gray = toGray(intVal)
for i in 0..<OUTPUT_BITS:
result[OUTPUT_BITS - 1 - i] = uint8((gray shr i) and 1)
proc decodeOutput*(vec: OutputVector): float =
var val = 0
for i in 0..<OUTPUT_BITS:
val = (val shl 1) or int(vec[i])
var binary = val
var mask = binary shr 1
while mask > 0:
binary = binary xor mask
mask = mask shr 1
result = AIM_MIN + (float(binary) / 127.0) * (AIM_MAX - AIM_MIN)