Skip to content

HowardLiYH/NichePopulation

Repository files navigation

🧬 Emergent Specialization in Learner Populations

Competition-Driven Niche Partitioning

Emergent Specialization - 6 Domain Learners



Python 3.9+ License: MIT Data: 100% Real

Niche Partitioning Without Explicit Coordination

PaperInstallationQuick StartExperimentsResultsCitation


📖 Abstract

We present a population-based learning system where learners spontaneously specialize to different environmental regimes without explicit supervision. Drawing from ecological niche theory, we introduce competitive exclusion with niche affinity that creates evolutionary pressure for strategy space partitioning.

Core Thesis: Competition alone, without explicit diversity incentives, is sufficient to induce emergent specialization in learner populations.

Note on Terminology: We use "learner" to denote individual units in the population, each implementing Thompson Sampling over prediction methods. This distinguishes our approach from LLM-based "agents" which are autoregressive language models.

Validated on 6 domains (100% REAL DATA):

  • 📈 Crypto - Bybit Exchange (44,000+ bars) ✅ Real
  • 📊 Commodities - FRED US Government (5,630 daily prices) ✅ Real
  • 🌤️ Weather - Open-Meteo (9,105 observations) ✅ Real
  • ☀️ Solar - Open-Meteo Satellite (116,834 hourly) ✅ Real
  • 🚕 Traffic - NYC TLC Yellow Taxi (2,879 hourly trips) ✅ Real
  • 🌬️ Air Quality - Open-Meteo PM2.5 (2,880 hourly readings) ✅ Real

🎯 Key Results (All Real Data)

Cross-Domain Validation

Domain Source Records Mean SI vs Random vs IQL
📈 Crypto Bybit Exchange 8,766 0.305±0.042 +67% +210%
📊 Commodities FRED (US Gov) 5,630 0.411±0.062 +119% +359%
🌤️ Weather Open-Meteo 9,105 0.205±0.026 +6% +98%
☀️ Solar Open-Meteo 116,834 0.443±0.036 +96% +294%

All data verified REAL from authoritative sources.

Cross-Domain Experimental Results (Unified Pipeline - 30 Trials Each)

All experiments run with identical configuration across all 6 domains:

  • 30 independent trials per experiment
  • 500 iterations per trial
  • 8 learners per population
  • Same random seeds for reproducibility
Domain Data Source Records Regimes SI (Niche) SI (Homo) Cohen's d p-value
Crypto Bybit Exchange 8,766 4 0.786±0.06 0.002 20.05 <0.001***
Commodities FRED (US Gov) 5,630 4 0.773±0.06 0.002 19.89 <0.001***
Weather Open-Meteo 9,105 4 0.758±0.05 0.002 23.44 <0.001***
Solar Open-Meteo 116,834 4 0.764±0.04 0.002 25.71 <0.001***
Traffic NYC TLC 2,879 6 0.573±0.05 0.003 15.86 <0.001***
Air Quality Open-Meteo 2,880 4 0.826±0.04 0.002 32.06 <0.001***
AVERAGE - 145,294 - 0.747 0.002 22.84 ✅ All

