docs: design, plan, and the execution record

The thinking behind the organism, versioned alongside the three code repos rather than
living only on one machine.

- AILED_General_Specification.md, the authoritative design, and the implementation plan
  the code was built from
- AGENTS.md, the project-wide rules, including the two that were learned the hard way:
  this is not a performance benchmark, and a null recorded early beats a claim propped up
  later
- the nine superseded module specs, each carrying a banner naming what replaced it
- .sdd/, the execution ledger and every task brief and report: each ruling taken, what it
  would cost if wrong, every correction, and every number verified independently

The three code repos are siblings, each its own repository, and are git-ignored here so
nothing is nested.
This commit is contained in:
chrnx committed 2026-09-02 13:17:39 -05:00
commit 5da4b8efa5
47 files changed
+7498

No files matched your search

+139
View File
@@ -0,0 +1,139 @@
# Memory (Temporal Trace): EMA-based Contextualization
> **Superseded (2026-09-01):** absorbed into §4 of the general spec. The external EMA is gone; memory is the per-entity GRP state. See `AILED_General_Specification.md`.
## Technical Specification for Short-Term Affective Memory
**Project Context:** AILED Organism
**Module Type:** Temporal Context Injector
**Mathematical Focus:** Exponential Moving Averages (EMA) and Feature Augmentation.
---
## 1. Concept Overview: The "Temporal Trace"
In a pure reactive system, a neuron only knows the current state of the board. In a biological organism, perception is continuous; we don't just see a snapshot, we see a sequence of events.
The **Memory Module** does not implement a long-term database (which would be computationally heavy and require complex retrieval). Instead, it implements a **Temporal Trace**: a lightweight, running summary of recent features. This allows the Relational Perceptron (RP) to distinguish between a piece that *is* on a square and a piece that has *just arrived* on that square, providing a sense of "momentum" and "history".
---
## 2. Mathematical Formalism
The memory is implemented as an **Exponential Moving Average (EMA)** of the feature vector $\mathbf{x}$.
### 2.1. The Memory Update Rule
For every move $t$, the memory $\mathbf{M}_t$ is updated using the current board features $\mathbf{x}_t$:
$$\mathbf{M}_t = (1 - \lambda) \cdot \mathbf{M}_{t-1} + \lambda \cdot \mathbf{x}_t$$
Where:
- $\mathbf{M}_t \in \mathbb{R}^d$: The current memory vector (trace).
- $\mathbf{x}_t \in \mathbb{R}^d$: The current feature vector (instantaneous state).
- $\lambda \in [0, 1]$: The **forgetting rate** (decay).
- Small $\lambda$: High inertia (long-term memory/slow changes).
- Large $\lambda$: Low inertia (rapid forgetting/high sensitivity).
### 2.2. Feature Augmentation (The Augmented Input)
To grant the Relational Perceptron (RP) access to this history, we concatenate the current state with the memory trace. This creates an **Augmented Feature Vector** $\mathbf{X}_{total}$:
$$\mathbf{X}_{total} = [ \mathbf{x}_t \parallel \mathbf{M}_t ] \in \mathbb{R}^{2d}$$
By providing $\mathbf{X}_{total}$ to the RP, the neuron can learn weights that depend on both the current position and the direction of change (e.g., "is the pressure increasing or decreasing?").
---
## 3. Psyche-Modulated Memory (Advanced Concept)
To further align with the biological metaphor, the forgetting rate $\lambda$ can be modulated by the **Psyche ($\psi$)**.
$$\lambda(\psi) = \text{clamp}(\lambda_{base} + \Delta_{\lambda}(\psi), 0, 1)$$
* **High Stress ($\psi \to -100$):** Increase $\lambda$. The organism becomes "hyper-focused" on the present moment, rapidly forgetting the past to react to immediate threats.
* **High Calm ($\psi \to +100$):** Decrease $\lambda$. The organism becomes "contemplative", maintaining a longer temporal trace to plan long-term strategies.
---
## 4. Minimal Implementation (Python + NumPy)
This implementation demonstrates how to maintain a running trace and augment it for the next processing step.
```python
import numpy as np
class TemporalMemory:
"""
A minimal implementation of the Temporal Trace (Memory).
Uses EMA to maintain a running context of features.
"""
def __init__(self, feature_dim: int, lambda_rate: float = 0.2):
self.dim = feature_dim
self.lambda_rate = lambda_rate
self.memory = np.zeros(feature_dim) # Initialize memory as neutral
def update_and_augment(self, current_features: np.ndarray, psyche: float = 0.0) -> np.ndarray:
"""
Updates the memory trace and returns the augmented input vector.
Args:
current_features: (D,) array of current board features.
psyche: Float [-100, 100] modulating the decay rate.
Returns:
augmented_features: (2D,) array of [current || memory].
"""
# 1. Modulate lambda based on Psyche (Stress = rapid forgetting)
# We map psi [-100, 100] to a lambda multiplier
# Low psi -> High lambda (fast decay)
# High psi -> Low lambda (slow decay)
stress_factor = 1.0 - (psyche + 100.0) / 200.0 # 0.0 (calm) to 1.0 (stress)
effective_lambda = np.clip(self.lambda_rate * (0.5 + stress_factor), 0.01, 0.99)
# 2. EMA Update: M_t = (1 - L) * M_{t-1} + L * x_t
self.memory = (1 - effective_lambda) * self.memory + effective_lambda * current_features
# 3. Augmentation: Concatenate current and memory
augmented = np.concatenate([current_features, self.memory])
return augmented
# --- DEMO ---
if __name__ == "__main__":
dim = 4
mem = TemporalMemory(feature_dim=dim, lambda_rate=0.2)
# Simulated sequence of features (e.g., increasing pressure)
sequence = [
np.array([0.1, 0.1, 0.1, 0.1]),
np.array([0.2, 0.3, 0.2, 0.1]),
np.array([0.5, 0.8, 0.4, 0.2]),
np.array([0.9, 0.9, 0.7, 0.5]),
]
print("--- Memory Trace Simulation ---")
# Case A: Calm (Slow decay)
print("\n[CALM MODE: Low Lambda]")
mem_calm = TemporalMemory(feature_dim=dim, lambda_rate=0.1)
for i, feat in enumerate(sequence):
aug = mem_calm.update_and_augment(feat, psyche=100.0)
print(f"Step {i} | Current: {feat} | Memory: {aug[4:]} | Augmented: {aug}")
# Case B: Stress (Fast decay)
print("\n[STRESS MODE: High Lambda]")
mem_stress = TemporalMemory(feature_dim=dim, lambda_rate=0.1)
for i, feat in enumerate(sequence):
aug = mem_stress.update_and_augment(feat, psyche=-100.0)
print(f"Step {i} | Current: {feat} | Memory: {aug[4:]} | Augmented: {aug}")
```
---
## 5. Comparative Analysis: Why EMA?
| Method | Pros | Cons | Suit_for_AILED |
| :--- | :--- | :--- | :--- |
| **Fixed Buffer** | Captures exact history. | Memory grows with history; high latency. | No (Too heavy). |
| **LSTM / RNN** | Captures long-term dependencies. | High computational cost; "Black box" complexity. | No (Violates minimalism). |
| **EMA (Proposed)** | **O(1) space/time; extremely fast; mathematically elegant.** | Loses specific discrete events. | **Yes (Optimal for real-time).** |
The "loss" of discrete events is actually a benefit for the RPN; it filters out high-frequency noise and focuses on the **trend**, which is what matters for high-level chess intuition.