API reference
Geometry
When is a number computed from two different models a fact, and when is it only a coordinate? reward_lens.geometry answers that with a frame: a per-site whitening artifact that puts two reward directions in a shared basis before anything compares them. Without one, a covariant quantity refuses to report. The plain-words version is gauge and frames.
The frame
A Frame is the frozen whitening artifact for one site and corpus: the mean, the square-root covariance, and the null basis that together fix the gauge. fit_frame estimates it with Ledoit-Wolf shrinkage and refuses fp16 activations, because a gauge you cannot trust is worse than no gauge at all.
reward_lens.geometry.frame.Frame
@dataclass(frozen=True)
The gauge-fixing whitening artifact for one (site, corpus) (DESIGN section 2.7.1).
mean is the reference distribution’s activation mean; sigma_sqrt and sigma_inv_sqrt
are the symmetric square roots of the shrinkage-regularized activation covariance. The canonical
form of a reward direction is Sigma^{1/2} w normalized (canonical.py), which weights
directions by how much the reference distribution varies along them and kills directions it does
not vary along at all. null_basis holds those data-null / gauge directions explicitly (an
orthonormal d x m matrix, or None when none were estimated) so canonicalization can quotient
them exactly rather than relying on the shrinkage floor. estimator_meta records the fit
provenance: sample count, shrinkage intensity, eigenspectrum summary, and the fp32 assertion.
All arrays are fp32. The frame is frozen and carries a content-derived FrameID so it is a
stable, shareable, per-(site, corpus) artifact.
Attributes
| Name | Type | Default |
|---|---|---|
id | FrameID | |
site | Site | |
corpus | DatasetID | None | |
mean | np.ndarray | |
sigma_sqrt | np.ndarray | |
sigma_inv_sqrt | np.ndarray | |
null_basis | np.ndarray | None | |
estimator_meta | dict[str, Any] | field(default_factory=dict) |
Properties
-
d : int: Ambient activation dimension the frame whitens in. -
null_dim : int: Number of estimated data-null / gauge directions (0 whennull_basisis None).
reward_lens.geometry.frame.fit_frame
fit_frame(
activations: Any,
margins: Any | None = None,
*,
site: Site | None = None,
corpus: DatasetID | None = None,
shrinkage: str = 'lw',
null_var_ratio: float = _DEFAULT_NULL_VAR_RATIO,
null_grad_ratio: float = _DEFAULT_NULL_GRAD_RATIO
) -> Frame Fit a Frame from a reference activation matrix (DESIGN section 2.7.1).
activations is an n x d fp32 matrix of reference-distribution activations read at
site (fp16 is refused). margins, when supplied, are the per-item reward margins used to
refine the null-subspace estimate to directions of near-zero margin gradient. shrinkage
selects the covariance estimator; only Ledoit-Wolf ("lw") is implemented, and "none" is
accepted for the raw sample covariance (which is only well conditioned when n comfortably
exceeds d).
The fit computes the mean, the shrinkage covariance, its symmetric square roots, and the
null basis, then derives the content FrameID from structural content (site, corpus, counts,
rounded eigenspectrum summary) so identical fits share an id across platforms.
Canonicalization and the cross-model angle
canonicalize projects a direction out of the null space and whitens it into the frame. effective_angle then compares two directions inside that frame and returns Evidence carrying the canonical cosine, the raw cosine, a STARC distance, and a regret bound. It is covariant, so it calls the gauge gate and raises without a frame. Two versions of one reward model can read as near-orthogonal in raw coordinates (raw cosine near ), which is exactly the coordinate artifact a frame removes.
reward_lens.geometry.canonical.canonicalize
canonicalize(w: Any, frame: Frame) -> np.ndarray Canonical form of a reward direction in a frame: Sigma^{1/2} w normalized.
DESIGN section 2.7.1. Whitening by Sigma^{1/2} weights each direction by how much the
reference distribution varies along it, so directions the distribution does not vary along
contribute nothing to the canonical direction. When the frame carries an estimated null_basis
the gauge components of w are projected out first, which makes canonicalization exactly
invariant to adding data-null directions to w (rather than leaving the small residual the
Ledoit-Wolf shrinkage floor would otherwise pass through). The result is a unit fp32 vector.
Raises NumericsError if w has no on-distribution component (Sigma^{1/2} w is zero),
which means the reward direction lives entirely in the gauge subspace and has no canonical form.
reward_lens.geometry.canonical.effective_angle
effective_angle(
w_a: Any,
w_b: Any,
frame: Frame,
*,
n_boot: int = 1000,
activations_for_bound: Any | None = None,
ci_level: float = 0.95,
max_pairs_corpus: int = 512,
seed: int = 0,
subject: SubjectRef | None = None,
provenance: Provenance | None = None
) -> Evidence[AngleResult] Canonical angle between two reward directions with a CI and a STARC regret bound.
DESIGN section 2.7.1 / Appendix A13. Reports cos(w_tilde_a, w_tilde_b) in the shared
frame (the gauge-fixed alignment), the raw cosine for contrast, a bootstrap CI obtained by
refitting the frame on corpus resamples (when activations_for_bound is supplied), and a
behavioural regret bound: the empirical worst-case preference disagreement on the frame corpus,
which the canonical (STARC) distance upper-bounds.
The quantity is COVARIANT and the frame argument has no default; this calls
require_frame_for_comparison so a frameless cross-signal comparison raises (gate 2, I3).
faithful_to is “STARC 2309.15257 / partial identifiability 2411.15951”.
Curvature and skew
hessian_spectrum estimates the eigenvalue density of the reward Hessian by Lanczos, and participation_ratio reduces that spectrum to how many directions the curvature actually spreads across. PreferenceRankTest looks for intransitivity: a planted cycle that a single scalar reward cannot represent.
reward_lens.geometry.hessian.hessian_spectrum
hessian_spectrum(
source: Any,
view: Any | None = None,
site: Site | None = None,
*,
k: int = 64,
method: Literal['lanczos', 'slq'] = 'lanczos',
dim: int | None = None,
scalar_fn: Any | None = None,
batch: Any | None = None,
n_starts: int = 1,
density: bool = False,
seed: int = 0,
subject: SubjectRef | None = None,
provenance: Provenance | None = None
) -> Evidence[SpectrumResult] Top-k reward-Hessian spectrum at a site, materialization-free via HVPs.
DESIGN section 2.7.2. source is a RewardSignal, a Runtime, a SymmetricOperator, or a
plain matvec callable (the synthetic-operator test path); the reward Hessian is the
double-backprop of the readout scalar at site, so nothing larger than dim probe vectors
is ever held, which is what keeps the spectrum within the 8B memory budget. Lanczos with full
reorthogonalization gives the extreme eigenvalues; n_starts > 1 seed-averages the Ritz
values across random starts for robustness; density=True adds an SLQ spectral-density
estimate for the tail.
The spectrum is INVARIANT (a property of one signal at one site, not a cross-signal comparison), so no frame is required.
reward_lens.geometry.hessian.participation_ratio
participation_ratio(spectrum: Any) -> float Participation ratio of a curvature spectrum: the effective dimension d_eff.
PR = (sum |lambda_i|)^2 / sum lambda_i^2 (Appendix A9 / A16). It counts how many eigenvalues
carry the curvature: n equal eigenvalues give PR = n, a single dominant eigenvalue gives
PR = 1. Magnitudes are used so a mixed-sign (indefinite) Hessian still reports the effective
number of curved directions. Accepts a SpectrumResult, a raw array, or any 1-D sequence.
reward_lens.geometry.skew.PreferenceRankTest
PreferenceRankTest(
activations: Any,
pairs: Any,
rank_k: int,
*,
proj_dim: int | None = None,
reg: float = 0.001
) Fit a rank-k skew preference operator and test cyclic recovery (DESIGN section 2.7.3, T8).
activations is the n x d matrix of frozen penultimate features (one row per response
item); pairs is a (P, 2) integer array of (winner_index, loser_index) preferences;
rank_k is the skew rank to fit. Optionally project activations to proj_dim principal
components first, which keeps the d^2 skew fit tractable at large d.
run splits the pairs into train and held-out, fits the transitive (scalar) baseline and the
rank-k skew operator on the train pairs, and reports their held-out accuracies. The gap is
the cyclic structure the scalar head cannot express (theorem T8). The result is INVARIANT: rank
and predictive accuracy do not depend on the activation coordinate basis, so this is a
within-model structural claim that needs no frame.
Methods
run(
*,
test_frac: float = 0.3,
seed: int = 0,
sig_ratio: float = 0.05,
subject: SubjectRef | None = None,
provenance: Provenance | None = None
) -> Evidence[PreferenceRankResult]
src