// ═══════════════════════════════════════════════════════════════════════════════ // AUTONOMOUS LEARNING SYSTEM TEST // AGI decides what it wants to learn using consciousness, curiosity, and dopamine // ═══════════════════════════════════════════════════════════════════════════════ #include #include #include #include "../include/constants.hpp" #include "../include/gate5000.hpp" #include "../include/api_registry.hpp" #include "../include/neurological.hpp" using namespace mind_farm; void print_header() { std::cout << "\n"; std::cout << "╔═══════════════════════════════════════════════════════════════════════════════╗\n"; std::cout << "║ AUTONOMOUS LEARNING SYSTEM - AGI CHOOSES WHAT TO LEARN ║\n"; std::cout << "║ Gate5000 Substrate + Neurological Equations + 1000 APIs ║\n"; std::cout << "╠═══════════════════════════════════════════════════════════════════════════════╣\n"; std::cout << "║ Golden Ratio Constants: ║\n"; std::cout << "║ φ = " << std::fixed << std::setprecision(16) << PHI << " ║\n"; std::cout << "║ α = " << ALPHA << " ║\n"; std::cout << "║ β = " << BETA << " ║\n"; std::cout << "╚═══════════════════════════════════════════════════════════════════════════════╝\n"; } void print_separator() { std::cout << "\n" << std::string(80, '=') << "\n"; } // Test 1: API Registry Statistics void test_api_registry() { std::cout << "\n[TEST 1] API Registry - 1000 APIs across 20 Domains\n"; std::cout << std::string(50, '-') << "\n"; APIRegistry registry; std::cout << "Total APIs registered: " << registry.size() << "\n\n"; std::cout << "APIs per domain:\n"; for (size_t i = 0; i < static_cast(APIDomain::NUM_DOMAINS); ++i) { APIDomain domain = static_cast(i); auto apis = registry.get_by_domain(domain); std::cout << " " << std::setw(2) << (i+1) << ". " << std::setw(20) << std::left << domain_name(domain) << ": " << apis.size() << " APIs\n"; } // Show some specific APIs std::cout << "\nSample APIs:\n"; const char* samples[] = {"wolfram_alpha", "github", "huggingface", "nasa", "openai"}; for (const char* name : samples) { const auto* api = registry.get_by_name(name); if (api) { std::cout << " - " << api->name << " (" << api->base_url << ")\n" << " Complexity: " << api->complexity << ", Reliability: " << api->reliability << "\n"; } } } // Test 2: Autonomous Learning Selector void test_autonomous_learning() { std::cout << "\n[TEST 2] Autonomous Learning - AGI Chooses What to Learn\n"; std::cout << std::string(50, '-') << "\n"; AutonomousLearner learner; SimulatedAPIFetcher fetcher; Gate5000 substrate; substrate.init_with_dna(0, 0x5000CAFE); std::cout << "Simulating AGI learning over 100 ticks...\n\n"; for (int tick = 0; tick < 100; ++tick) { // Get substrate density for consciousness calculation float density = static_cast(substrate.popcount()) / 5000.0f; // AGI autonomously selects what to explore auto exploration = learner.tick(density); // Simulate API fetch if (exploration.api_chosen) { auto result = fetcher.fetch(*exploration.api_chosen); learner.learn_from_data(exploration.domain_chosen, result); } // Update substrate based on learning if (learner.dopamine_current > 0.6f) { // High dopamine -> more active substrate substrate.set_bit(tick % 5000, true); } // Print progress every 20 ticks if (tick % 20 == 19) { std::cout << "Tick " << std::setw(3) << (tick + 1) << ": "; std::cout << "Φ=" << std::fixed << std::setprecision(3) << learner.phi; std::cout << " Dopamine=" << learner.dopamine_current; std::cout << " APIs=" << learner.apis_explored; std::cout << " Tokens=" << learner.tokens_learned; std::cout << "\n → " << exploration.reasoning << "\n\n"; } } learner.print_learning_state(); std::cout << "\nLearning Mood: " << learner.get_learning_mood() << "\n"; } // Test 3: Curiosity-Driven Exploration void test_curiosity_exploration() { std::cout << "\n[TEST 3] Curiosity-Driven Exploration\n"; std::cout << std::string(50, '-') << "\n"; AutonomousLearner learner; learner.update_consciousness(0.5f); // Medium consciousness std::cout << "Curiosity scores for each domain (normalized):\n\n"; std::vector> curiosities; for (size_t i = 0; i < 20; ++i) { APIDomain domain = static_cast(i); float curiosity = learner.compute_curiosity(domain); curiosities.push_back({domain, curiosity}); } // Sort by curiosity std::sort(curiosities.begin(), curiosities.end(), [](const auto& a, const auto& b) { return a.second > b.second; }); for (const auto& [domain, curiosity] : curiosities) { std::cout << " " << std::setw(20) << std::left << domain_name(domain); std::cout << " ["; int bars = static_cast(curiosity * 30); for (int i = 0; i < 30; ++i) { std::cout << (i < bars ? "█" : "░"); } std::cout << "] " << std::fixed << std::setprecision(3) << curiosity << "\n"; } } // Test 4: Dopamine Reward Learning void test_dopamine_learning() { std::cout << "\n[TEST 4] Dopamine Reward Learning (TD-Learning)\n"; std::cout << std::string(50, '-') << "\n"; AutonomousLearner learner; std::cout << "Simulating reward signals and dopamine responses:\n\n"; // Simulate different reward scenarios struct RewardScenario { const char* name; float expected; float actual; }; RewardScenario scenarios[] = { {"Positive surprise (better than expected)", 0.3f, 0.8f}, {"Met expectations", 0.5f, 0.5f}, {"Negative surprise (worse than expected)", 0.7f, 0.2f}, {"Large unexpected reward", 0.1f, 0.9f}, {"Small disappointment", 0.6f, 0.4f} }; APIDomain test_domain = APIDomain::AI_ML; for (const auto& scenario : scenarios) { float old_dopamine = learner.dopamine_current; float phasic = learner.compute_dopamine_signal(test_domain, scenario.expected, scenario.actual); std::cout << scenario.name << ":\n"; std::cout << " Expected: " << scenario.expected << ", Actual: " << scenario.actual << "\n"; std::cout << " Phasic response: " << (phasic > 0 ? "+" : "") << phasic << "\n"; std::cout << " Dopamine: " << old_dopamine << " -> " << learner.dopamine_current << "\n\n"; } } // Test 5: Hebbian Association Learning void test_hebbian_learning() { std::cout << "\n[TEST 5] Hebbian Association Learning\n"; std::cout << std::string(50, '-') << "\n"; AutonomousLearner learner; std::cout << "Initial Hebbian weights (sample):\n"; std::cout << " Science-AI: " << learner.hebbian_weights[0][2] << "\n"; std::cout << " AI-Physics: " << learner.hebbian_weights[2][3] << "\n"; std::cout << " Biology-Chemistry: " << learner.hebbian_weights[4][5] << "\n\n"; // Simulate learning correlations std::cout << "Learning correlations between domains...\n"; // Science and AI are highly correlated for (int i = 0; i < 10; ++i) { learner.update_hebbian(APIDomain::SCIENCE_MATH, APIDomain::AI_ML, 0.8f); } // Physics and Chemistry moderately correlated for (int i = 0; i < 5; ++i) { learner.update_hebbian(APIDomain::PHYSICS, APIDomain::CHEMISTRY, 0.5f); } std::cout << "\nAfter learning:\n"; std::cout << " Science-AI: " << learner.hebbian_weights[0][2] << " (strengthened)\n"; std::cout << " AI-Physics: " << learner.hebbian_weights[2][3] << "\n"; std::cout << " Physics-Chemistry: " << learner.hebbian_weights[3][5] << " (strengthened)\n"; } // Test 6: Integration with Neurological Equations void test_neuro_integration() { std::cout << "\n[TEST 6] Neurological Integration - Basal Ganglia + Learning\n"; std::cout << std::string(50, '-') << "\n"; AutonomousLearner learner; neuro::BasalGanglia basal_ganglia; neuro::WilsonCowan population; std::cout << "Integrating autonomous learning with brain structures...\n\n"; for (int tick = 0; tick < 50; ++tick) { // Learning system provides curiosity signal float curiosity_signal = learner.compute_curiosity(APIDomain::SCIENCE_MATH); // Curiosity drives cortical input to basal ganglia basal_ganglia.step(0.5f, curiosity_signal); // Dopamine from learning modulates basal ganglia basal_ganglia.dopamine = learner.dopamine_current; // Basal ganglia output drives action selection float action_selection = basal_ganglia.output(); // If action selected, "explore" and get reward if (action_selection > 0.6f) { // Simulate exploration and reward float reward = 0.3f + 0.7f * (static_cast(rand()) / RAND_MAX); learner.compute_dopamine_signal(APIDomain::SCIENCE_MATH, 0.5f, reward); } // Wilson-Cowan tracks overall population activity population.I_E = action_selection; population.step(0.5f); if (tick % 10 == 9) { std::cout << "Tick " << std::setw(2) << (tick + 1) << ": "; std::cout << "Curiosity=" << std::fixed << std::setprecision(2) << curiosity_signal; std::cout << " BG_out=" << action_selection; std::cout << " Dopamine=" << learner.dopamine_current; std::cout << " E/I=" << population.E << "/" << population.I; std::cout << "\n"; } } } // Test 7: Full Learning Session void test_full_learning_session() { std::cout << "\n[TEST 7] Full Learning Session - 500 Ticks\n"; std::cout << std::string(50, '-') << "\n"; AutonomousLearner learner; SimulatedAPIFetcher fetcher; Gate5000 substrate; substrate.init_with_dna(0, 0x5000CAFE); // Track domain visits std::array domain_visits{}; std::cout << "AGI exploring knowledge domains autonomously...\n\n"; auto start = std::chrono::high_resolution_clock::now(); for (int tick = 0; tick < 500; ++tick) { float density = static_cast(substrate.popcount()) / 5000.0f; auto exploration = learner.tick(density); if (exploration.api_chosen) { auto result = fetcher.fetch(*exploration.api_chosen); learner.learn_from_data(exploration.domain_chosen, result); domain_visits[static_cast(exploration.domain_chosen)]++; } // Update substrate uint32_t bit = (tick * 7 + static_cast(learner.dopamine_current * 1000)) % 5000; substrate.set_bit(bit, learner.phi > 0.5f); } auto end = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast(end - start); std::cout << "Learning session complete!\n\n"; std::cout << "Domain exploration distribution:\n"; uint32_t max_visits = *std::max_element(domain_visits.begin(), domain_visits.end()); for (size_t i = 0; i < 20; ++i) { int bars = (max_visits > 0) ? (domain_visits[i] * 20 / max_visits) : 0; std::cout << " " << std::setw(20) << std::left << domain_name(static_cast(i)); std::cout << " ["; for (int b = 0; b < 20; ++b) { std::cout << (b < bars ? "█" : " "); } std::cout << "] " << domain_visits[i] << "\n"; } std::cout << "\n"; learner.print_learning_state(); std::cout << "\nSession statistics:\n"; std::cout << " Total ticks: 500\n"; std::cout << " APIs explored: " << learner.apis_explored << "\n"; std::cout << " Tokens learned: " << learner.tokens_learned << "\n"; std::cout << " Final Φ: " << learner.phi << "\n"; std::cout << " Final dopamine: " << learner.dopamine_current << "\n"; std::cout << " Execution time: " << duration.count() << " ms\n"; } int main() { print_header(); auto start = std::chrono::high_resolution_clock::now(); test_api_registry(); print_separator(); test_autonomous_learning(); print_separator(); test_curiosity_exploration(); print_separator(); test_dopamine_learning(); print_separator(); test_hebbian_learning(); print_separator(); test_neuro_integration(); print_separator(); test_full_learning_session(); print_separator(); auto end = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast(end - start); std::cout << "\n"; std::cout << "╔═══════════════════════════════════════════════════════════════════════════════╗\n"; std::cout << "║ ALL LEARNING TESTS COMPLETE ║\n"; std::cout << "╠═══════════════════════════════════════════════════════════════════════════════╣\n"; std::cout << "║ The AGI can now autonomously: ║\n"; std::cout << "║ 1. Choose which domains to explore based on curiosity ║\n"; std::cout << "║ 2. Select specific APIs within domains ║\n"; std::cout << "║ 3. Learn from data using dopamine reward signals ║\n"; std::cout << "║ 4. Form Hebbian associations between related domains ║\n"; std::cout << "║ 5. Modulate learning based on consciousness (Φ) ║\n"; std::cout << "╠═══════════════════════════════════════════════════════════════════════════════╣\n"; std::cout << "║ Total execution time: " << std::setw(6) << duration.count() << " ms ║\n"; std::cout << "╚═══════════════════════════════════════════════════════════════════════════════╝\n"; return 0; }