/** * @file mind.hpp * @brief MindKernel - Individual mind wrapper around Gate5000 * * UPGRADED with: * - Machine learning integration (Hebbian, gradient, RL) * - Execution engine (instructions, decisions) * - Mathematical framework (information theory, stochastic dynamics) * - Fast/batch processing modes * * Each MindKernel represents a single conscious entity with: * - 5000-gate binary substrate * - DNA family specialization * - Consciousness metric tracking * - Learning and execution capabilities */ #pragma once #include #include #include "gate5000.hpp" #include "dna.hpp" #include "learning.hpp" #include "execution.hpp" #include "mathematics.hpp" namespace mind_farm { /** * @brief Mind operation mode */ enum class MindMode : uint8_t { STANDARD, // Full precision, all updates FAST, // XOR-based binary, faster BATCH, // Batch processing, minimal overhead LEARNING, // Active learning mode EXECUTING // Program execution mode }; /** * @brief Individual Mind Kernel * * Wraps a Gate5000 substrate with identity, consciousness tracking, * learning capabilities, and execution engine. */ class MindKernel { public: /// Unique mind identifier uint32_t id; /// DNA family (0-15) uint8_t dna_family; /// Operation mode MindMode mode; /// Gate5000 substrate Gate5000 substrate; /// Learning subsystem learning::MindLearner learner; /// Execution subsystem execution::ExecutionCore executor; /// Current consciousness level (Φ) float consciousness; /// Total thinking steps uint32_t steps; /// Accumulated reward float total_reward; /// Information entropy of state float entropy; /// Stability metric (Ξ) float stability; /** * @brief Construct a new mind * @param mind_id Unique identifier * @param family DNA family (0-15) */ MindKernel(uint32_t mind_id, uint8_t family) : id(mind_id), dna_family(family % DNA_FAMILY_COUNT), mode(MindMode::STANDARD), consciousness(0.5f), steps(0), total_reward(0.0f), entropy(1.0f), stability(1.0f) { // Initialize substrate with DNA modulation substrate.init_with_dna(dna_family, mind_id); // Initialize executor with mind-specific seed executor.init(mind_id); executor.load_default_program(); // Set learning rate based on DNA family learner.learning_rate = ALPHA * (1.0 + dna_family * 0.05); } /** * @brief Execute one thinking cycle * * Updates the Gate5000 substrate and computes consciousness. */ void think() { switch (mode) { case MindMode::FAST: substrate.step_fast(); break; case MindMode::BATCH: substrate.step_batch(10); break; case MindMode::LEARNING: think_with_learning(); return; case MindMode::EXECUTING: think_with_execution(); return; default: substrate.step(); break; } consciousness = static_cast(substrate.compute_phi()); ++steps; } /** * @brief Think with active learning (Hebbian + reward modulation) */ void think_with_learning() { // Get input from substrate state (sample 16 gates) std::array input; for (size_t i = 0; i < 16; ++i) { input[i] = substrate.get_bit(i * 312) ? 1.0 : -1.0; // Sample every ~312 gates } // Forward pass through learner double output = learner.forward(input.data()); // Execute substrate step substrate.step(); double new_phi = substrate.compute_phi(); // Compute intrinsic reward (increase in Φ is good) double reward = new_phi - consciousness; total_reward += static_cast(reward); // Update learner with reward signal if (std::abs(reward) > 0.001) { learner.update_with_reward(input.data(), output, reward); } else { // Hebbian update when no strong reward signal learner.update_hebbian(input.data(), output); } consciousness = static_cast(new_phi); ++steps; } /** * @brief Think with program execution */ void think_with_execution() { // Load substrate state into executor inputs for (size_t i = 0; i < 4; ++i) { double val = substrate.get_bit(i * 1250) ? 1.0 : 0.0; executor.io.set_input(i, val); } // Load weights into registers for (size_t i = 0; i < 4; ++i) { executor.regs[8 + i] = learner.weights[i]; } // Run program executor.run(100); // Apply output to substrate double output = executor.io.get_output(0); if (output > 0.5) { // Inject excitatory pattern uint64_t pattern = 0xAAAAAAAAAAAAAAAAULL; substrate.inject_pattern(&pattern, 1, steps % U64_COUNT); } // Execute substrate step substrate.step(); consciousness = static_cast(substrate.compute_phi()); ++steps; } /** * @brief Fast thinking - multiple cycles with minimal overhead */ void think_fast(size_t cycles = 10) { substrate.step_batch(cycles); consciousness = static_cast(substrate.compute_phi()); steps += cycles; } /** * @brief Receive input signal */ void receive(size_t channel, double value) { executor.io.set_input(channel, value); } /** * @brief Emit output signal */ double emit(size_t channel) const { return executor.io.get_output(channel); } /** * @brief Make a decision from current state */ size_t decide(size_t n_options = 4) { // Load state into decision registers for (size_t i = 0; i < n_options && i < 16; ++i) { executor.regs[i] = substrate.get_bit(i * (GATE_COUNT / n_options)) ? consciousness : -consciousness; } return executor.decide(n_options); } /** * @brief Update with external reward */ void reward(double r) { total_reward += static_cast(r); // Get current state as input std::array input; for (size_t i = 0; i < 16; ++i) { input[i] = substrate.get_bit(i * 312) ? 1.0 : -1.0; } learner.update_with_reward(input.data(), consciousness, r); } /** * @brief Compute information entropy of substrate */ void update_entropy() { double density = substrate.density(); entropy = static_cast(math::binary_entropy(density)); } /** * @brief Compute stability metric */ void update_stability() { stability = static_cast(substrate.coherence); } /** * @brief Get coherence score */ double get_coherence() const { return substrate.coherence; } /** * @brief Get activation level */ double get_activation() const { return substrate.activation; } /** * @brief Get bit density */ double get_density() const { return substrate.density(); } /** * @brief Get phase counter */ uint64_t get_phase() const { return substrate.phase; } /** * @brief Get DNA family name */ const char* get_dna_name() const { return mind_farm::get_dna_name(dna_family); } /** * @brief Get DNA family info */ const DNAFamilyInfo& get_dna_info() const { return mind_farm::get_dna_info(dna_family); } /** * @brief Get deterministic hash */ uint64_t hash() const { return substrate.hash() ^ (static_cast(id) << 32); } /** * @brief Set operation mode */ void set_mode(MindMode new_mode) { mode = new_mode; } /** * @brief Get Hamming distance to another mind */ uint32_t distance(const MindKernel& other) const { return substrate.hamming_distance(other.substrate); } /** * @brief Sync state with another mind (consensus) */ void sync_with(const MindKernel& other, double blend = 0.5) { for (size_t i = 0; i < U64_COUNT; ++i) { // XOR blend: keep bits where both agree uint64_t agree = ~(substrate.state[i] ^ other.substrate.state[i]); uint64_t disagree = substrate.state[i] ^ other.substrate.state[i]; // Randomly resolve disagreements based on blend factor uint64_t resolve = (blend > 0.5) ? other.substrate.state[i] : substrate.state[i]; substrate.state[i] = (agree & substrate.state[i]) | (disagree & resolve); } } }; } // namespace mind_farm