morpho-logic-engine / test_mle.py
Harry00's picture
Upload test_mle.py
e412146 verified
"""Test basique du système MLE."""
import sys
sys.path.insert(0, '.')
import numpy as np
from mle.mle_system import MLESystem
from mle.memory import VECTOR_SIZE
np.random.seed(42)
print("Initializing MLESystem...")
mle = MLESystem(memory_capacity=100, online_learning=True)
print(f"Memory size: {mle.memory.size}")
print(f"Router vectors: {mle.router.get_stats()['n_vectors']}")
# Test basique
vec = np.zeros(VECTOR_SIZE, dtype=np.uint8)
vec[np.random.choice(VECTOR_SIZE, size=200, replace=False)] = 1
print(f"\nProcessing vector with {np.sum(vec)} active bits...")
result = mle.process(vec)
print(f"Converged: {result.converged}")
print(f"Iterations: {result.n_iterations}")
if result.energy_trajectory:
print(f"Final energy: {result.energy_trajectory[-1]:.1f}")
print(f"Energy trajectory: {[f'{e:.1f}' for e in result.energy_trajectory[:10]]}")
# Test binding
print("\nTesting binding...")
a = np.zeros(VECTOR_SIZE, dtype=np.uint8)
a[np.random.choice(VECTOR_SIZE, size=200, replace=False)] = 1
b = np.zeros(VECTOR_SIZE, dtype=np.uint8)
b[np.random.choice(VECTOR_SIZE, size=200, replace=False)] = 1
bound = mle.binder.bind(a, b)
recovered = mle.binder.unbind(bound, a)
similarity = np.mean(recovered == b)
print(f"Binding similarity: {similarity:.3f}")
# Test requête
print("\nTesting query...")
neighbors = mle.query(vec, k=3)
print(f"Found {len(neighbors)} neighbors")
# Metrics
print("\nMetrics summary:")
summary = mle.get_metrics_summary()
for section, data in summary.items():
print(f" {section}: {data}")
print("\n✓ All basic tests passed!")