Initial commit: GKERN glyph kernel
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
"""GLYPHOS SUBSTRATE BENCHMARK"""
|
||||
try:
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
print("\033[91m[ERROR] numpy not installed. Run: pip install numpy\033[0m")
|
||||
exit(1)
|
||||
|
||||
import time
|
||||
|
||||
def resonance(similarity):
|
||||
return 1.0 / (1.0 + np.exp(-1.0 * (similarity - 4.0)))
|
||||
|
||||
class SubstrateGraph:
|
||||
def __init__(self, node_count=4096, edges_per_node=4):
|
||||
np.random.seed(42) # Reproducible
|
||||
self.nodes = np.random.rand(node_count).astype(np.float32)
|
||||
self.edges = [(i, (i * 7 + e * 13 + 3) % node_count)
|
||||
for i in range(node_count) for e in range(edges_per_node)]
|
||||
|
||||
def converge(self, max_epochs=100, threshold=0.001):
|
||||
for epoch in range(max_epochs):
|
||||
new_nodes = self.nodes.copy()
|
||||
max_delta = 0.0
|
||||
for i in range(len(self.nodes)):
|
||||
neighbors = [self.nodes[j] for _, j in self.edges if _ == i]
|
||||
if neighbors:
|
||||
sims = np.where(np.abs(self.nodes[i] - neighbors) < 0.5, 5.0, 0.0)
|
||||
weights = np.array([resonance(s) for s in sims])
|
||||
w_sum = np.sum(weights)
|
||||
new_nodes[i] = np.sum(np.array(neighbors) * weights) / w_sum if w_sum > 0 else self.nodes[i]
|
||||
delta = abs(new_nodes[i] - self.nodes[i])
|
||||
max_delta = max(max_delta, delta)
|
||||
self.nodes = new_nodes
|
||||
if max_delta < threshold:
|
||||
return epoch + 1, max_delta
|
||||
return max_epochs, max_delta
|
||||
|
||||
def benchmark():
|
||||
print("\033[35mGlyphOS Substrate Benchmark\033[0m")
|
||||
|
||||
# TTC test
|
||||
print("\033[33mRunning convergence test (4096 nodes)...\033[0m")
|
||||
start = time.perf_counter()
|
||||
epochs, delta = SubstrateGraph(4096, 4).converge(100)
|
||||
ttc = (time.perf_counter() - start) * 1000
|
||||
print(f" Converged in {epochs} epochs, delta={delta:.4f}")
|
||||
|
||||
# NEPS test
|
||||
print("\033[33mRunning throughput test...\033[0m")
|
||||
start = time.perf_counter()
|
||||
for _ in range(20):
|
||||
SubstrateGraph(4096, 4).converge(5)
|
||||
elapsed = time.perf_counter() - start
|
||||
neps = (4096 * 20) / elapsed
|
||||
|
||||
print(f"\n\033[1m=== GLYPHOS BASELINE RESULTS ===\033[0m")
|
||||
print(f"TTC (4096 nodes): {ttc:.2f} ms in {epochs} epochs")
|
||||
print(f"NEPS: {neps:,.0f} node-epochs/sec")
|
||||
print(f"\033[93mNote: Measures constraint graph relaxation, not AI inference\033[0m")
|
||||
|
||||
if __name__ == '__main__':
|
||||
benchmark()
|
||||
Reference in New Issue
Block a user