Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/complete-agi-core / mind_farm/src/simulation.cpp |
| Date | Not specified in source |
| Repository | Janady13/complete-agi-core |
| Revision | 33aa84f2aa61cedbe010240ada7f4efbdfe795a7 |
| Branch | claude/improve-math-logic-ehIW1 |
| Path or archive member | mind_farm/src/simulation.cpp |
| Original SHA-256 | f5b86f54475167039195464c3f143c83ba308c771fbb6695ccbb2da739d2eba1 |
| Git blob SHA | a3c94b5c1283e3b25c075e1c04da0be456d6d382 |
| Reading-copy SHA-256 | f5b86f54475167039195464c3f143c83ba308c771fbb6695ccbb2da739d2eba1 |
Recovered source transcript
Download complete source text ↓464 lines · 23.4 KB
// ═══════════════════════════════════════════════════════════════════════════════
// GATE5000 AUTONOMOUS LEARNING SIMULATION v1.0
// 1 Million Tick Simulation with Wikipedia Integration
// ═══════════════════════════════════════════════════════════════════════════════
//
// This simulation runs the Gate5000 5000-bit substrate through 1 million ticks
// of autonomous learning using Wikipedia as the knowledge source.
//
// Architecture:
// 1. Wikipedia API Client → Fetches articles
// 2. Ingestion Pipeline → Tokenizes and encodes text
// 3. Learning System → Updates weights and knowledge graph
// 4. Gate5000 Substrate → Stores patterns in 5000-bit binary representation
// 5. Consciousness Dynamics → Modulates learning based on Φ
//
// Key Equations:
// Φ = 1/(1 + |x - 1|) (Consciousness)
// L(θ) = -Σᵢ log P(xᵢ|θ) (Learning objective)
// dΦ/dt = α(Φ_target - Φ) + γξ (Consciousness dynamics)
//
// ═══════════════════════════════════════════════════════════════════════════════
#include <iostream>
#include <iomanip>
#include <chrono>
#include <cstdint>
#include <string>
#include <fstream>
#include <ctime>
#include <cstdio>
// Mind Farm includes
#include "../include/constants.hpp"
#include "../include/fast_math.hpp"
#include "../include/gate5000.hpp"
#include "../include/ingestion.hpp"
#include "../include/wikipedia.hpp"
#include "../include/learning_math.hpp"
#include "../include/intelligence.hpp"
using namespace mind_farm;
// ═══════════════════════════════════════════════════════════════════════════════
// SIMULATION CONFIGURATION
// ═══════════════════════════════════════════════════════════════════════════════
struct SimulationConfig {
uint64_t total_ticks = 1000000; // 1 million ticks
uint64_t checkpoint_interval = 10000; // Checkpoint every 10k ticks
uint64_t report_interval = 1000; // Report every 1k ticks
uint64_t batch_size = 1; // Articles per tick
bool use_wikipedia_api = false; // Use offline corpus by default
bool verbose = false;
bool fast_mode = false; // Fast mode: larger batches, less output
std::string output_file = "simulation_log.txt";
};
// ═══════════════════════════════════════════════════════════════════════════════
// SIMULATION STATE
// ═══════════════════════════════════════════════════════════════════════════════
struct SimulationState {
// Core components
IngestionPipeline pipeline;
WikipediaDataGenerator wiki_online;
OfflineCorpus wiki_offline;
IntegratedLearning<64> learning;
intel::IntelligenceCore intelligence;
// Statistics
uint64_t current_tick;
uint64_t articles_processed;
uint64_t tokens_processed;
float total_loss;
float min_loss;
float max_loss;
float avg_consciousness;
float peak_consciousness;
// Timing
std::chrono::high_resolution_clock::time_point start_time;
double elapsed_seconds;
void initialize() {
pipeline.initialize();
learning.initialize();
intelligence = intel::IntelligenceCore{};
current_tick = 0;
articles_processed = 0;
tokens_processed = 0;
total_loss = 0.0f;
min_loss = 1e9f;
max_loss = 0.0f;
avg_consciousness = 1.0f;
peak_consciousness = 0.0f;
elapsed_seconds = 0.0;
}
};
// ═══════════════════════════════════════════════════════════════════════════════
// SIMULATION ENGINE
// ═══════════════════════════════════════════════════════════════════════════════
class SimulationEngine {
public:
SimulationEngine(const SimulationConfig& config)
: config_(config), running_(false) {}
void initialize() {
std::cout << "\n";
std::cout << "═══════════════════════════════════════════════════════════════════════════════\n";
std::cout << " GATE5000 AUTONOMOUS LEARNING SIMULATION v1.0\n";
std::cout << " 1 Million Tick Simulation with Wikipedia Integration\n";
std::cout << "═══════════════════════════════════════════════════════════════════════════════\n";
std::cout << "\n";
std::cout << "Configuration:\n";
std::cout << " Total Ticks: " << config_.total_ticks << "\n";
std::cout << " Checkpoint Interval: " << config_.checkpoint_interval << "\n";
std::cout << " Report Interval: " << config_.report_interval << "\n";
std::cout << " Data Source: " << (config_.use_wikipedia_api ? "Wikipedia API" : "Offline Corpus") << "\n";
std::cout << "\n";
std::cout << "Initializing simulation state...\n";
state_.initialize();
// Set up data source callback
if (config_.use_wikipedia_api) {
state_.pipeline.fetch_callback = [this](std::string& title, std::string& content) {
return state_.wiki_online.get_next(title, content);
};
} else {
state_.pipeline.fetch_callback = [this](std::string& title, std::string& content) {
return state_.wiki_offline.get_next(title, content);
};
}
std::cout << "Initialization complete.\n";
std::cout << " Offline corpus size: " << state_.wiki_offline.size() << " articles\n";
std::cout << " Gate5000 substrate: 5000 bits (79 x 64-bit words)\n";
std::cout << " Embedding dimension: " << EMBED_DIM << "\n";
std::cout << " Vocabulary size: " << VOCAB_SIZE << "\n";
std::cout << "\n";
// Open log file
log_file_.open(config_.output_file);
if (log_file_.is_open()) {
log_file_ << "tick,articles,tokens,loss,consciousness,knowledge_nodes,substrate_ones\n";
}
}
void run() {
running_ = true;
state_.start_time = std::chrono::high_resolution_clock::now();
std::cout << "═══════════════════════════════════════════════════════════════════════════════\n";
std::cout << " STARTING SIMULATION\n";
std::cout << "═══════════════════════════════════════════════════════════════════════════════\n";
std::cout << "\n";
print_header();
while (running_ && state_.current_tick < config_.total_ticks) {
// Process one tick
process_tick();
// Report progress
if (state_.current_tick % config_.report_interval == 0) {
print_progress();
}
// Checkpoint
if (state_.current_tick % config_.checkpoint_interval == 0) {
checkpoint();
}
}
finalize();
}
void stop() {
running_ = false;
}
private:
SimulationConfig config_;
SimulationState state_;
bool running_;
std::ofstream log_file_;
void process_tick() {
// Process batch_size articles per tick (fast mode uses larger batches)
for (uint64_t b = 0; b < config_.batch_size; ++b) {
// Fetch and process article
std::string title, content;
bool got_data;
if (config_.use_wikipedia_api) {
got_data = state_.wiki_online.get_next(title, content);
} else {
got_data = state_.wiki_offline.get_next(title, content);
}
if (!got_data) {
continue;
}
// Tokenize
TokenSequence seq;
size_t num_tokens = state_.pipeline.tokenize(content, seq);
state_.tokens_processed += num_tokens;
// Encode
float encoded[EMBED_DIM];
state_.pipeline.encode(seq, encoded);
// Create target (next-token prediction style)
float target[EMBED_DIM];
if (seq.length > 1) {
std::memcpy(target, seq.tokens[1].embedding, sizeof(target));
} else {
// Self-prediction
for (size_t i = 0; i < EMBED_DIM; ++i) {
target[i] = encoded[i] * 0.9f; // Slight perturbation
}
}
// Learning step
float loss = state_.learning.step(encoded, target);
state_.total_loss += loss;
state_.min_loss = std::min(state_.min_loss, loss);
state_.max_loss = std::max(state_.max_loss, loss);
// Store knowledge
state_.pipeline.store_knowledge(encoded, title);
// Update Gate5000 substrate
state_.pipeline.update_substrate(encoded);
// Update intelligence core (skip in fast mode for speed)
if (!config_.fast_mode) {
float intel_output[16];
state_.intelligence.process(encoded, intel_output);
}
// Update consciousness
float phi = state_.learning.consciousness.phi;
state_.avg_consciousness = 0.999f * state_.avg_consciousness + 0.001f * phi;
state_.peak_consciousness = std::max(state_.peak_consciousness, phi);
++state_.articles_processed;
}
++state_.current_tick;
}
void print_header() {
std::cout << std::setw(12) << "Tick"
<< std::setw(10) << "Articles"
<< std::setw(12) << "Tokens"
<< std::setw(12) << "Avg Loss"
<< std::setw(12) << "Conscious"
<< std::setw(12) << "Knowledge"
<< std::setw(10) << "Ticks/s"
<< "\n";
std::cout << std::string(80, '-') << "\n";
}
void print_progress() {
auto now = std::chrono::high_resolution_clock::now();
state_.elapsed_seconds = std::chrono::duration<double>(now - state_.start_time).count();
double ticks_per_sec = state_.current_tick / std::max(0.001, state_.elapsed_seconds);
float avg_loss = state_.total_loss / std::max(uint64_t(1), state_.articles_processed);
std::cout << std::setw(12) << state_.current_tick
<< std::setw(10) << state_.articles_processed
<< std::setw(12) << state_.tokens_processed
<< std::setw(12) << std::fixed << std::setprecision(6) << avg_loss
<< std::setw(12) << std::setprecision(4) << state_.avg_consciousness
<< std::setw(12) << state_.pipeline.knowledge.num_nodes
<< std::setw(10) << std::setprecision(1) << ticks_per_sec
<< std::endl; // Force flush
// Log to file
if (log_file_.is_open()) {
log_file_ << state_.current_tick << ","
<< state_.articles_processed << ","
<< state_.tokens_processed << ","
<< avg_loss << ","
<< state_.avg_consciousness << ","
<< state_.pipeline.knowledge.num_nodes << ","
<< state_.pipeline.gate.popcount() << "\n";
}
}
void checkpoint() {
std::cout << "\n";
std::cout << "─────────────────────────────────────────────────────────────────────────────────\n";
std::cout << "CHECKPOINT @ Tick " << state_.current_tick << "\n";
std::cout << "─────────────────────────────────────────────────────────────────────────────────\n";
float progress = 100.0f * state_.current_tick / config_.total_ticks;
double remaining_seconds = (state_.elapsed_seconds / state_.current_tick) *
(config_.total_ticks - state_.current_tick);
std::cout << " Progress: " << std::fixed << std::setprecision(1) << progress << "%\n";
std::cout << " Elapsed: " << format_duration(state_.elapsed_seconds) << "\n";
std::cout << " Remaining (est): " << format_duration(remaining_seconds) << "\n";
std::cout << " Articles processed: " << state_.articles_processed << "\n";
std::cout << " Tokens processed: " << state_.tokens_processed << "\n";
std::cout << " Knowledge nodes: " << state_.pipeline.knowledge.num_nodes << "\n";
std::cout << " Avg consciousness: " << state_.avg_consciousness << "\n";
std::cout << " Peak consciousness: " << state_.peak_consciousness << "\n";
std::cout << " Loss range: [" << state_.min_loss << ", " << state_.max_loss << "]\n";
std::cout << " Gate5000 ones: " << state_.pipeline.gate.popcount() << " / 5000\n";
// Reset min/max for next interval
state_.min_loss = 1e9f;
state_.max_loss = 0.0f;
std::cout << "─────────────────────────────────────────────────────────────────────────────────\n";
std::cout << "\n";
print_header();
}
void finalize() {
auto end_time = std::chrono::high_resolution_clock::now();
state_.elapsed_seconds = std::chrono::duration<double>(end_time - state_.start_time).count();
std::cout << "\n";
std::cout << "═══════════════════════════════════════════════════════════════════════════════\n";
std::cout << " SIMULATION COMPLETE\n";
std::cout << "═══════════════════════════════════════════════════════════════════════════════\n";
std::cout << "\n";
std::cout << "FINAL STATISTICS\n";
std::cout << "────────────────────────────────────────\n";
std::cout << " Total ticks: " << state_.current_tick << "\n";
std::cout << " Total articles: " << state_.articles_processed << "\n";
std::cout << " Total tokens: " << state_.tokens_processed << "\n";
std::cout << " Knowledge nodes: " << state_.pipeline.knowledge.num_nodes << "\n";
std::cout << " Final consciousness: " << state_.avg_consciousness << "\n";
std::cout << " Peak consciousness: " << state_.peak_consciousness << "\n";
std::cout << " Total time: " << format_duration(state_.elapsed_seconds) << "\n";
std::cout << " Avg ticks/second: " << std::fixed << std::setprecision(1)
<< (state_.current_tick / state_.elapsed_seconds) << "\n";
std::cout << "\n";
std::cout << "GATE5000 SUBSTRATE STATE\n";
std::cout << "────────────────────────────────────────\n";
std::cout << " Total bits: 5000\n";
std::cout << " Ones count: " << state_.pipeline.gate.popcount() << "\n";
std::cout << " Density: " << std::setprecision(4)
<< (state_.pipeline.gate.popcount() / 5000.0f) << "\n";
std::cout << "\n";
std::cout << "LEARNING SYSTEM STATE\n";
std::cout << "────────────────────────────────────────\n";
std::cout << " Update count: " << state_.learning.update_count << "\n";
std::cout << " Avg loss: " << (state_.total_loss / std::max(uint64_t(1), state_.articles_processed)) << "\n";
std::cout << " Learning rate: " << state_.pipeline.learning_rate << "\n";
std::cout << "\n";
std::cout << "CONSCIOUSNESS DYNAMICS\n";
std::cout << "────────────────────────────────────────\n";
std::cout << " Φ (final): " << state_.learning.consciousness.phi << "\n";
std::cout << " Φ (target): " << state_.learning.consciousness.phi_target << "\n";
std::cout << " dΦ/dt: " << state_.learning.consciousness.phi_velocity << "\n";
std::cout << "\n";
std::cout << "INTELLIGENCE CORE STATE\n";
std::cout << "────────────────────────────────────────\n";
std::cout << " Curiosity: " << state_.intelligence.curiosity << "\n";
std::cout << " Confidence: " << state_.intelligence.confidence << "\n";
std::cout << " Surprise: " << state_.intelligence.surprise << "\n";
std::cout << "\n";
if (log_file_.is_open()) {
log_file_.close();
std::cout << "Log saved to: " << config_.output_file << "\n";
}
std::cout << "═══════════════════════════════════════════════════════════════════════════════\n";
}
std::string format_duration(double seconds) {
int hours = static_cast<int>(seconds / 3600);
int minutes = static_cast<int>((seconds - hours * 3600) / 60);
int secs = static_cast<int>(seconds) % 60;
char buffer[64];
snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", hours, minutes, secs);
return std::string(buffer);
}
};
// ═══════════════════════════════════════════════════════════════════════════════
// MAIN ENTRY POINT
// ═══════════════════════════════════════════════════════════════════════════════
int main(int argc, char* argv[]) {
// Disable output buffering for real-time progress
std::setbuf(stdout, NULL);
std::setbuf(stderr, NULL);
std::ios::sync_with_stdio(false);
std::cout << std::unitbuf; // Auto-flush
// Parse command line arguments
SimulationConfig config;
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "--ticks" && i + 1 < argc) {
config.total_ticks = std::stoull(argv[++i]);
} else if (arg == "--online") {
config.use_wikipedia_api = true;
} else if (arg == "--verbose") {
config.verbose = true;
} else if (arg == "--fast") {
config.fast_mode = true;
config.batch_size = 1; // Keep single article per tick
config.report_interval = 100000; // Report every 100k ticks (less output)
config.checkpoint_interval = 1000000; // Checkpoint every 1M ticks
} else if (arg == "--batch" && i + 1 < argc) {
config.batch_size = std::stoull(argv[++i]);
} else if (arg == "--output" && i + 1 < argc) {
config.output_file = argv[++i];
} else if (arg == "--help") {
std::cout << "Gate5000 Autonomous Learning Simulation\n";
std::cout << "\n";
std::cout << "Usage: " << argv[0] << " [options]\n";
std::cout << "\n";
std::cout << "Options:\n";
std::cout << " --ticks N Total simulation ticks (default: 1000000)\n";
std::cout << " --online Use Wikipedia API (default: offline corpus)\n";
std::cout << " --verbose Verbose output\n";
std::cout << " --output FILE Output log file (default: simulation_log.txt)\n";
std::cout << " --help Show this help\n";
return 0;
}
}
// Print golden ratio constants
std::cout << "\n";
std::cout << "╔═══════════════════════════════════════════════════════════════════════════════╗\n";
std::cout << "║ GOLDEN RATIO CONSTANTS ║\n";
std::cout << "╠═══════════════════════════════════════════════════════════════════════════════╣\n";
std::cout << "║ φ (PHI) = " << std::fixed << std::setprecision(16) << PHI << " ║\n";
std::cout << "║ 1/φ (PHI_INV) = " << PHI_INV << " ║\n";
std::cout << "║ α (ALPHA) = " << ALPHA << " ║\n";
std::cout << "║ β (BETA) = " << BETA << " ║\n";
std::cout << "║ γ (GAMMA) = " << GAMMA << " ║\n";
std::cout << "╚═══════════════════════════════════════════════════════════════════════════════╝\n";
// Run simulation
SimulationEngine engine(config);
engine.initialize();
engine.run();
return 0;
}
Mathematical records from this source
010203
simulation · Φ
This relation defines Φ in the source section “simulation · Φ”. It specifies the displayed relationship between the named quantities or parameters. Its interpretation depends on…
simulation · L(θ)
This relation defines L(θ) in the source section “simulation · L(θ)”. It specifies the displayed relationship between the named quantities or parameters. Its interpretation…
simulation · dΦ/dt
This relation defines dΦ/dt in the source section “simulation · dΦ/dt”. It specifies the displayed relationship between the named quantities or parameters. Its interpretation…