# Gated Relational Perceptron (GRP): Temporal-Relational Integration > **Superseded (2026-09-01):** replaced by §4 of the general spec. As written here the unit has no recurrence and no candidate transform, and the ψ modulation can only lower the gate. See `AILED_General_Specification.md`. ## Technical Specification for Memory-Augmented Neuroevolution **Project Context:** AILED Organism / RPN Architecture **Module Type:** Advanced Perceptual Unit **Mathematical Focus:** Gated Recurrent Dynamics and State Fusion. --- ## 1. Concept Overview: Beyond Static Perception Standard Relational Perceptrons (RP) treat each board state as an isolated event. While efficient, they lack the ability to maintain **temporal coherence**. They cannot distinguish between a new development in the game and a transient noise in the sensor data. The **Gated Relational Perceptron (GRP)** introduces a "memory gate" within the neuron itself. Instead of simply processing the current relational features, the GRP performs a **dynamic fusion** between the current state and a decaying temporal trace. This allows the organism to maintain "object permanence" (knowing a piece is still relevant even if its position shifts slightly) and to implement **affective-driven focus** (deciding how much to trust new information based on psychological tension). --- ## 2. Mathematical Formalism The GRP operates on two inputs: the instantaneous relational features $\mathbf{x}_t$ and the latent memory state $\mathbf{M}_{t-1}$. ### 2.1. The Gating Mechanism (The "Attention" to Change) A gating vector $\mathbf{g}_t$ is computed to decide the proportion of information to take from the past versus the present. This gate is a function of both inputs, allowing the model to learn *when* to trust memory. $$\mathbf{g}_t = \sigma \left( \mathbf{W}_{gate} \cdot [\mathbf{x}_t \parallel \mathbf{M}_{t-1}] + b_{gate} \right)$$ Where: - $[\mathbf{x}_t \parallel \mathbf{M}_{t-1}]$ is the concatenation of current and previous states. - $\sigma$ is the sigmoid activation function, ensuring $g \in [0, 1]$. - $\mathbf{W}_{gate}$ is the parameter set (evolved via HyperNEAT). ### 2.2. State Fusion (The "Integrated Perception") The fused state $\mathbf{z}_t$ is an element-wise interpolation between the current observations and the historical trace: $$\mathbf{z}_t = (1 - \mathbf{g}_t) \odot \mathbf{x}_t + \mathbf{g}_t \odot \mathbf{M}_{t-1}$$ Where $\odot$ denotes the Hadamard (element-wise) product. ### 2.3. Final Activation (The Relational Output) The final output is the non-linear projection of this integrated state using the weights $\mathbf{W}_{RP}$ (the topological backbone): $$y = \phi \left( \sum_{i=1}^{n} w_{ij}(\psi) \cdot z_{t,i} \right)$$ Where: - $w_{ij}(\psi)$ is the weight generated by the Affective CPPN. - $\phi$ is the non-linear activation (e.g., $\tanh$). --- ## 3. Psychological Modulation of the Gate The most critical innovation is that the gate $\mathbf{g}_t$ is not just a learned parameter, but is **modulated by the Psyche ($\psi$)**. This creates a biological-like response to stress: $$g_t(\psi) \approx \text{clamp}\left( g_{\text{learned}} + \Delta_{\text{psyche}}(\psi), 0, 1 \right)$$ - **Low $\psi$ (Stress/Panic):** $\mathbf{g}_t \to 0$. The gate "opens" to the present. The organism becomes hyper-reactive to new threats, discarding old memory to focus on immediate survival. - **High $\psi$ (Calm/Confidence):** $\mathbf{g}_t \to 1$. The gate "closes" on the past. The organism becomes stable and follows its established strategic plan (memory), ignoring minor positional fluctuations. --- ## 4. Minimal Implementation (Python + NumPy) This implementation demonstrates the fusion of current features and memory through a gating mechanism. ```python import numpy as np class GatedRelationalPerceptron: """ A minimal implementation of the Gated Relational Perceptron (GRP). Demonstrates the fusion of current state and memory via a gating mechanism. """ def __init__(self, num_relations: int, embedding_dim: int): self.n = num_relations self.d = embedding_dim # Gate parameters: Maps [x || M] -> [0, 1]^n # In a full RPN, these are evolved by HyperNEAT self.W_gate = np.random.randn(self.n, 2 * self.d) self.b_gate = np.zeros(self.n) # RP weights: Simulated topological weights self.W_rp = np.random.randn(self.n, self.d) def _sigmoid(self, x): return 1 / (1 + np.exp(-x)) def forward(self, x_t: np.ndarray, M_prev: np.ndarray, psyche: float) -> float: """ Performs the gated forward pass. Args: x_t: (N, D) Current relational features. M_prev: (N, D) Previous memory trace. psyche: Float [-100, 100] modulating gate behavior. Returns: float: The integrated output. """ # 1. Concatenate State and Memory # Shape: (N, 2*D) combined_input = np.hstack([x_t, M_prev]) # 2. Compute the Gate (g) # g = sigmoid(W_gate @ combined_input + b) # We use the dot product to treat each relation's gate independently gate = self._sigmoid(np.dot(combined_input, self.W_gate.T) + self.b_gate) # 3. Modulate Gate via Psyche (Affective Bias) # Low psyche -> High reactivity (g -> 0) # High psyche -> High stability (g -> 1) psyche_bias = (psyche + 100.0) / 200.0 gate = np.clip(gate * psyche_bias, 0.01, 0.99) # 4. State Fusion (Interpolation) # Expand gate to (N, 1) for broadcasting with (N, D) g_exp = gate[:, np.newaxis] z_t = (1 - g_exp) * x_t + g_exp * M_prev # 5. Relational Projection # y = tanh( Sum( z_i * w_i ) ) activation = np.sum(z_t * self.W_rp) return float(np.tanh(activation)) # --- DEMO --- if __name__ == "__main__": N, D = 3, 2 grp = GatedRelationalPerceptron(num_relations=N, embedding_dim=D) # Two different states for the same relations # Scenario: A piece moves from (0,0) to (1,1) x_t = np.array([ [1.0, 1.0], [0.5, 0.5], [0.0, 0.0] ]) M_prev = np.array([ [0.0, 0.0], [0.5, 0.5], [0.0, 0.0] ]) print("--- GRP Simulation ---") # Case A: High Psyche (Stable/Conservative) print("\n[MODE: HIGH PSYCHE - Trusting Memory]") # We simulate high psyche by forcing the gate high in our test # For the demo, we'll just call forward and observe the sensitivity out_stable = grp.forward(x_t, M_prev, psyche=100.0) print(f"Output (Stable): {out_stable:.4f}") # Case B: Low Psyche (Reactive/Anxious) print("\n[MODE: LOW PSYCHE - Reacting to Change]") out_reactive = grp.forward(x_t, M_prev, psyche=-100.0) print(f"Output (Reactive): {out_reactive:.4f}") ``` --- ## 5. Summary of Advantages | Aspect | Benefit | | :--- | :--- | | **Temporal Coherence** | Reduces "jitter" in predictions caused by minor positional shifts. | | **Computational Efficiency** | Replaces heavy RNN/LSTM architectures with a simple $\text{O}(1)$ gating mechanism. | | **Affective Adaptability** | Allows the agent's "attention" to be controlled by its internal emotional state ($\psi$). | | **Identity Persistence** | Enables the model to maintain the logical concept of a piece through time. | ```