Generic GL Aggregator

Generic Graded Logic (GL) Aggregator

Implements the canonical aggregation form from the GL aggregator paper:

\[A(x \mid c) = \sum_i \alpha_i(\psi(u, c))\,F_i(u), \quad u = II(x)\]
where:
  • x = (x1, …, xn) are the original inputs in [0, 1]

  • II(x) is a learned row-stochastic coordinate transformation R

  • F_i(u) are anchor aggregation operators (min, mean, max, …)

  • psi(u, c) is a feature mapping capturing relational input characteristics

  • alpha_i are weights (static, conditional, or value-dependent)

  • c is an optional external context variable

The architecture supports N-ary inputs and four weight modes:

  1. Static: fixed convex combination of anchors (classical MAT).

  2. Composite: coordinate transformation R enables composite operators like partial absorption to emerge from standard anchors.

  3. Conditional: weights depend on external context c via neural gating.

  4. Value-dependent: weights depend on input features psi(u) via neural gating, enabling joint-condition aggregation.

class bacon.aggregators.lsp.generic_gl.GenericGLAggregator(anchors: Sequence[str] = ('min', 'harmonic', 'geometric', 'mean', 'quadratic', 'max'), anchor_interpolation: int = 0, weight_mode: str = 'static', use_transform: bool = False, context_dim: int = 0, hidden_dim: int = 16, tau: float = 0.5, identity_reg: float = 0.0, eps: float = 1e-07)

Generic Graded Logic aggregator - N-ary canonical form.

Implements the canonical GL aggregation (paper Section 4.5):

\[A(x \mid c) = \sum_i \alpha_i(\psi(u, c))\,F_i(u), \quad u = R x\]

where Fᵢ are anchor operators from the generalized-mean family and the convex weights αᵢ are controlled by the Mean Andness Theorem.

The six core anchors from the paper are:

\[ext{min} \rightarrow \text{harmonic} \rightarrow \text{geometric} \rightarrow \text{mean} \rightarrow \text{quadratic} \rightarrow \text{max}\]
\[(\alpha=1),\ (\alpha=3/4),\ (\alpha=5/8),\ (\alpha=1/2),\ (\alpha=3/8),\ (\alpha=0)\]

Two additional t-norm / t-conorm anchors (product, prob_sum) are available as extensions but are not part of the standard GL set.

Parameters:
  • anchors (sequence of str) – Anchor operators. The paper’s default set is ('min', 'harmonic', 'geometric', 'mean', 'quadratic', 'max'). Additional choices: 'product' (algebraic t-norm, andness ≈ 1.08), 'prob_sum' (probabilistic t-conorm, andness ≈ −0.08).

  • anchor_interpolation (int) – Number of linearly interpolated anchors to insert between each consecutive pair. For example, anchor_interpolation=1 with the default 6 anchors produces 6 + 5 = 11 total anchors; the 5 extras sit at the midpoints of each adjacent pair. 0 (default) adds no interpolated anchors.

  • weight_mode (str) –

    • 'static' — fixed learnable logits (MAT).

    • 'conditional' — weights from context c.

    • 'value_dependent' — weights from input features ψ(u).

    • 'full' — weights from both inputs and context.

  • use_transform (bool) – Learn a row-stochastic N×N coordinate transformation R.

  • context_dim (int) – Dimension of external context c.

  • hidden_dim (int) – Hidden width of the neural gating network.

  • tau (float) – Softmax temperature.

  • identity_reg (float) – Regularization toward identity R.

  • eps (float) – Numerical stability constant.

aggregate_float(values: Sequence[float], a: float, weights: Sequence[float]) float

Aggregate N scalar values with scalar andness a and N weights.

aggregate_tensor(values: Sequence[Any], a: Any, weights: Sequence[Any] | Tensor) Tensor

Aggregate N tensors with andness a and N weights.

forward(x: Tensor, c: Tensor | None = None) Tensor

Compute A(x | c).

Parameters:
  • x (torch.Tensor) – Shape [N, ...] — N input truth values in [0, 1].

  • c (torch.Tensor, optional) – External context.

Returns:

Aggregated output [...], clamped to [0, 1].

Return type:

torch.Tensor

get_transform_matrix() Tensor

Return the current N×N row-stochastic transformation matrix R.

transform(x: Tensor) Tensor

Apply u = R @ x.

Parameters:

x (torch.Tensor) – Shape [N, ...] where N is the number of inputs.

Returns:

Same shape — each row is a convex combination of inputs.

Return type:

torch.Tensor

transform_regularization() Tensor

||R - I||^2 penalty.