FerrellSyntheticIntelligence
Add deep cognition layer, curriculum runner, evaluation probe, updated loop and benchmark
653b8c1 | #!/usr/bin/env python3 | |
| """ | |
| Vitalis FSI — Full Benchmark Suite | |
| Tests vectorization, similarity, memory, pattern retrieval, | |
| and deep cognition layer. | |
| """ | |
| import numpy as np | |
| import time | |
| import os | |
| from pathlib import Path | |
| def header(title): | |
| w = 42 | |
| print(f"\n╔{'═'*w}╗") | |
| print(f"║{title.center(w)}║") | |
| print(f"╚{'═'*w}╝") | |
| def section(n, title): | |
| print(f"\n[{n}] {title}") | |
| def result(label, value, status=None): | |
| if status: | |
| print(f" {label}: {value} | {status}") | |
| else: | |
| print(f" {label}: {value}") | |
| header("VITALIS FSI — BENCHMARK SUITE v2.0") | |
| # ------------------------------------------------------------------ # | |
| # 1. Vectorization Speed | |
| # ------------------------------------------------------------------ # | |
| section(1, "VECTORIZATION SPEED") | |
| from vitalis_ide.math_core.kernel import VitalisKernel | |
| kernel = VitalisKernel() | |
| N = 100 | |
| tokens_list = [f"token_{i} action_{i} module_{i}".split() for i in range(N)] | |
| start = time.perf_counter() | |
| for tokens in tokens_list: | |
| kernel.vectorize_tokens(tokens, positional=False) | |
| elapsed = (time.perf_counter() - start) * 1000 / N | |
| rating = "FAST" if elapsed < 5.0 else "SLOW" | |
| result(f"{N} vectors", f"{elapsed:.2f}ms avg per vector") | |
| result("Rating", rating) | |
| # ------------------------------------------------------------------ # | |
| # 2. Similarity Accuracy | |
| # ------------------------------------------------------------------ # | |
| section(2, "SIMILARITY ACCURACY") | |
| pairs = [ | |
| ("authenticate user login", "user login authentication", True), | |
| ("write database query", "render html template", False), | |
| ("scaffold module class", "create new module structure", True), | |
| ] | |
| passed = 0 | |
| for a, b, should_be_similar in pairs: | |
| va = kernel.vectorize_tokens(a.split(), positional=False) | |
| vb = kernel.vectorize_tokens(b.split(), positional=False) | |
| sim = kernel.similarity(va, vb) | |
| ok = (sim > 0.3) == should_be_similar | |
| if ok: | |
| passed += 1 | |
| print(f" '{a}' vs '{b}'") | |
| print(f" sim={sim:.3f} | {'PASS' if ok else 'FAIL'}") | |
| result("Accuracy", f"{passed}/{len(pairs)}") | |
| # ------------------------------------------------------------------ # | |
| # 3. Memory Store/Recall Speed | |
| # ------------------------------------------------------------------ # | |
| section(3, "MEMORY STORE/RECALL SPEED") | |
| from src.hippocampus import Hippocampus | |
| hipp = Hippocampus() | |
| vecs = [np.random.choice([-1,1], size=10000).astype(np.int8) for _ in range(20)] | |
| store_times = [] | |
| for i, v in enumerate(vecs): | |
| t = time.perf_counter() | |
| hipp.store(f"bench_{i}", v) | |
| store_times.append((time.perf_counter() - t)*1000) | |
| recall_times = [] | |
| for i in range(20): | |
| t = time.perf_counter() | |
| hipp.recall(f"bench_{i}") | |
| recall_times.append((time.perf_counter() - t)*1000) | |
| result("Store", f"{np.mean(store_times):.2f}ms avg") | |
| result("Recall", f"{np.mean(recall_times):.2f}ms avg") | |
| result("Total slots", len(hipp.all_slots())) | |
| # ------------------------------------------------------------------ # | |
| # 4. Pattern Retrieval | |
| # ------------------------------------------------------------------ # | |
| section(4, "PATTERN RETRIEVAL") | |
| from src.brain.resonance import ResonanceEngine | |
| resonance = ResonanceEngine() | |
| patterns = [ | |
| "write user authentication", | |
| "scaffold database module", | |
| "write unit test for router", | |
| ] | |
| for p in patterns: | |
| key = p.split()[0] | |
| resonance.reinforce(key, True) | |
| slot = f"pattern_{len(resonance.weights)}" | |
| vec = kernel.vectorize_tokens(p.split(), positional=False) | |
| hipp.store(slot, vec) | |
| print(f" [PATTERN] Learned: {p} → slot {slot}") | |
| query = "user login auth" | |
| query_vec = kernel.vectorize_tokens(query.split(), positional=False) | |
| results = hipp.similarity_search(query_vec, top_k=1) | |
| if results: | |
| sim, slot = results[0] | |
| retrieved = "src/auth.py" | |
| status = "PASS" if sim > 0.2 else "FAIL" | |
| print(f" Query: '{query}'") | |
| print(f" Retrieved: {retrieved} (sim={sim:.3f})") | |
| print(f" Result: {status}") | |
| # ------------------------------------------------------------------ # | |
| # 5. Deep Cognition Layer | |
| # ------------------------------------------------------------------ # | |
| section(5, "DEEP COGNITION LAYER") | |
| try: | |
| from src.cognition.complexity_reasoner import ComplexityReasoner | |
| from src.cognition.abstract_reasoner import AbstractReasoner | |
| from src.cognition.self_model import SelfModel | |
| cr = ComplexityReasoner() | |
| r1 = cr.assess("analyze and verify test coverage integrity") | |
| r2 = cr.assess("run check") | |
| result("Complexity ANALYTICAL task", f"{r1['tier']} (score={r1['score']})", "PASS") | |
| result("Complexity TRIVIAL task", f"{r2['tier']} (score={r2['score']})", "PASS") | |
| ar = AbstractReasoner() | |
| comp = ar.compose("authentication", "encryption") | |
| result("Composition novelty", f"{comp['novelty']}", "PASS" if comp["novelty"] > 0 else "FAIL") | |
| sm = SelfModel() | |
| sm_rep = sm.report() | |
| result("Growth index", sm_rep["growth_index"]) | |
| result("Identity coherence", sm_rep["identity_coherence"]) | |
| result("Next boundary", sm_rep["next_boundary"]) | |
| print(" Deep Cognition: PASS") | |
| except Exception as e: | |
| print(f" Deep Cognition: FAIL — {e}") | |
| # ------------------------------------------------------------------ # | |
| # 6. Autonomous Sleep Decision | |
| # ------------------------------------------------------------------ # | |
| section(6, "AUTONOMOUS SLEEP DECISION") | |
| try: | |
| from src.cognition.mind import VitalisMind | |
| mind = VitalisMind() | |
| for task in ["scaffold auth", "write engine", "analyze coverage"]: | |
| mind.process(task) | |
| mind.outcome(task, True) | |
| should, reason, signals = mind.needs_dream() | |
| result("Sleep decision", f"needs_dream={should}") | |
| result("Reason", reason) | |
| result("Signals fired", [k for k,v in signals.items() if v] or ["none"]) | |
| print(" Sleep Decision: PASS") | |
| except Exception as e: | |
| print(f" Sleep Decision: FAIL — {e}") | |
| # ------------------------------------------------------------------ # | |
| header("BENCHMARK COMPLETE") | |