lex-predictive-processing
Multi-domain predictive processing system for the LegionIO cognitive architecture. Manages per-domain generative models with automatic inference mode selection.
What It Does
Maintains a collection of generative models, one per cognitive domain. Each model tracks prediction accuracy, precision, and free energy. The inference mode adapts automatically: perceptual when free energy is low, active when moderate, and hybrid when high free energy coincides with sufficient precision. Each tick, precision decays across all models.
Usage
client = Legion::Extensions::PredictiveProcessing::Client.new
# Add a domain model
client.add_generative_model(domain: :api_latency)
# Generate a prediction
pred = client.predict_from_model(domain: :api_latency, context: { expected: 0.2 })
# => { predicted: true, domain: :api_latency, prediction: { expected_value: 0.2, ... } }
# Observe what actually happened
result = client.observe_outcome(domain: :api_latency, actual: 0.8, predicted: 0.2)
# => { observed: true, domain: :api_latency, prediction_error: 0.6,
# inference_mode: :active, free_energy: 0.6, state: :surprised }
# Check inference mode
client.inference_mode(domain: :api_latency)
# => { domain: :api_latency, mode: :active }
# Global free energy
client.free_energy
# => { global_free_energy: 0.3 }
# Domain-specific free energy
client.free_energy(domain: :api_latency)
# Domains needing attention
client.models_needing_update
client.active_inference_candidates
# Periodic tick (decay)
client.update_predictive_processing
client.predictive_processing_statsInference Modes
| Mode | Condition |
|---|---|
:hybrid |
free_energy > 0.7 AND precision >= 0.5 |
:active |
free_energy > 0.5 |
:perceptual |
otherwise |
Development
bundle install
bundle exec rspec
bundle exec rubocopLicense
MIT