# Relational Perceptron (RP): Deep Dive & Technical Implementation > **Superseded (2026-09-01):** replaced by §3–§4 of the general spec. The demo code here has three silent bugs (scalar weight collapse, missing W_feat, ψ as pure gain). See `AILED_General_Specification.md`. ## Beyond Vector-Space: A Paradigm of Relational Intelligence **Project Context:** AILED Organism **Focus:** Mathematical structure, comparative analysis, and minimal implementation of the Relational Perceptron (RP). --- ## 1. Concept Overview The **Relational Perceptron (RP)** is a departure from the traditional Artificial Neuron. While a standard perceptron operates on a static, flattened vector of values, the RP operates on a **set of relational entities**. It treats input not as independent scalars, but as a collection of objects defined by their **intrinsic properties** and their **spatial/relational context**. In the AILED organism, the RP is the core sensory-motor unit that allows the engine to "feel" the tension of the board by processing the interactions between pieces rather than just their positions. --- ## 2. RP vs. Standard Perceptron | Feature | Standard Perceptron (MLP) | Relational Perceptron (RP) | | :--- | :--- | :--- | | **Input Representation** | Flat vector $\mathbf{x} \in \mathbb{R}^n$ (e.g., 64 values for a board). | Set of tuples $\{(\mathbf{p}_i, \mathbf{r}_i)\}_{i=1}^n$. | | **Geometric Awareness** | **None.** Must learn spatial correlations via massive data. | **Inherent.** Spatiality is encoded in the $\mathbf{r}_i$ input. | | **Weight Nature** | Constant $w_i$ learned via Backpropagation. | Dynamic $w(\mathbf{r}, \psi)$ generated via CPPN. | | **Scaling** | Scales with the size of the input vector (grid size). | Scales with the number of **active relationships**. | | **Complexity Focus** | Focuses on "What is in cell X?". | Focuses on "How does piece A interact with B?". | --- ## 3. Potential Use Cases While designed for Chess, the RP is a general-purpose architecture for any domain defined by **Relational Graphs**: 1. **Robotics (Spatial Interaction):** Modeling the relationship between a robot's joints, sensors, and objects in 3D space. 2. **Graph Neural Networks (GNN) Optimization:** A more lightweight, neuroevolutionary alternative to standard message-passing GNNs. 3. **Social Network Analysis:** Processing nodes (people) based on attributes (age, status) and relations (distance, influence). 4. **Molecular Biology:** Modeling protein-protein interactions where the "input" is the chemical property and the "relation" is the binding geometry. --- ## 4. Future Improvements & Evolutionary Paths * **HyperNEAT Integration:** Moving from a fixed weight-generator to a full CPPN that evolves the entire topology of the RP. * **$\psi$-Modulated Plasticity:** Using the Psyche to not only change weights but to change the *learning rate* (Hebbian plasticity) of the neuron. * **Attention-Weighted RP:** Adding a mechanism where the neuron can "attend" to specific relations more heavily, effectively becoming a hybrid between an RP and a Transformer-head. --- ## 5. Minimal Implementation (Python + NumPy) This implementation demonstrates the core mathematics: using a simplified CPPN to generate weights from a spatial relationship and applying them to piece embeddings. ```python import numpy as np class RelationalPerceptron: """ A minimal implementation of the Relational Perceptron. Demonstrates how weights are generated from geometry and applied to embeddings. """ def __init__(self, embedding_dim: int): self.embedding_dim = embedding_dim # In a full RPN, this would be a learned CPPN. # Here, we use a simplified functional approximation. self.phi = np.random.randn(2, 2) # Simplified CPPN weights for (dx, dy) def _cppn_weight_gen(self, relations: np.ndarray, psyche: float) -> np.ndarray: """ Simulates the CPPN generating weights based on (dx, dy) and psyche. Returns a vector of weights, one for each relation. """ # Simplified CPPN: w = tanh(relation @ phi) * psyche_factor # In reality, this would be a deep network. weights = np.tanh(np.dot(relations, self.phi)) # Modulate weight magnitude by Psyche (e.g., higher psyche = higher sensitivity) psyche_factor = 1.0 + (psyche / 100.0) return weights * psyche_factor def forward(self, piece_embeddings: np.ndarray, relations: np.ndarray, psyche: float) -> float: """ Performs the relational forward pass. Args: piece_embeddings: (N, D) array of piece properties. relations: (N, 2) array of (dx, dy) coordinates. psyche: Float modulating the weight generation. Returns: float: The scalar output of the neuron. """ num_relations = relations.shape[0] # 1. Generate weights for each relation via CPPN weights = self._cppn_weight_gen(relations, psyche) # (N,) # 2. Apply weights to the embeddings (weighted sum of features) # We calculate: Sum over i [ w_i * (W_feat @ p_i) ] # For this minimal demo, we simplify W_feat as identity or a projection. weighted_embeddings = piece_embeddings * weights[:, np.newaxis] # 3. Sum all weighted interactions activation = np.sum(weighted_embeddings) # 4. Non-linear activation return float(np.tanh(activation)) # --- DEMO --- if __name__ == "__main__": # Setup: 3 pieces in the scene # Piece 1: White Queen (high value) # Piece 2: Black Pawn (low value) # Piece 3: White Knight (medium value) embeddings = np.array([ [0.9, 0.1], # Queen [-0.3, -0.1],# Pawn [0.5, 0.4] # Knight ]) # Relative positions (dx, dy) of pieces relative to a central point/target relations = np.array([ [1.0, 1.0], # Queen is at (1,1) [0.0, 2.0], # Pawn is at (0,2) [-1.0, 0.0] # Knight is at (-1,0) ]) rp = RelationalPerceptron(embedding_dim=2) print("--- RP Simulation ---") for psi in [-50.0, 0.0, 50.0]: output = rp.forward(embeddings, relations, psi) print(f"Psyche: {psi:4.1f} | Neuron Output: {output: .4f}") ``` ### Mathematical Summary of the Demo: The code implements the core logic: $$\text{Output} = \tanh\left( \sum_{i=1}^n \text{CPPN}(\mathbf{r}_i, \psi) \cdot \mathbf{p}_i \right)$$ This demonstrates that even with a tiny amount of code, the **Relational Perceptron** captures the essence of a system that "senses" through relationships and "responds" to its internal state.