| Crates.io | omega-hippocampus |
| lib.rs | omega-hippocampus |
| version | 1.1.0 |
| created_at | 2025-12-12 07:10:36.145412+00 |
| updated_at | 2025-12-12 07:10:36.145412+00 |
| description | Hippocampal memory system for ExoGenesis Omega - DG/CA3/CA1 circuits, pattern separation/completion, replay |
| homepage | |
| repository | https://github.com/prancer-io/ExoGenesis-Omega |
| max_upload_size | |
| id | 1981102 |
| size | 123,557 |
Biologically-inspired hippocampal memory system with pattern separation, completion, and sharp-wave ripple replay.
Part of the ExoGenesis-Omega cognitive architecture.
omega-hippocampus implements a computational model of the hippocampal formation, the brain region critical for episodic memory and spatial navigation. The model includes:
Add this to your Cargo.toml:
[dependencies]
omega-hippocampus = "1.0.0"
use omega_hippocampus::{Hippocampus, HippocampusConfig};
fn main() {
// Create hippocampus with default configuration
let config = HippocampusConfig::default();
let mut hippo = Hippocampus::new(config);
// Encode a new memory
let input = vec![0.5; 256];
let memory_id = hippo.encode(&input, None)?;
println!("Encoded memory: {}", memory_id);
// Retrieve with partial cue (pattern completion)
let partial_cue = create_partial_cue(&input, 0.3); // 30% of original
let retrieved = hippo.retrieve(&partial_cue)?;
if let Some(memory) = retrieved {
println!("Retrieved memory with similarity: {:.3}", memory.similarity);
}
// Trigger replay during "sleep"
let replayed = hippo.replay(10)?; // Replay 10 memories
println!("Replayed {} memories", replayed.len());
}
┌─────────────────────────────────────────────────────────────────────┐
│ HIPPOCAMPAL FORMATION │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │ ENTORHINAL CORTEX (EC) │ │
│ │ Grid Cells │ Input/Output Interface │ │
│ └────────────────────────────────────────────────────────────────┘ │
│ ↓ Perforant Path ↑ │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │ DENTATE GYRUS (DG) │ │
│ │ Pattern Separation │ Sparse Coding │ 10x Expansion │ │
│ └────────────────────────────────────────────────────────────────┘ │
│ ↓ Mossy Fibers │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │ CA3 │ │
│ │ Autoassociative │ Pattern Completion │ Recurrent Connections │ │
│ └────────────────────────────────────────────────────────────────┘ │
│ ↓ Schaffer Collaterals │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │ CA1 │ │
│ │ Output Layer │ Consolidation │ To Neocortex │ │
│ └────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────┐ ┌──────────────────────────────────────┐ │
│ │ PLACE CELLS │ │ SHARP-WAVE RIPPLES │ │
│ │ Spatial Memory │ │ Memory Replay │ Consolidation │ │
│ └─────────────────────┘ └──────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
The DG separates similar patterns into distinct representations:
use omega_hippocampus::{DentateGyrus, GranuleCell};
// Create DG with 10x expansion
let mut dg = DentateGyrus::new(256, 2560, 0.02); // 2% sparsity
// Encode two similar patterns
let pattern1 = vec![0.5; 256];
let pattern2 = pattern1.iter().map(|x| x + 0.1).collect(); // Slight variation
let sparse1 = dg.encode(&pattern1);
let sparse2 = dg.encode(&pattern2);
// Sparse codes are more orthogonal than original patterns
let original_sim = cosine_similarity(&pattern1, &pattern2);
let sparse_sim = cosine_similarity(&sparse1, &sparse2);
println!("Original similarity: {:.3}", original_sim); // ~0.99
println!("Sparse similarity: {:.3}", sparse_sim); // ~0.30
CA3 implements autoassociative memory for completing partial patterns:
use omega_hippocampus::{CA3Network, PatternCompletion};
let mut ca3 = CA3Network::new(512, 0.04); // 4% recurrent connectivity
// Store a pattern
let pattern = vec![0.5; 512];
ca3.store(&pattern)?;
// Retrieve with only 30% of the pattern
let partial = create_partial_pattern(&pattern, 0.3);
let completed = ca3.complete(&partial, 100)?; // 100 iterations
// Measure completion accuracy
let accuracy = cosine_similarity(&pattern, &completed);
println!("Completion accuracy: {:.3}", accuracy); // ~0.95
use omega_hippocampus::{PlaceCell, PlaceField};
// Create place cell with field at (50, 50) with radius 10
let mut pc = PlaceCell::new(0, (50.0, 50.0), 10.0);
// Compute firing rate at different locations
let rate_at_center = pc.compute(50.0, 50.0); // ~1.0
let rate_at_edge = pc.compute(60.0, 50.0); // ~0.37
let rate_outside = pc.compute(100.0, 100.0); // ~0.0
println!("At center: {:.3}", rate_at_center);
println!("At edge: {:.3}", rate_at_edge);
println!("Outside: {:.3}", rate_outside);
use omega_hippocampus::{GridCell, EntorhinalCortex};
// Create grid cell with 30cm spacing
let mut gc = GridCell::new(0, 30.0, 0.0);
// Activation is periodic with hexagonal pattern
let a1 = gc.compute(0.0, 0.0); // Peak
let a2 = gc.compute(15.0, 0.0); // Trough
let a3 = gc.compute(30.0, 0.0); // Adjacent peak
println!("Origin: {:.3}", a1);
println!("Half spacing: {:.3}", a2);
println!("Full spacing: {:.3}", a3);
use omega_hippocampus::place_cells::HeadDirectionCell;
use std::f64::consts::PI;
// Cell preferring 0 degrees (facing right)
let mut hd = HeadDirectionCell::new(0.0);
let facing_preferred = hd.compute(0.0); // ~1.0
let facing_opposite = hd.compute(PI); // ~0.0
let facing_orthogonal = hd.compute(PI/2.0); // ~0.5
println!("Preferred: {:.3}", facing_preferred);
println!("Opposite: {:.3}", facing_opposite);
Memory replay during rest/sleep:
use omega_hippocampus::{ReplayBuffer, SharpWaveRipple, ReplayEvent};
let mut buffer = ReplayBuffer::new(1000, 0.7);
// Add memories to buffer
for i in 0..100 {
let pattern = generate_memory(i);
buffer.add(pattern, 0.5 + (i as f64 * 0.005)); // Increasing importance
}
// Trigger sharp-wave ripple replay
let ripple = buffer.trigger_ripple()?;
println!("Ripple:");
println!(" Frequency: {:.1} Hz", ripple.frequency);
println!(" Duration: {:.1} ms", ripple.duration_ms);
println!(" Memories replayed: {}", ripple.replayed_count);
// Get replay events
let events = buffer.get_replay_events(10);
for event in events {
println!(" Replayed memory with importance {:.3}", event.importance);
}
use omega_hippocampus::HippocampusConfig;
let config = HippocampusConfig {
input_dim: 256,
dg_size: 2560, // 10x expansion
ca3_size: 512,
ca1_size: 256,
dg_sparsity: 0.02, // 2% active
ca3_recurrence: 0.04, // 4% recurrent connections
learning_rate: 0.01,
replay_buffer_size: 1000,
ripple_threshold: 0.7,
};
let hippo = Hippocampus::new(config);
use omega_hippocampus::MemoryTrace;
// Memory traces contain multi-layer representations
let trace = hippo.encode(&input, Some("important_event".to_string()))?;
println!("Memory trace:");
println!(" ID: {}", trace.id);
println!(" DG code sparsity: {:.3}", sparsity(&trace.dg_code));
println!(" CA3 representation: {} dims", trace.ca3_code.len());
println!(" CA1 output: {} dims", trace.ca1_output.len());
println!(" Strength: {:.3}", trace.strength);
println!(" Age: {:?}", trace.created_at.elapsed());
// Store episodes with context
let episode = Episode {
what: encode("met John"),
where_: encode("coffee shop"),
when: encode("yesterday"),
};
let memory_id = hippo.encode_episode(&episode)?;
// Later, cue with partial info
let cue = encode("coffee shop");
let recalled = hippo.recall_episode(&cue)?;
// Returns: what=met John, where=coffee shop, when=yesterday
// Build spatial map as agent explores
let mut spatial_map = SpatialMap::new(100.0, 100.0, 20);
for position in agent_path {
spatial_map.update(position, &observation);
}
// Compute rate map for place cell
let rate_map = spatial_map.compute_rate_map(place_cell_id, num_bins);
// During "sleep", consolidate important memories
hippo.initiate_consolidation()?;
// Replay prioritized by importance
let consolidated = hippo.consolidate(|memory| {
memory.importance > 0.5 && memory.replay_count < 3
})?;
println!("Consolidated {} memories", consolidated);
omega-brain (Unified Integration)
└── omega-hippocampus (This crate)
├── Pattern separation (DG)
├── Pattern completion (CA3)
├── Memory output (CA1)
├── Spatial navigation (EC)
└── Replay during sleep
Used with:
├── omega-sleep - Triggers replay during SWS/REM
├── omega-attention - What gets encoded
└── omega-consciousness - Conscious recall
Licensed under the MIT License. See LICENSE for details.