| # HippocampAIF β End-to-End Codebase Guide |
|
|
| **A Biologically Grounded Cognitive Architecture for One-Shot Learning & Active Inference** |
|
|
| License: Β© 2026 Algorembrant, Rembrant Oyangoren Albeos |
|
|
| --- |
|
|
| ## Table of Contents |
|
|
| 1. [What This Is](#what-this-is) |
| 2. [Theoretical Foundations](#theoretical-foundations) |
| 3. [Architecture Map](#architecture-map) |
| 4. [Setup](#setup) |
| 5. [Module Reference](#module-reference) |
| 6. [How the Pipeline Works](#how-the-pipeline-works) |
| 7. [Using the MNIST Agent](#using-the-mnist-agent) |
| 8. [Using the Breakout Agent](#using-the-breakout-agent) |
| 9. [Running Tests](#running-tests) |
| 10. [Extending the Framework](#extending-the-framework) |
| 11. [Design Decisions & Rationale](#design-decisions--rationale) |
| 12. [File Map](#file-map) |
|
|
| --- |
|
|
| ## What This Is |
|
|
| HippocampAIF is a **complete cognitive architecture** implemented in pure Python (NumPy + SciPy only β no PyTorch, no TensorFlow, no JAX). Every module corresponds to a real brain structure with citations to the computational neuroscience literature. |
|
|
| The framework does two things that conventional ML cannot: |
|
|
| 1. **One-shot classification** β learn to recognize a new category from a single example (like humans do) |
| 2. **Fast game mastery** β play Atari Breakout using innate physics priors (like infants understand gravity before they can walk) |
|
|
| ### Key Innovation |
|
|
| Instead of POMDP/VI/MCMC (traditional AI approaches), HippocampAIF uses: |
| - **Free-Energy Minimization** (Friston) for perception and action |
| - **Hippocampal Fast-Binding** for instant one-shot memory |
| - **Spelke's Core Knowledge** systems as hardcoded innate priors |
| - **Distortable Canvas** for elastic image comparison |
|
|
| --- |
|
|
| ## Theoretical Foundations |
|
|
| ### Three Source Papers |
|
|
| | Paper | What It Provides | Where in Code | |
| |-------|-----------------|---------------| |
| | **Friston (2009)** "The free-energy principle: a rough guide to the brain" | Free energy F = Energy β Entropy, recognition dynamics, active inference | `core/free_energy.py`, `core/message_passing.py`, `neocortex/predictive_coding.py`, `action/active_inference.py` | |
| | **Lake et al. (2015)** "Human-level concept learning through probabilistic program induction" (BPL) | One-shot learning from single examples, compositional representations | `learning/one_shot_classifier.py`, `hippocampus/index_memory.py`, `agent/mnist_agent.py` | |
| | **Distortable Canvas** (oneandtrulyone) | Elastic canvas deformation, dual distance metric, AMGD optimization | `learning/distortable_canvas.py`, `learning/amgd.py`, `core_knowledge/geometry_system.py` | |
|
|
| ### Core Equations |
|
|
| **Free Energy (Friston Box 1):** |
| ``` |
| F = ββ¨ln p(y,Ο|m)β©_q + β¨ln q(Ο|ΞΌ)β©_q |
| ``` |
| Under Laplace approximation: `F β βln p(y,ΞΌ) + Β½ ln|Ξ (ΞΌ)|` |
|
|
| **Recognition Dynamics (Friston Box 3):** |
| ``` |
| ΞΌΜ = ββF/βΞΌ (perception: update internal model) |
| Θ§ = ββF/βa (action: change world to match predictions) |
| Ξ»Μ = ββF/βΞ» (attention: optimize precision) |
| ``` |
|
|
| **Dual Distance (Distortable Canvas):** |
| ``` |
| D(Iβ, Iβ) = min_u,v [ color_dist(warp(Iβ, u, v), Iβ) + Ξ» Γ canvas_dist(u, v) ] |
| ``` |
|
|
| --- |
|
|
| ## Architecture Map |
|
|
| ``` |
| ββββββββββββββββββββββββββββββ |
| β Prefrontal Cortex (PFC) β |
| β β’ Working memory (7Β±2) β |
| β β’ Executive control β |
| β β’ Goal stack β |
| ββββββββββββ¬ββββββββββββββββββ |
| β top-down control |
| ββββββββββββββββββββββββββΌβββββββββββββββββββββββββ |
| β β β |
| βΌ βΌ βΌ |
| βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββββ |
| β Temporal Cortex β β Predictive Codingβ β Parietal Cortex β |
| β β’ Recognition β β β’ Friston Box 3 β β β’ Priority maps β |
| β β’ Categories βββββ β’ Free-energy minββββΊ β β’ Coord. transformsβ |
| β β’ Semantic mem. β β β’ Error signals β β β’ Sensorimotor β |
| ββββββββββ¬βββββββββ ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββββ |
| β β β |
| β βββββββββββββββββΌββββββββββββββββ β |
| β βΌ βΌ βΌ β |
| β βββββββ ββββββββββββββββ ββββββββββββ β |
| β β SC β β Precision β β Biased β β |
| β βSaccadeβ β Modulator β β Compete β β |
| β ββββ¬βββ ββββββββ¬βββββββ ββββββ¬ββββββ β |
| β βββββββββββββββΌββββββββββββββββ β |
| β β attention β |
| β βββββββββββββββΌββββββββββββββ β |
| βΌ βΌ βΌ βΌ βΌ |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| β H I P P O C A M P U S β |
| β ββββββββββ βββββββ βββββββ ββββββββββββββββ β |
| β β DG ββ β CA3 ββ β CA1 βββ Index Memory β β |
| β βSeparate β βCompleteβ βMatchβ β Fast-binding β β |
| β ββββββββββ βββββββ βββββββ ββββββββββββββββ β |
| β βββββββββββββββββ βββββββββββββββββ β |
| β β Entorhinal EC β β Replay Buffer β β |
| β β Grid cells β β Consolidation β β |
| β βββββββββββββββββ βββββββββββββββββ β |
| ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ |
| β features |
| ββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββ |
| β V I S U A L C O R T E X β |
| β βββββββββββββ ββββββββββββββββ βββββββββββββββββ β |
| β β V1 Simple ββ β V1 Complex ββ β HMAX Hierarchyβ β |
| β β Gabor β β Max-pooling β β V2βV4βIT β β |
| β βββββββββββββ ββββββββββββββββ βββββββββββββββββ β |
| ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ |
| β ON/OFF sparse |
| ββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββ |
| β R E T I N A β |
| β ββββββββββββββββ ββββββββββββ ββββββββββββββββββ β |
| β β Photoreceptorsβ β Ganglion β β Spatiotemporal β β |
| β β Adaptation β β DoG β β Motion energy β β |
| β ββββββββββββββββ ββββββββββββ ββββββββββββββββββ β |
| ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ |
| β raw image |
| ββββββ§βββββ |
| β SENSES β |
| βββββββββββ |
| |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| β C O R E K N O W L E D G E β |
| β ββββββββββ ββββββββββ ββββββββββ ββββββββββ β |
| β βObjects β βPhysics β βNumber β βGeometryβ β |
| β βPerm/Cohβ βGravity β βANS/Sub β βCanvas β β |
| β ββββββββββ ββββββββββ ββββββββββ ββββββββββ β |
| β ββββββββββ ββββββββββ β |
| β βAgent β βSocial β β INNATE, NOT LEARNED β |
| β βGoals β βHelper β β |
| β ββββββββββ ββββββββββ β |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| β A C T I O N S Y S T E M β |
| β ββββββββββββββββββββ ββββββββββββββ ββββββββββββ β |
| β β Active Inference β β Motor β β Reflex β β |
| β β Θ§ = ββF/βa β β Primitives β β Arc β β |
| β β Expected FE min. β β L/R/Fire β β Track β β |
| β ββββββββββββββββββββ ββββββββββββββ ββββββββββββ β |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| ``` |
|
|
| --- |
|
|
| ## Setup |
|
|
| ### Prerequisites |
| - Python β₯ 3.10 |
| - NumPy β₯ 1.24 |
| - SciPy β₯ 1.10 |
| - Pillow β₯ 9.0 |
|
|
| ### Installation |
|
|
| ```powershell |
| # 1. Clone or navigate to the project |
| cd c:\Users\User\Desktop\debugrem\clawd-one-and-only-one-shot |
| |
| # 2. Create virtual environment |
| python -m venv .venv |
| |
| # 3. Activate |
| .venv\Scripts\activate |
| |
| # 4. Install dependencies |
| pip install -r requirements.txt |
| |
| # 5. Set PYTHONPATH (REQUIRED β PowerShell syntax) |
| $env:PYTHONPATH = "c:\Users\User\Desktop\debugrem\clawd-one-and-only-one-shot" |
| ``` |
|
|
| > **CMD users:** Use `set PYTHONPATH=c:\Users\User\Desktop\debugrem\clawd-one-and-only-one-shot` |
|
|
| > **Linux/Mac users:** Use `export PYTHONPATH=$(pwd)` |
|
|
| ### Verify Installation |
|
|
| ```powershell |
| python -c "import hippocampaif; print(f'HippocampAIF v{hippocampaif.__version__}')" |
| # Expected: HippocampAIF v1.0.0 |
| ``` |
|
|
| --- |
|
|
| ## Module Reference |
|
|
| ### Phase 1: Core Infrastructure (`core/`) |
|
|
| | Module | Class | Purpose | |
| |--------|-------|---------| |
| | `tensor.py` | `SparseTensor` | Sparse ndarray wrapper β the brain is "lazy and sparse" | |
| | `free_energy.py` | `FreeEnergyEngine` | Variational free-energy computation and gradient descent | |
| | `message_passing.py` | `HierarchicalMessagePassing` | Forward (errors) + Backward (predictions) message passing | |
| | `dynamics.py` | `ContinuousDynamics` | Euler integration of recognition dynamics | |
|
|
| **Usage:** |
| ```python |
| from hippocampaif.core.free_energy import FreeEnergyEngine |
| |
| fe = FreeEnergyEngine(learning_rate=0.01) |
| F = fe.compute_free_energy(sensory_input, prediction, precision) |
| new_state = fe.perception_update(state, sensory_input, generative_fn, precision) |
| ``` |
|
|
| ### Phase 2: Retina (`retina/`) |
|
|
| | Module | Class | Purpose | |
| |--------|-------|---------| |
| | `photoreceptor.py` | `PhotoreceptorArray` | Luminance adaptation, Weber's law | |
| | `ganglion.py` | `GanglionCellLayer` | DoG center-surround β ON/OFF sparse channels | |
| | `spatiotemporal_energy.py` | `SpatiotemporalEnergyBank` | Adelson-Bergen motion energy | |
|
|
| **Usage:** |
| ```python |
| from hippocampaif.retina.ganglion import GanglionCellLayer |
| |
| retina = GanglionCellLayer(center_sigma=1.0, surround_sigma=3.0) |
| st_on, st_off = retina.process(image) # Returns SparseTensors |
| on_array = st_on.data # Dense numpy array |
| ``` |
|
|
| ### Phase 3: Visual Cortex (`v1_v5/`) |
| |
| | Module | Class | Purpose | |
| |--------|-------|---------| |
| | `gabor_filters.py` | `V1SimpleCells` | 2D Gabor filter bank (multi-orientation, multi-scale) | |
| | `sparse_coding.py` | `V1ComplexCells` | Max-pooling for shift invariance + hypercolumn sparsity | |
| | `hmax_pooling.py` | `HMAXHierarchy` | S-cell/C-cell hierarchy: V1βV2βV4βIT | |
|
|
| **Usage:** |
| ```python |
| from hippocampaif.v1_v5.gabor_filters import V1SimpleCells |
| from hippocampaif.v1_v5.sparse_coding import V1ComplexCells |
| from hippocampaif.v1_v5.hmax_pooling import HMAXHierarchy |
| |
| v1 = V1SimpleCells(n_orientations=8, n_scales=2, kernel_size=11, frequency=0.25) |
| v1c = V1ComplexCells(pool_size=3) |
| hmax = HMAXHierarchy(pool_sizes=[2, 2]) |
| |
| simple = v1.process(on_center_image) # (n_filters, H, W) |
| complex_maps = v1c.process(simple) # list[SparseTensor] |
| hierarchy = hmax.process(complex_maps) # list[list[SparseTensor]] |
| ``` |
|
|
| ### Phase 4: Hippocampus (`hippocampus/`) |
|
|
| | Module | Class | Purpose | |
| |--------|-------|---------| |
| | `dg.py` | `DentateGyrus` | Pattern separation β sparse expansion coding | |
| | `ca3.py` | `CA3` | Pattern completion β attractor network | |
| | `ca1.py` | `CA1` | Match/mismatch detection β novelty signals | |
| | `entorhinal.py` | `EntorhinalCortex` | Grid cells, spatial coding | |
| | `index_memory.py` | `HippocampalIndex` | **One-shot fast-binding** β store and retrieve in 1 exposure | |
| | `replay.py` | `ReplayBuffer` | Memory consolidation via offline replay | |
|
|
| **Usage (one-shot memory):** |
| ```python |
| from hippocampaif.hippocampus.index_memory import HippocampalIndex |
| |
| mem = HippocampalIndex(cortical_size=128, index_size=256) |
| mem.store(features_vector) # Instant! No training loops |
| result = mem.retrieve(query_features) # Nearest match |
| ``` |
|
|
| ### Phase 5: Core Knowledge (`core_knowledge/`) |
| |
| These are **innate priors** β hardcoded "common sense" that constrains perception, NOT learned from data. |
| |
| | Module | Class | What It Encodes | |
| |--------|-------|----------------| |
| | `object_system.py` | `ObjectSystem` | Objects persist when occluded, can't teleport, don't pass through each other | |
| | `physics_system.py` | `PhysicsSystem` | Gravity pulls down, objects bounce elastically, friction slows things | |
| | `number_system.py` | `NumberSystem` | Exact count β€4 (subitizing), Weber ratio for larger sets | |
| | `geometry_system.py` | `GeometrySystem` | Spatial relations + Distortable Canvas deformation fields | |
| | `agent_system.py` | `AgentSystem` | Self-propelled entities with direction changes = intentional agents | |
| | `social_system.py` | `SocialSystem` | Helpers are preferred over hinderers | |
|
|
| **Usage (physics prediction for Breakout):** |
| ```python |
| from hippocampaif.core_knowledge.physics_system import PhysicsSystem, PhysicsState |
| |
| phys = PhysicsSystem(gravity=0.0, elasticity=1.0) |
| ball = PhysicsState(position=[50, 100], velocity=[3, -2]) |
| trajectory = phys.predict_trajectory(ball, steps=50, bounds=([0,0], [160,210])) |
| # β Predicts ball path with wall bounces |
| ``` |
|
|
| ### Phase 6: Neocortex + Attention (`neocortex/`, `attention/`) |
|
|
| | Module | Class | Purpose | |
| |--------|-------|---------| |
| | `predictive_coding.py` | `PredictiveCodingHierarchy` | Hierarchical free-energy minimization (Friston Box 3) | |
| | `prefrontal.py` | `PrefrontalCortex` | Working memory (7Β±2 items), executive control | |
| | `temporal.py` | `TemporalCortex` | Object recognition, one-shot categories | |
| | `parietal.py` | `ParietalCortex` | Priority maps, coordinate transforms | |
| | `superior_colliculus.py` | `SuperiorColliculus` | Saccade target selection via WTA competition | |
| | `precision.py` | `PrecisionModulator` | Attention = precision weighting (attend/suppress channels) | |
| | `competition.py` | `BiasedCompetition` | Desimone & Duncan biased competition model | |
|
|
| ### Phase 7: One-Shot Learning (`learning/`) |
|
|
| | Module | Class | Purpose | |
| |--------|-------|---------| |
| | `distortable_canvas.py` | `DistortableCanvas` | Elastic image warping + dual distance metric | |
| | `amgd.py` | `AMGD` | Coarse-to-fine deformation optimization | |
| | `one_shot_classifier.py` | `OneShotClassifier` | Full pipeline: features β match β canvas refine | |
| | `hebbian.py` | `HebbianLearning` | Basic/Oja/BCM/anti-Hebbian plasticity rules | |
|
|
| ### Phase 8: Action (`action/`) |
|
|
| | Module | Class | Purpose | |
| |--------|-------|---------| |
| | `active_inference.py` | `ActiveInferenceController` | Θ§ = ββF/βa β choose actions that minimize surprise | |
| | `motor_primitives.py` | `MotorPrimitives` | NOOP/FIRE/LEFT/RIGHT for Breakout | |
| | `reflex_arc.py` | `ReflexArc` | Tracking, withdrawal, orienting, intercept reflexes | |
|
|
| ### Phase 9: Integrated Agent (`agent/`) |
|
|
| | Module | Class | Purpose | |
| |--------|-------|---------| |
| | `brain.py` | `Brain` | Wires ALL modules together: senseβrememberβpredictβattendβact | |
| | `mnist_agent.py` | `MNISTAgent` | One-shot MNIST: 1 exemplar per digit β classify | |
| | `breakout_agent.py` | `BreakoutAgent` | Breakout: physics priors + reflex tracking | |
|
|
| --- |
|
|
| ## How the Pipeline Works |
|
|
| ### Perception Pipeline (seeing) |
|
|
| ``` |
| Raw Image (28Γ28 or 84Γ84) |
| β |
| βΌ GanglionCellLayer.process() |
| ON/OFF SparseTensors (DoG filtered) |
| β |
| βΌ V1SimpleCells.process() |
| Gabor responses (n_orientations Γ n_scales, H, W) |
| β |
| βΌ V1ComplexCells.process() |
| Shift-invariant sparse maps: list[SparseTensor] |
| β |
| βΌ HMAXHierarchy.process() |
| Hierarchical features: list[list[SparseTensor]] |
| β |
| βΌ Flatten + truncate to feature_size |
| Feature vector (128-dim) |
| β |
| ββββΊ PredictiveCodingHierarchy.process() β free energy minimization |
| ββββΊ TemporalCortex.recognize() β category label |
| ββββΊ PrefrontalCortex.store() β working memory |
| ββββΊ HippocampalIndex.store() β one-shot binding |
| ``` |
|
|
| ### Action Pipeline (doing) |
|
|
| ``` |
| Current internal state (from predictive coding) |
| β |
| βΌ ActiveInferenceController.select_action() |
| Expected free energy G(a) for each action |
| β |
| βΌ softmax(βΞ² Γ G) |
| Action probabilities |
| β |
| βΌ argmin or sample |
| Discrete action (0-3) |
| β |
| βΌ MotorPrimitives.get_action_name() |
| "LEFT" / "RIGHT" / "FIRE" / "NOOP" |
| ``` |
|
|
| ### One-Shot Learning Pipeline (classifying) |
|
|
| ``` |
| Test Image |
| β |
| βΌ Full perception pipeline |
| Feature vector |
| β |
| βΌ OneShotClassifier.classify() |
| β |
| βββ Compare to all stored exemplar features |
| βββ If confidence > threshold β return label |
| βββ If ambiguous β DistortableCanvas refinement: |
| βββ AMGD optimizes deformation field |
| βββ Dual distance = color_dist + Ξ» Γ canvas_dist |
| βββ Choose exemplar with lowest dual distance |
| ``` |
|
|
| --- |
|
|
| ## Using the MNIST Agent |
|
|
| ### Quick Start |
|
|
| ```python |
| import numpy as np |
| from hippocampaif.agent.mnist_agent import MNISTAgent |
| |
| # Create agent (feature_size=128 is the default) |
| agent = MNISTAgent(feature_size=128, use_canvas=True) |
| |
| # === TRAINING: Learn 1 exemplar per digit === |
| # Load your MNIST data (10 training images, one per digit) |
| for digit in range(10): |
| image = training_images[digit] # 28Γ28 numpy array, values 0-255 |
| agent.learn_digit(image, label=digit) |
| |
| print(f"Learned {agent.exemplars_stored} digits") |
| |
| # === TESTING: Classify new images === |
| result = agent.classify(test_image) |
| print(f"Predicted: {result['label_int']}, Confidence: {result['confidence']:.2f}") |
| |
| # === EVALUATION: Batch accuracy === |
| stats = agent.evaluate(test_images, test_labels) |
| print(f"Accuracy: {stats['accuracy']*100:.1f}%") |
| print(f"Per-class: {stats['per_class_accuracy']}") |
| ``` |
|
|
| ### Loading MNIST Data |
|
|
| ```python |
| # Option 1: From sklearn |
| from sklearn.datasets import fetch_openml |
| mnist = fetch_openml('mnist_784', version=1) |
| images = mnist.data.values.reshape(-1, 28, 28) |
| labels = mnist.target.values.astype(int) |
| |
| # Option 2: From local .npy files |
| images = np.load('mnist_images.npy') |
| labels = np.load('mnist_labels.npy') |
| |
| # Select 1 training exemplar per digit |
| train_indices = [] |
| for d in range(10): |
| idx = np.where(labels == d)[0][0] |
| train_indices.append(idx) |
| |
| train_images = images[train_indices] |
| train_labels = labels[train_indices] |
| ``` |
|
|
| --- |
|
|
| ## Using the Breakout Agent |
|
|
| ### Quick Start |
|
|
| ```python |
| import numpy as np |
| from hippocampaif.agent.breakout_agent import BreakoutAgent |
| |
| # Create agent |
| agent = BreakoutAgent(screen_height=210, screen_width=160) |
| |
| # === Game Loop === |
| agent.new_episode() |
| observation = env.reset() # From gymnasium |
| |
| for step in range(10000): |
| action = agent.act(observation, reward=0.0) |
| observation, reward, done, _, info = env.step(action) |
| |
| if done: |
| print(f"Episode {agent.episode}: reward = {agent.episode_reward}") |
| agent.new_episode() |
| observation = env.reset() |
| ``` |
|
|
| ### With Gymnasium (requires optional deps) |
|
|
| ```powershell |
| pip install gymnasium[atari] ale-py |
| ``` |
|
|
| ```python |
| import gymnasium as gym |
| from hippocampaif.agent.breakout_agent import BreakoutAgent |
| |
| env = gym.make('BreakoutNoFrameskip-v4', render_mode='human') |
| agent = BreakoutAgent() |
| |
| for episode in range(5): |
| agent.new_episode() |
| obs, _ = env.reset() |
| total_reward = 0 |
| |
| while True: |
| action = agent.act(obs) |
| obs, reward, term, trunc, _ = env.step(action) |
| total_reward += reward |
| if term or trunc: |
| break |
| |
| print(f"Episode {episode+1}: {total_reward} reward") |
| print(agent.get_stats()) |
| |
| env.close() |
| ``` |
|
|
| --- |
|
|
| ## Running Tests |
|
|
| ### All Phases |
|
|
| ```powershell |
| # Set PYTHONPATH first! |
| $env:PYTHONPATH = "c:\Users\User\Desktop\debugrem\clawd-one-and-only-one-shot" |
| |
| # Phase 1-4 (Core, Retina, Visual Cortex, Hippocampus) |
| python -m hippocampaif.tests.test_core |
| python -m hippocampaif.tests.test_retina |
| python -m hippocampaif.tests.test_v1_v5 |
| python -m hippocampaif.tests.test_hippocampus |
| |
| # Phase 5-8 (Core Knowledge, Neocortex, Learning, Action) |
| python -m hippocampaif.tests.test_core_knowledge |
| python -m hippocampaif.tests.test_neocortex_attention |
| python -m hippocampaif.tests.test_learning |
| python -m hippocampaif.tests.test_action |
| ``` |
|
|
| ### What Each Test Suite Validates |
|
|
| | Test Suite | # Tests | What It Checks | |
| |-----------|---------|----------------| |
| | `test_core` | β | Free-energy convergence, message passing stability, sparse tensor ops | |
| | `test_retina` | β | DoG center-surround, motion energy detection | |
| | `test_v1_v5` | β | Gabor orientations, HMAX invariant features | |
| | `test_hippocampus` | β | Pattern separation orthgonality, completion from partial cues | |
| | `test_core_knowledge` | 11 | Object permanence, continuity, gravity, bounce, support, subitizing, Weber, geometry, deformation, agency, social | |
| | `test_neocortex_attention` | 10 | PC convergence, PC learning, WM capacity, WM decay, one-shot recognition, coord transforms, priority maps, saccades, precision, biased competition | |
| | `test_learning` | 7 | Canvas warp identity, dual distance, same-class distance, AMGD, Hebbian basic, Oja bounded, one-shot classifier | |
| | `test_action` | 6 | Active inference goal-seeking, forward model learning, motor primitives, reflex tracking, intercept, habituation | |
|
|
| --- |
|
|
| ## Extending the Framework |
|
|
| ### Adding a New Core Knowledge System |
|
|
| ```python |
| # hippocampaif/core_knowledge/my_new_system.py |
| import numpy as np |
| |
| class TemporalSystem: |
| """Core knowledge of time and causality.""" |
| |
| def __init__(self): |
| self.causal_chains = [] |
| |
| def detect_causality(self, event_a, event_b, time_gap): |
| """Innate prior: causes precede effects in time.""" |
| if time_gap > 0 and time_gap < 2.0: # Temporal contiguity |
| return {'causal': True, 'strength': 1.0 / time_gap} |
| return {'causal': False, 'strength': 0.0} |
| ``` |
|
|
| Then add to `core_knowledge/__init__.py`: |
| ```python |
| from .my_new_system import TemporalSystem |
| ``` |
|
|
| ### Adding a New Agent |
|
|
| ```python |
| # hippocampaif/agent/my_agent.py |
| from hippocampaif.agent.brain import Brain |
| |
| class MyAgent: |
| def __init__(self): |
| self.brain = Brain(image_height=64, image_width=64, n_actions=4) |
| |
| def act(self, observation): |
| perception = self.brain.perceive(observation) |
| return self.brain.act() |
| |
| def learn(self, image, label): |
| self.brain.one_shot_learn(image, label) |
| ``` |
|
|
| ### Adding Custom Reflexes |
|
|
| ```python |
| from hippocampaif.action.reflex_arc import ReflexArc |
| |
| class CustomReflexArc(ReflexArc): |
| def dodge_reflex(self, projectile_pos, projectile_vel, agent_pos): |
| """Dodge an incoming projectile.""" |
| # Predict collision point |
| predicted = projectile_pos + projectile_vel * 0.5 |
| |
| # Move perpendicular to projectile trajectory |
| direction = np.cross(projectile_vel, [0, 0, 1])[:2] |
| return self.reflex_gain * direction |
| ``` |
|
|
| --- |
|
|
| ## Design Decisions & Rationale |
|
|
| ### Why No PyTorch/TensorFlow/JAX? |
|
|
| The framework is intentionally pure NumPy + SciPy because: |
| 1. **Biological fidelity** β neural computations are local gradient updates, not backprop through a compute graph |
| 2. **Interpretability** β every array corresponds to a neural population with known anatomy |
| 3. **Minimal dependencies** β runs on any machine with Python and NumPy |
| 4. **Educational value** β you can read every line and understand the neuroscience |
|
|
| ### Why Hippocampal Fast-Binding Instead of MCMC? |
|
|
| MCMC sampling is computationally expensive and biologically implausible. The hippocampus stores new memories **instantly** via pattern separation (DG) + fast Hebbian binding (CA3) β no need for thousands of samples. |
|
|
| ### Why Spelke's Core Knowledge Instead of Tabula Rasa? |
|
|
| Human infants are NOT blank slates. They have innate expectations about: |
| - **Objects** β things persist when hidden |
| - **Physics** β dropped objects fall |
| - **Numbers** β small quantities are exact |
|
|
| These priors are hardcoded because they evolved over millions of years and shouldn't need to be learned from scratch by every agent. |
|
|
| ### Why Distortable Canvas Instead of CNN Features? |
|
|
| CNNs require thousands of training images. The Distortable Canvas achieves 90% MNIST accuracy with just **4 examples** by treating image comparison as a smooth deformation problem β "how much do I need to warp image A to look like image B?" |
|
|
| --- |
|
|
| ## File Map |
|
|
| ``` |
| hippocampaif/ # 59 Python files across 9 packages |
| βββ __init__.py # v1.0.0, exports core classes |
| βββ core/ # Phase 1 β Foundation |
| β βββ tensor.py # SparseTensor |
| β βββ free_energy.py # FreeEnergyEngine |
| β βββ message_passing.py # HierarchicalMessagePassing |
| β βββ dynamics.py # ContinuousDynamics |
| βββ retina/ # Phase 2 β Eye |
| β βββ photoreceptor.py # PhotoreceptorArray |
| β βββ ganglion.py # GanglionCellLayer (DoG) |
| β βββ spatiotemporal_energy.py # SpatiotemporalEnergyBank |
| βββ v1_v5/ # Phase 3 β Visual Cortex |
| β βββ gabor_filters.py # V1SimpleCells |
| β βββ sparse_coding.py # V1ComplexCells |
| β βββ hmax_pooling.py # HMAXHierarchy |
| βββ hippocampus/ # Phase 4 β Memory |
| β βββ dg.py # DentateGyrus |
| β βββ ca3.py # CA3 |
| β βββ ca1.py # CA1 |
| β βββ entorhinal.py # EntorhinalCortex |
| β βββ index_memory.py # HippocampalIndex |
| β βββ replay.py # ReplayBuffer |
| βββ core_knowledge/ # Phase 5 β Innate Priors |
| β βββ object_system.py # ObjectSystem |
| β βββ physics_system.py # PhysicsSystem |
| β βββ number_system.py # NumberSystem |
| β βββ geometry_system.py # GeometrySystem |
| β βββ agent_system.py # AgentSystem |
| β βββ social_system.py # SocialSystem |
| βββ neocortex/ # Phase 6a β Higher Cognition |
| β βββ predictive_coding.py # PredictiveCodingHierarchy |
| β βββ prefrontal.py # PrefrontalCortex |
| β βββ temporal.py # TemporalCortex |
| β βββ parietal.py # ParietalCortex |
| βββ attention/ # Phase 6b β Attention |
| β βββ superior_colliculus.py # SuperiorColliculus |
| β βββ precision.py # PrecisionModulator |
| β βββ competition.py # BiasedCompetition |
| βββ learning/ # Phase 7 β One-Shot |
| β βββ distortable_canvas.py # DistortableCanvas |
| β βββ amgd.py # AMGD |
| β βββ one_shot_classifier.py # OneShotClassifier |
| β βββ hebbian.py # HebbianLearning |
| βββ action/ # Phase 8 β Motor |
| β βββ active_inference.py # ActiveInferenceController |
| β βββ motor_primitives.py # MotorPrimitives |
| β βββ reflex_arc.py # ReflexArc |
| βββ agent/ # Phase 9 β Integration |
| β βββ brain.py # Brain (full pipeline) |
| β βββ mnist_agent.py # MNISTAgent |
| β βββ breakout_agent.py # BreakoutAgent |
| βββ tests/ # 8 test suites, 34+ tests |
| βββ test_core.py |
| βββ test_retina.py |
| βββ test_visual_cortex.py |
| βββ test_hippocampus.py |
| βββ test_core_knowledge.py |
| βββ test_neocortex_attention.py |
| βββ test_learning.py |
| βββ test_action.py |
| ``` |
|
|
| --- |
|
|
| ## Citation |
|
|
| If you use this framework in research or production, please cite: |
|
|
| ```bibtex |
| @software{hippocampaif2026, |
| author = {Albeos, Rembrant Oyangoren}, |
| title = {HippocampAIF: Biologically Grounded Cognitive Architecture}, |
| year = {2026}, |
| description = {Free-energy minimization + hippocampal fast-binding + |
| Spelke's core knowledge for one-shot learning and active inference} |
| } |
| ``` |
|
|
| **References:** |
| - Friston, K. (2009). The free-energy principle: a rough guide to the brain. *Trends in Cognitive Sciences*, 13(7), 293-301. |
| - Lake, B. M., Salakhutdinov, R., & Tenenbaum, J. B. (2015). Human-level concept learning through probabilistic program induction. *Science*, 350(6266), 1332-1338. |
| - Spelke, E. S. (2000). Core knowledge. *American Psychologist*, 55(11), 1233-1243. |
|
|