Masked L1 distance is the primary similarity metric in AGISystem2. It measures the Manhattan distance between two vectors, but only considers dimensions marked as relevant by a mask. This enables context-sensitive comparisons where different dimensions matter in different situations.

d(a, b, mask) = Σ mask[i] × |a[i] - b[i]| Vector A: 10 25 -5 40 15 ... Vector B: 12 20 0 38 10 ... Mask: 1 1 0 1 0 ... |Diff|: 2 5 5 2 5 Masked sum: 2 + 5 + 0 + 2 + 0 = 9 Unmasked would be: 2 + 5 + 5 + 2 + 5 = 19 Masked dims (gray) are ignored dim 0 dim 1 dim 2 dim 3 dim 4 Grayed dimensions (mask=0) don't contribute to the distance. This focuses comparison on relevant features.

The mask determines which dimensions count. Dimensions with mask=1 contribute their absolute difference to the total. Dimensions with mask=0 are ignored. This allows context-sensitive similarity comparisons.

Why Masking?

Not all dimensions are relevant in every context. When comparing animals by behavior, physical appearance dimensions might be irrelevant. When comparing products by price, brand dimensions might not matter. The mask provides this flexibility without requiring different vector representations for different contexts.

AGISystem2 uses separate dimension ranges for ontological (factual) and axiological (value) information. The BiasController can automatically mask value dimensions when pure factual comparisons are needed, enabling the "veil of ignorance" mode for fair reasoning.

Implementation

The MathEngine provides optimized distance computation:

// Basic masked L1 distance
const dist = mathEngine.maskedL1(vectorA, vectorB, mask);

// With ontology-only mask (dims 0-255)
const ontoDist = mathEngine.maskedL1(vectorA, vectorB, ontologyMask);

// With full mask (all 384 dims)
const fullDist = mathEngine.maskedL1(vectorA, vectorB, fullMask);

Mask Types

Mask TypeDimensionsUse Case
Full mask All 384 Complete similarity including values
Ontology mask 0-255 Factual similarity only (veil of ignorance)
Axiology mask 256-383 Value similarity only
Custom mask User-defined Domain-specific comparisons

Why L1 (Manhattan)?

L1 distance sums absolute differences rather than squared differences (L2/Euclidean). This has practical advantages:

Related Documentation