Key Findings:

  • All 6 domains show statistically significant specialization (p < 0.001)
  • Average SI = 0.747 across all real data domains
  • Effect sizes are very large (Cohen's d > 15 for all domains)
  • Air Quality shows highest SI (0.826), Traffic lowest (0.573) due to 6 regimes

Lambda Ablation Study (All 6 Domains, 30 Trials Each)

λ Crypto Commodities Weather Solar Traffic Air Quality Avg
0.0 0.314 0.302 0.305 0.256 0.294 0.501 0.329
0.1 0.415 0.409 0.412 0.383 0.331 0.588 0.423
0.2 0.598 0.587 0.613 0.583 0.425 0.769 0.596
0.3 0.786 0.773 0.758 0.764 0.573 0.826 0.747
0.4 0.837 0.835 0.829 0.839 0.708 0.837 0.814
0.5 0.856 0.848 0.858 0.853 0.790 0.800 0.834

Key Finding: Even with λ=0 (no niche bonus), competition alone induces SI > 0.25 across all domains, confirming our core thesis that competition is sufficient for emergent specialization.

Task Performance Metrics (All 6 Domains)

Domain Metric Diverse Homo Δ%
Crypto Sharpe 1.21 0.88 +38%
Commodities Dir. Acc. 65% 54% +21%
Weather RMSE (°C) 2.41 3.20 -25%
Solar MAE (W/m²) 48.3 67.1 -28%
Traffic MAPE (%) 15.1 22.8 -34%
Air Quality RMSE (μg/m³) 4.2 5.8 -28%

Diverse populations consistently outperform homogeneous baselines across all task-specific metrics.

Method Specialization Experiment (NEW)

Learners choose among 5 prediction methods per domain and specialize through competition:

Domain Methods MSI Coverage Niche Perf Homo Perf Δ% p-value
Crypto 5 0.361 79% 0.886 0.626 +41.6% <0.001***
Commodities 5 0.371 73% 0.890 0.648 +37.2% <0.001***
Weather 5 0.402 100% 0.868 0.675 +28.6% <0.001***
Solar 5 0.367 97% 0.925 0.786 +17.6% <0.001***
Traffic 5 0.311 100% 0.917 0.740 +23.8% <0.001***
Air Quality 5 0.371 73% 0.916 0.834 +9.9% <0.001***
Average 5 0.364 87% - - +26.5% ✅ All

Key Findings:

  1. Emergent Method Specialization: Learners develop preferences for specific prediction methods (MSI = 0.364)
  2. Division of Labor: Population uses 87% of available methods on average
  3. Performance Benefit: Diverse populations outperform homogeneous by +26.5% on average

Method Distribution Examples

Crypto Domain:

  • mean_revert: 47.9% of learners
  • momentum_long: 40.8% of learners
  • trend: 8.3% of learners
  • momentum_short: 2.9% of learners

Traffic Domain (best diversity):

  • rush_hour: 32.1% of learners
  • weekly_pattern: 20.4% of learners
  • exp_smooth: 17.1% of learners
  • persistence: 16.2% of learners
  • hourly_avg: 14.2% of learners

📐 Prediction Methods (Mathematical Formulas)

Each domain has 5 prediction methods. Learners learn which method works best for each regime through Thompson sampling.

📈 Crypto Domain

Method Description Formula
naive Persistence p̂ₜ = pₜ₋₁
momentum_short 5-period momentum p̂ₜ = pₜ₋₁ + 0.1 × (pₜ₋₁ - pₜ₋₅)
momentum_long 20-period momentum p̂ₜ = pₜ₋₁ + 0.05 × (pₜ₋₁ - pₜ₋₂₀)
mean_revert Mean reversion to MA20 p̂ₜ = pₜ₋₁ + 0.2 × (MA₂₀ - pₜ₋₁)
trend Linear trend extrapolation p̂ₜ = pₜ₋₁ + slope(pₜ₋₁₀:ₜ)

📊 Commodities Domain

Method Description Formula
naive Persistence p̂ₜ = pₜ₋₁
ma5 5-day moving average p̂ₜ = (1/5) × Σᵢ₌₁⁵ pₜ₋ᵢ
ma20 20-day moving average p̂ₜ = (1/20) × Σᵢ₌₁²⁰ pₜ₋ᵢ
mean_revert Mean reversion (α=0.3) p̂ₜ = pₜ₋₁ + 0.3 × (MA₂₀ - pₜ₋₁)
trend 5-day trend extrapolation p̂ₜ = pₜ₋₁ + (pₜ₋₁ - pₜ₋₅)/5

🌤️ Weather Domain

Method Description Formula
naive Persistence T̂ₜ = Tₜ₋₁
ma3 3-day moving average T̂ₜ = (1/3) × Σᵢ₌₁³ Tₜ₋ᵢ
ma7 7-day moving average T̂ₜ = (1/7) × Σᵢ₌₁⁷ Tₜ₋ᵢ
seasonal Same day last week T̂ₜ = Tₜ₋₇
trend 3-day trend extrapolation T̂ₜ = Tₜ₋₁ + (Tₜ₋₁ - Tₜ₋₃)/3

☀️ Solar Domain

Method Description Formula
naive Persistence Ĝₜ = Gₜ₋₁
ma6 6-hour moving average Ĝₜ = (1/6) × Σᵢ₌₁⁶ Gₜ₋ᵢ
clear_sky Clear sky model Ĝₜ = G_clear(t) (theoretical max)
seasonal Same hour yesterday Ĝₜ = Gₜ₋₂₄
hybrid Weighted blend Ĝₜ = 0.6 × Gₜ₋₁ + 0.4 × G_clear(t)

🚕 Traffic Domain

Method Description Formula
persistence Last value v̂ₜ = vₜ₋₁
hourly_average Historical hourly mean v̂ₜ = v̄_h(t) where h(t) = hour of day
weekly_pattern Same hour last week v̂ₜ = vₜ₋₁₆₈ (168 = 24×7 hours)
rush_hour_model Regime-based prediction v̂ₜ = v̄_regime(t)
exponential_smoothing EMA (α=0.3) v̂ₜ = 0.3·vₜ₋₁ + 0.7·v̂ₜ₋₁

🌬️ Air Quality Domain

Method Description Formula
persistence Last value q̂ₜ = qₜ₋₁
hourly_average Historical hourly mean q̂ₜ = q̄_h(t)
moving_average 24-hour MA q̂ₜ = (1/24) × Σᵢ₌₁²⁴ qₜ₋ᵢ
regime_average AQI regime-based q̂ₜ = q̄_regime(qₜ₋₁)
exponential_smoothing EMA (α=0.3) q̂ₜ = 0.3·qₜ₋₁ + 0.7·q̂ₜ₋₁

Method Categories

Category Methods Best For
Baseline naive, persistence Stable regimes, hard to beat
Smoothing ma3, ma5, ma7, ma20, moving_average Noisy data, reduces variance
Momentum momentum_short, momentum_long, trend Trending regimes
Mean Reversion mean_revert Volatile regimes, overshoots
Seasonal seasonal, weekly_pattern, hourly_average Predictable patterns
Adaptive exponential_smoothing, hybrid Balance between recent and history

Experimental Rigor Checklist

Requirement Status
Same trials across all domains ✅ 30 trials
Same iterations per trial ✅ 500 iterations
Same number of learners ✅ 8 learners
Same methods per domain ✅ 5 methods
Lambda ablation on ALL domains ✅ 6 λ values × 6 domains
Method specialization on ALL domains ✅ 8 learners × 5 methods × 6 domains
Statistical tests on ALL domains ✅ t-test, Cohen's d, p-value
Random baseline on ALL domains ✅ 30 trials each
Homogeneous baseline on ALL domains ✅ 30 trials each
100% Real data ✅ All 6 domains

Data Source Verification

Domain Source Verification
📈 Crypto Bybit Exchange ✅ Real exchange data with funding rates, OI, basis
📊 Commodities fred.stlouisfed.org ✅ US Government official data (captured -$36.98 oil on 2020-04-20)
🌤️ Weather Open-Meteo API ✅ ERA5 reanalysis + weather stations
☀️ Solar Open-Meteo Solar ✅ CAMS satellite-derived irradiance

🏗️ Architecture

emergent_specialization/
├── 📁 src/                           # Core implementation
│   ├── domains/                      # ⭐ Multi-domain validation
│   │   ├── crypto.py                 # Bybit real data
│   │   ├── commodities.py            # FRED real data
│   │   ├── weather.py                # Open-Meteo real data
│   │   └── solar.py                  # Open-Meteo solar data
│   ├── learners/                     # Learner implementations
│   │   ├── niche_population.py       # ⭐ Core: Competitive exclusion
│   │   └── inventory_v2.py           # Prediction methods
│   └── baselines/                    # Comparison baselines
│       ├── marl_baselines.py         # IQL, QMIX, MAPPO
│       └── oracle.py                 # Perfect regime knowledge
├── 📁 experiments/                   # Experiment scripts
│   ├── exp_real_data_v2.py           # ⭐ Main 4-domain experiment
│   └── exp_marl_comparison.py        # ⭐ MARL baseline comparison
├── 📁 data/                          # Real-world datasets
│   ├── bybit/                        # Crypto exchange data
│   ├── commodities/                  # FRED commodity prices
│   ├── weather/                      # Open-Meteo weather
│   └── solar/                        # Open-Meteo solar
├── 📁 results/                       # Experiment outputs
│   └── figures/                      # Publication figures
├── 📁 paper/                         # arXiv paper
│   ├── propositions.tex              # 3 theoretical propositions
│   └── limitations.tex               # Limitations section
└── 📁 scripts/                       # Data download utilities

🚀 Quick Start

Installation

# Clone repository
git clone https://github.com/HowardLiYH/NichePopulation.git
cd NichePopulation

# Create conda environment
conda create -n emergent python=3.10
conda activate emergent

# Install dependencies
pip install -e .

Download Real Data

# Weather (Open-Meteo - no API key needed)
python scripts/download_real_weather.py

# Solar (Open-Meteo - no API key needed)
python scripts/download_real_solar.py

# Commodities (FRED - no API key needed)
python scripts/download_fred_commodities_real.py

Run Experiments

# Main experiment on all 4 real domains
python experiments/exp_real_data_v2.py

# MARL baseline comparison
python experiments/exp_marl_comparison.py

# Generate publication figures
python scripts/generate_real_data_figures.py

📈 SI-Performance Correlation (NEW)

Metric Value Interpretation
Pearson r 0.525 Moderate-strong positive correlation
p-value < 0.0001 Highly significant
Regression Δ% = 52.9 × SI - 14.2 Higher SI → Better performance
0.276 SI explains 28% of performance variance

Per-Domain Correlation:

Domain r p-value Interpretation
Crypto +0.411 0.024* Moderate
Commodities +0.591 0.0006*** Strong
Weather +0.349 0.059 Boundary condition (P3)
Solar +0.515 0.004** Strong

Weather as Boundary Condition: Weather validates Proposition 3 (Mono-Regime Collapse) - its low k_eff (1.8) leads to lower SI and weaker correlation, which is expected behavior, not failure.


🔬 Theoretical Foundation (Formal Proofs)

Three Propositions with Rigorous Proofs

Proposition 1: Competitive Exclusion (Game-Theoretic Proof)

In a winner-take-all game with n learners competing across k regimes, complete competitors cannot coexist at Nash equilibrium.

Proof: When identical strategies yield payoff V/n - c, deviation to empty niche yields V - c > V/n - c for n ≥ 2. No symmetric Nash equilibrium exists. See paper/propositions_formal.tex for complete proof.

Proposition 2: SI Lower Bound (Optimization Proof)

For niche bonus λ > 0 and k regimes: E[SI] ≥ λ/(1+λ) · (1 - 1/k)

Proof: Using Lagrangian optimization on the learner's reward function with entropy constraint. For λ=0.3, k=4: SI ≥ 0.173. Our observed SI (0.20-0.76) exceeds this bound.

Proposition 3: Mono-Regime Collapse (Limit Analysis)

As dominant regime fraction η → 1, meaningful SI → 0.

Proof: k_eff = exp(H(regime_dist)). As η → 1, k_eff → 1, leaving nothing to specialize between. Weather (k_eff ≈ 1.8) validates this.

See paper/propositions_formal.tex for complete mathematical proofs.


📊 Figures

Five publication-quality figures in results/figures/:

  1. fig1_cross_domain_si.pdf - Cross-domain SI comparison
  2. fig2_marl_comparison.pdf - MARL baseline comparison
  3. fig3_improvement_scatter.pdf - SI vs improvement correlation
  4. fig4_regime_distribution.pdf - Regime distributions by domain
  5. fig5_summary_heatmap.pdf - Summary heatmap

📋 Changelog

v3.0.0 (2026-01-16) - Learner Populations Reframing ⭐

Major Update: Reframed from "Multi-Agent Systems" to "Learner Populations"

  • Terminology Update: "agents" → "learners" throughout
  • Paper Title: "Emergent Specialization in Learner Populations"
  • Clearer Positioning: Distinguishes from LLM-based agents
  • arXiv Ready: Updated paper ready for submission

v2.0.0 (2024-12-23) - Real Data Validation

Major Update: All experiments now use 100% verified real data

  • 4 Real Data Domains: Crypto, Commodities, Weather, Solar
  • 175K+ real records across all domains
  • MARL Comparison: NichePopulation beats IQL by 2-4x
  • 5 Publication Figures generated
  • 3 Theoretical Propositions with proof sketches
  • Limitations Section for honest assessment

v1.7.0 (2024-12-22) - Unified Prediction & Mechanistic Analysis

  • 📊 Unified prediction experiment across domains
  • 🔬 Mechanistic analysis: why specialization works
  • ⚡ Computational benchmarks: 2-4× faster than MARL

v1.6.0 (2024-12-22) - Multi-Domain Validation

  • 🚕 NYC Taxi (Traffic): SI = 0.73
  • ⚡ EIA Energy: SI = 0.88
  • 📈 Bybit Finance: SI = 0.86

🔬 Reproducibility

Setting Value
Random Seeds 0-29 (30 trials per experiment)
Statistical Tests Bonferroni-corrected (α = 0.05/k)
Confidence Intervals 95% Bootstrap CI
Effect Sizes Cohen's d reported

All data sources are free and publicly accessible without API keys.


📚 Citation

@misc{li2026emergent,
  title     = {Emergent Specialization in Learner Populations:
               Competition as the Source of Diversity},
  author    = {Li, Yuhao},
  year      = {2026},
  howpublished = {\url{https://github.com/HowardLiYH/NichePopulation}},
  note      = {arXiv preprint}
}

📄 License

MIT License - See LICENSE for details.


⭐ Star this repo if you find it useful!

Report BugRequest Feature

About

Competition-driven emergent specialization in learner populations. Learners naturally partition into niche specialists without explicit coordination. Validated on 6 real-world domains with 145K+ records.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages