feat(BNNBot): add similarity and overlap metrics to output
Output format: <tick> <44 bits> <hamming> <similarity> <overlap> - Similarity: bits that are the same (TOTAL_BITS - hamming) - Overlap: bits that are 1 in both vectors (popcount of bitwise AND) - First tick: all metrics printed as 0 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Binary file not shown.
@@ -43,8 +43,10 @@ method onScannedBot*(bot: BNNBot, e: ScannedBotEvent) =
|
|||||||
heading: bot.heading,
|
heading: bot.heading,
|
||||||
)
|
)
|
||||||
let vec = encode(scan)
|
let vec = encode(scan)
|
||||||
let distance = if bot.hasPrev: hammingDistance(bot.prevVec, vec) else: 0
|
let hamming = if bot.hasPrev: hammingDistance(bot.prevVec, vec) else: 0
|
||||||
echo align($bot.tick, 4), " ", formatBinary(vec), " ", distance
|
let similarity = if bot.hasPrev: TOTAL_BITS - hamming else: 0
|
||||||
|
let overlap = if bot.hasPrev: popcount(bitwiseAnd(bot.prevVec, vec)) else: 0
|
||||||
|
echo align($bot.tick, 4), " ", formatBinary(vec), " ", hamming, " ", similarity, " ", overlap
|
||||||
bot.prevVec = vec
|
bot.prevVec = vec
|
||||||
bot.hasPrev = true
|
bot.hasPrev = true
|
||||||
|
|
||||||
|
|||||||
@@ -71,3 +71,7 @@ proc popcount*(vec: BinaryVector): int =
|
|||||||
proc hammingDistance*(a, b: BinaryVector): int =
|
proc hammingDistance*(a, b: BinaryVector): int =
|
||||||
for i in 0..<TOTAL_BITS:
|
for i in 0..<TOTAL_BITS:
|
||||||
result += int(a[i] xor b[i])
|
result += int(a[i] xor b[i])
|
||||||
|
|
||||||
|
proc bitwiseAnd*(a, b: BinaryVector): BinaryVector =
|
||||||
|
for i in 0..<TOTAL_BITS:
|
||||||
|
result[i] = a[i] and b[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user