Skip to content

chc.symbolic

Stability tier: experimental.

Symbolic extraction from a Kolmogorov-Arnold layer: turn a learned edge into a formula.

RBFKANLayer advertises each input-output edge as "an extractable 1D curve". This module is the extraction. An edge of that layer is exactly

phi_ji(z) = sum_g coeff[j,i,g] * exp(-((z - grid_g) * inv_h)^2) + base_weight[j,i] * silu(z),

a genuine scalar function of one scalar, so it can be sampled and fitted against a small library of closed forms. Two structural facts decide the API:

Gauge. The layer computes bias_j + sum_i phi_ji(z_i), which is invariant under phi_ji -> phi_ji + k_i, bias_j -> bias_j - sum_i k_i. Individual edges are therefore identified only up to an additive constant; only the sum of the constants is pinned down. Each extracted edge carries its own offset and the identity is checked, rather than the constant being silently attributed to whichever edge the fit happened to put it in.

Separability. A single layer can represent only additively separable functions. On a target with a genuine interaction the extraction does not fail loudly -- it returns the best additive approximation, which for independent centred inputs is a poor one. The certificate carries that arm so the number is visible instead of assumed away.

SymbolicEdge dataclass

A closed form fitted to one input-output edge of an RBFKANLayer.

__call__(z)

Evaluate the extracted formula -- unlike the layer, this extrapolates.

SymbolicExtractionCurve dataclass

Evidence that extraction recovers the generating formula -- and where it stops working.

kan_edge(layer, out_index, in_index, z)

The exact scalar edge map phi_ji of layer, as a function of one input coordinate.

This is not an approximation of the layer: summing kan_edge over in_index and adding layer.bias[out_index] reproduces layer(z) exactly.

extract_symbolic_edge(layer, out_index, in_index, *, max_terms=2, n_points=401, r2_target=0.999, library=LIBRARY)

Fit a closed form to one edge, on the grid range where the RBF basis has support.

The selection rule is stated rather than tuned: take the smallest subset of library whose least-squares fit reaches r2_target, and if none does, the best subset of size max_terms. An intercept is always present and is reported separately as offset, because it is the gauge-dependent part.

extract_symbolic(layer, *, max_terms=2, n_points=401, r2_target=0.999)

Extract every edge of layer, row-major in (out_index, in_index).

symbolic_extraction_certificate(*, n_samples=4000, num_grid=16, grid_range=3.0, seed=0)

Fit a KAN layer to a KNOWN formula, extract it back, and price the two scope boundaries.

The generating function is 0.7 + 0.5*z0**2 - 1.2*sin(z1) -- additively separable, so a single layer can represent it exactly and the extraction has a right answer to be checked against. Two arms exist to make the certificate able to fail: an interaction target z0*z1 that no additive layer can fit, and evaluation outside the grid range, where the layer loses its RBF support but the extracted formula does not.