Upload run_quick_test.py
Browse files- run_quick_test.py +107 -0
run_quick_test.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test rapide et léger du système MLE."""
|
| 2 |
+
import sys
|
| 3 |
+
sys.path.insert(0, '.')
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
import time
|
| 7 |
+
from mle.mle_system import MLESystem
|
| 8 |
+
from mle.memory import VECTOR_SIZE
|
| 9 |
+
|
| 10 |
+
np.random.seed(42)
|
| 11 |
+
|
| 12 |
+
print("="*60)
|
| 13 |
+
print("MLE QUICK TEST")
|
| 14 |
+
print("="*60)
|
| 15 |
+
|
| 16 |
+
mle = MLESystem(memory_capacity=500, online_learning=True, temperature=0.5)
|
| 17 |
+
|
| 18 |
+
# Phase 1: Crée des vecteurs reliés (concepts)
|
| 19 |
+
print("\n--- Creating related concepts ---")
|
| 20 |
+
n_concepts = 3
|
| 21 |
+
n_variants = 3
|
| 22 |
+
|
| 23 |
+
concepts = []
|
| 24 |
+
for c in range(n_concepts):
|
| 25 |
+
base_active = np.random.choice(VECTOR_SIZE, size=200, replace=False)
|
| 26 |
+
base = np.zeros(VECTOR_SIZE, dtype=np.uint8)
|
| 27 |
+
base[base_active] = 1
|
| 28 |
+
|
| 29 |
+
variants = []
|
| 30 |
+
for v in range(n_variants):
|
| 31 |
+
variant = base.copy()
|
| 32 |
+
# Ajoute du bruit
|
| 33 |
+
to_flip = np.random.choice(VECTOR_SIZE, size=30, replace=False)
|
| 34 |
+
variant[to_flip] = 1 - variant[to_flip]
|
| 35 |
+
variants.append(variant)
|
| 36 |
+
|
| 37 |
+
concepts.append((base, variants))
|
| 38 |
+
|
| 39 |
+
# Traite les variants
|
| 40 |
+
for variant in variants:
|
| 41 |
+
t0 = time.time()
|
| 42 |
+
result = mle.process(variant)
|
| 43 |
+
t1 = time.time()
|
| 44 |
+
|
| 45 |
+
if result.energy_trajectory:
|
| 46 |
+
print(f" Concept {c}, variant: energy={result.energy_trajectory[-1]:.0f}, "
|
| 47 |
+
f"conv={result.converged}, time={(t1-t0)*1000:.0f}ms")
|
| 48 |
+
|
| 49 |
+
print(f"\nMemory after concepts: {mle.memory.size}")
|
| 50 |
+
|
| 51 |
+
# Phase 2: Test généralisation avec requêtes bruitées
|
| 52 |
+
print("\n--- Testing generalization (noisy queries) ---")
|
| 53 |
+
for c, (base, _) in enumerate(concepts):
|
| 54 |
+
query = base.copy()
|
| 55 |
+
# Plus de bruit
|
| 56 |
+
to_flip = np.random.choice(VECTOR_SIZE, size=80, replace=False)
|
| 57 |
+
query[to_flip] = 1 - query[to_flip]
|
| 58 |
+
|
| 59 |
+
result = mle.process(query)
|
| 60 |
+
if result.energy_trajectory:
|
| 61 |
+
print(f" Query concept {c}: energy={result.energy_trajectory[-1]:.0f}, "
|
| 62 |
+
f"conv={result.converged}")
|
| 63 |
+
|
| 64 |
+
# Phase 3: Test stabilité
|
| 65 |
+
print("\n--- Testing stability (continuous stream) ---")
|
| 66 |
+
energies = []
|
| 67 |
+
for i in range(20):
|
| 68 |
+
c = i % n_concepts
|
| 69 |
+
_, variants = concepts[c]
|
| 70 |
+
vec = variants[i % len(variants)]
|
| 71 |
+
|
| 72 |
+
result = mle.process(vec)
|
| 73 |
+
if result.energy_trajectory:
|
| 74 |
+
energies.append(result.energy_trajectory[-1])
|
| 75 |
+
|
| 76 |
+
if i % 5 == 0:
|
| 77 |
+
print(f" [{i:2d}] memory={mle.memory.size}, n_assoc={len(mle.energy.associations)}")
|
| 78 |
+
|
| 79 |
+
if len(energies) >= 10:
|
| 80 |
+
early = np.mean(energies[:5])
|
| 81 |
+
late = np.mean(energies[-5:])
|
| 82 |
+
print(f"\n Early energy: {early:.0f}")
|
| 83 |
+
print(f" Late energy: {late:.0f}")
|
| 84 |
+
if late < early * 0.95:
|
| 85 |
+
print(" ✓ System is LEARNING")
|
| 86 |
+
else:
|
| 87 |
+
print(" ~ System is STABLE")
|
| 88 |
+
|
| 89 |
+
# Phase 4: Test binding
|
| 90 |
+
print("\n--- Testing binding ---")
|
| 91 |
+
a = np.zeros(VECTOR_SIZE, dtype=np.uint8)
|
| 92 |
+
a[np.random.choice(VECTOR_SIZE, size=200, replace=False)] = 1
|
| 93 |
+
b = np.zeros(VECTOR_SIZE, dtype=np.uint8)
|
| 94 |
+
b[np.random.choice(VECTOR_SIZE, size=200, replace=False)] = 1
|
| 95 |
+
|
| 96 |
+
bound = mle.binder.bind(a, b)
|
| 97 |
+
recovered = mle.binder.unbind(bound, a)
|
| 98 |
+
sim = np.mean(recovered == b)
|
| 99 |
+
print(f" Binding similarity: {sim:.3f}")
|
| 100 |
+
|
| 101 |
+
# Résumé
|
| 102 |
+
print("\n" + "="*60)
|
| 103 |
+
print("SUMMARY")
|
| 104 |
+
print("="*60)
|
| 105 |
+
mle.print_summary()
|
| 106 |
+
|
| 107 |
+
print("\n✓ Quick test complete!")
|