| """Test rapide et léger du système MLE.""" |
| import sys |
| sys.path.insert(0, '.') |
|
|
| import numpy as np |
| import time |
| from mle.mle_system import MLESystem |
| from mle.memory import VECTOR_SIZE |
|
|
| np.random.seed(42) |
|
|
| print("="*60) |
| print("MLE QUICK TEST") |
| print("="*60) |
|
|
| mle = MLESystem(memory_capacity=500, online_learning=True, temperature=0.5) |
|
|
| |
| print("\n--- Creating related concepts ---") |
| n_concepts = 3 |
| n_variants = 3 |
|
|
| concepts = [] |
| for c in range(n_concepts): |
| base_active = np.random.choice(VECTOR_SIZE, size=200, replace=False) |
| base = np.zeros(VECTOR_SIZE, dtype=np.uint8) |
| base[base_active] = 1 |
| |
| variants = [] |
| for v in range(n_variants): |
| variant = base.copy() |
| |
| to_flip = np.random.choice(VECTOR_SIZE, size=30, replace=False) |
| variant[to_flip] = 1 - variant[to_flip] |
| variants.append(variant) |
| |
| concepts.append((base, variants)) |
| |
| |
| for variant in variants: |
| t0 = time.time() |
| result = mle.process(variant) |
| t1 = time.time() |
| |
| if result.energy_trajectory: |
| print(f" Concept {c}, variant: energy={result.energy_trajectory[-1]:.0f}, " |
| f"conv={result.converged}, time={(t1-t0)*1000:.0f}ms") |
|
|
| print(f"\nMemory after concepts: {mle.memory.size}") |
|
|
| |
| print("\n--- Testing generalization (noisy queries) ---") |
| for c, (base, _) in enumerate(concepts): |
| query = base.copy() |
| |
| to_flip = np.random.choice(VECTOR_SIZE, size=80, replace=False) |
| query[to_flip] = 1 - query[to_flip] |
| |
| result = mle.process(query) |
| if result.energy_trajectory: |
| print(f" Query concept {c}: energy={result.energy_trajectory[-1]:.0f}, " |
| f"conv={result.converged}") |
|
|
| |
| print("\n--- Testing stability (continuous stream) ---") |
| energies = [] |
| for i in range(20): |
| c = i % n_concepts |
| _, variants = concepts[c] |
| vec = variants[i % len(variants)] |
| |
| result = mle.process(vec) |
| if result.energy_trajectory: |
| energies.append(result.energy_trajectory[-1]) |
| |
| if i % 5 == 0: |
| print(f" [{i:2d}] memory={mle.memory.size}, n_assoc={len(mle.energy.associations)}") |
|
|
| if len(energies) >= 10: |
| early = np.mean(energies[:5]) |
| late = np.mean(energies[-5:]) |
| print(f"\n Early energy: {early:.0f}") |
| print(f" Late energy: {late:.0f}") |
| if late < early * 0.95: |
| print(" ✓ System is LEARNING") |
| else: |
| print(" ~ System is STABLE") |
|
|
| |
| print("\n--- Testing 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) |
| sim = np.mean(recovered == b) |
| print(f" Binding similarity: {sim:.3f}") |
|
|
| |
| print("\n" + "="*60) |
| print("SUMMARY") |
| print("="*60) |
| mle.print_summary() |
|
|
| print("\n✓ Quick test complete!") |