Results: scorequant.results¶
Every type a task, report or certificate returns. None is constructed by hand; import one to annotate code or check a type.
PartitionResult
dataclass
¶
PartitionResult(
labels: ndarray,
training_scores: ndarray,
cell_weights: ndarray,
cell_score_sums: ndarray,
cell_score_means: ndarray,
information_full: ndarray,
information_partitioned: ndarray,
objective: float,
transform: FisherTransform,
transformed_centers: ndarray | None,
metric: ndarray | None,
criterion: DOptimality | ProfiledDOptimality,
config: PartitionConfig,
execution: ExecutionConfig,
train_report: InformationReport,
provenance: ScoreProvenance,
accepted_moves: int,
scans: int,
exchange_stable: bool,
best_remaining_gain: float,
objective_history: ndarray,
positive_weight_mask: ndarray,
lloyd_iterations: int = 0,
accepted_lloyd_steps: int = 0,
geometry: GeometryReport | None = None,
profiled_report: ProfiledInformationReport
| None = None,
profiled_geometry: ProfiledGeometryReport | None = None,
schema: ScoreSchema | None = None,
)
Represent optimized labels of one fixed weighted score table.
The solver counters are reported separately and never merged: scans and
accepted_moves describe exchange work, while lloyd_iterations and
accepted_lloyd_steps describe guarded batch relabelings. Both stay zero
for a solver that performs neither. objective_history records every
accepted step of every phase in order and is strictly increasing.
Geometry diagnostics are criterion-specific and never shared: a
DOptimality result carries geometry and no profiled_geometry, a
ProfiledDOptimality result carries profiled_geometry and no
geometry. The two measure different objects — a strict Mahalanobis
Voronoi rule that exchange stability guarantees, and an efficient
semimetric whose Voronoi rule a stable profiled partition may violate — so
one name for both would claim an implication that does not hold.
exchange_stable and geometry are verdicts at config.gain_tolerance,
which GeometryReport records, and never claims at tolerance zero. A
finite solver stops at that threshold, so verifying its output against a
stricter one would reject partitions it legitimately converged on.
information_kind
property
¶
Describe whether supplied-score matrices justify exact Fisher language.
"supplied_score_surrogate" means the reported matrices measure
Var(E[s_hat | q]) for the supplied vectors s_hat, which is
the model's Fisher information only when s_hat equals the model
score.
compile_quantizer ¶
compile_quantizer(
*, execution: ExecutionConfig | None = None
) -> Quantizer
Compile an exchange-stable D partition into its canonical rule.
Theorem 3 makes a one-point-exchange-stable, nonsingular D partition a
self-consistent \(I^{-1}\)-Mahalanobis Voronoi partition of the observed
rows, so the compiled rule
\(\hat q(s)=\arg\min_b (s-\mu_b)^\top I^{-1}(s-\mu_b)\) is bookkeeping
rather than a new fit. The theorem is exact; the partition behind it is
not. A finite solver stops at config.gain_tolerance, so the
guarantee this method can offer is self-consistency at that tolerance:
each admissible individual prediction disagreement has relocation gain at
most gain_tolerance, priced against the original partition. Successful
solver result construction separately checks that every positive-weight
disagreement is admissible. Positive tolerance alone does not guarantee
compilability: a singleton tie can be refused
(CE-D-COMPILE-SINGLETON-TIE-001). No bound on simultaneous relabeling,
global suboptimality or population loss follows from the tolerance
(CE-D-COMPILE-BATCH-TOLERANCE-001). These are numerical exact-formula
diagnostics in the retained score subspace, not interval arithmetic.
Boundary ties are never resolved here. predict_scores keeps the
ordinary argmin rule, which is deterministic and breaks a tie toward
the lowest cell index; the tolerance governs verification, not
assignment.
Returns:
-
Quantizer–The deployable rule itself -- the partition's centers, metric and transform. It is a rule, not a new fit, so it carries no labels, reports or history; those already belong to this partition.
Raises:
-
ContractError–When the compilation geometry is missing.
-
RefusalError–When the criterion is not
DOptimality, when the partition is not exchange-stable, or when the rule relabels a training row by more thangain_tolerance.
QuantizerResult
dataclass
¶
QuantizerResult(
quantizer: Quantizer,
criterion: Criterion,
config: QuantizerConfig,
execution: ExecutionConfig,
trace: OptimizationTrace,
labels: ndarray,
train_report: InformationReport,
validation_report: InformationReport | None,
provenance: ScoreProvenance,
hardening_gap: float | None = None,
source_kind: SourceKind = "score_sample",
train_profiled_report: ProfiledInformationReport
| None = None,
validation_profiled_report: ProfiledInformationReport
| None = None,
)
Represent a reusable hard rule on raw score vectors.
metric
property
¶
Return the frozen common Mahalanobis metric, if the rule carries one.
transform
property
¶
transform: FisherTransform
Return the informative-subspace projection the rule was fitted in.
schema
property
¶
schema: ScoreSchema | None
Return the names of the raw score coordinates, when they were declared.
information_kind
property
¶
Describe whether supplied-score matrices justify exact Fisher language.
"supplied_score_surrogate" means the reported matrices measure
Var(E[s_hat | q]) for the supplied vectors s_hat, which is
the model's Fisher information only when s_hat equals the model
score.
predict_scores ¶
predict_scores(
scores: ArrayLike,
*,
execution: ExecutionConfig | None = None,
) -> ndarray
Assign raw score rows with the frozen score-space rule.
Rows are assigned in memory-bounded chunks so that predicting on a
large sample never materializes the full [n_rows, n_bins, rank]
distance tensor at once; each row's distance and nearest-center
argmin are independent of every other row, so chunking is
bit-identical to the unchunked computation.
evaluate_scores ¶
evaluate_scores(
scores: ArrayLike,
weights: ArrayLike | None = None,
*,
execution: ExecutionConfig | None = None,
) -> InformationReport
Evaluate the frozen rule on a new weighted score sample.
to_dict ¶
Return JSON-ready in-memory state, not a versioned artifact format.
OptimizationTrace
dataclass
¶
OptimizationTrace(
steps: ndarray,
centers: ndarray,
objective: ndarray,
bin_weights: ndarray,
train_hard_retention: ndarray,
objective_label: str,
validation_hard_retention: ndarray | None = None,
soft_retention: ndarray | None = None,
temperatures: ndarray | None = None,
gradient_norms: ndarray | None = None,
)
Store aggregate quantizer optimization history.
Attributes:
-
objective_label(str) –Units of
objective. Solvers do not share one objective convention:"whitened_sse"is a minimized weighted within-cell squared error in Fisher-whitened coordinates,"logdet_retained"is a maximized retained log determinant, and"profiled_logdet"is a maximized profiled log determinant. Never compare two traces across labels.
FisherTransform
dataclass
¶
FisherTransform(
matrix: ndarray,
eigenvectors: ndarray,
eigenvalues: ndarray,
retained_eigenvalues: ndarray,
rank_rtol: float,
threshold: float,
whiten: bool,
)
Projection onto informative Fisher directions, optionally whitened.
Scores are never mean-centered. matrix maps raw score vectors from
shape [..., P] to optimization coordinates [..., R].
Attributes:
-
matrix(ndarray) –Projection or whitening matrix with shape
[P, R]. -
eigenvectors, eigenvalues–Complete eigendecomposition of the symmetrized input Fisher matrix.
-
retained_eigenvalues(ndarray) –Eigenvalues above the numerical rank threshold.
-
rank_rtol, threshold–Relative and absolute rank thresholds.
-
whiten(bool) –Whether retained directions are scaled by inverse square root eigenvalues.
dropped_directions
property
¶
Return the number of projected-out score directions.
apply ¶
apply(
scores: ArrayLike,
*,
execution: ExecutionConfig | None = None,
) -> ndarray
Map raw scores into the fitted informative coordinate system.
InformationReport
dataclass
¶
InformationReport(
fisher_unbinned: ndarray,
fisher_binned: ndarray,
retained_matrix: ndarray,
retained_eigenvalues: ndarray,
arithmetic_mean_retention: float,
geometric_mean_retention: float,
logdet_retention: float,
bin_weights: ndarray,
bin_counts: ndarray,
bin_effective_sample_sizes: ndarray,
effective_rank: int,
rank_threshold: float,
psd_residual_min_eigenvalue: float,
)
ProfiledInformationReport
dataclass
¶
ProfiledInformationReport(
interest: tuple[int, ...],
nuisance: tuple[int, ...],
schur_unbinned: ndarray,
schur_binned: ndarray,
nuisance_unbinned: ndarray,
nuisance_binned: ndarray,
objective: float,
logdet_retention: float,
geometric_mean_retention: float,
interest_rank: int,
nuisance_rank: int,
schema: ScoreSchema | None = None,
)
Report same-label profiled information for interest and nuisance blocks.
interest_names
property
¶
Return the names of the parameters of interest, when they were declared.
nuisance_names
property
¶
Return the names of the profiled nuisance parameters, when declared.
describe ¶
Summarize the profiling split in one line, by name when one is available.
interest: HSPCs says what was optimized; interest: (4,) requires
the reader to remember the column order.
to_dict ¶
Return a JSON-compatible profiled-information representation.
RetentionUncertainty
dataclass
¶
RetentionUncertainty(
estimate: float | None,
standard_error: float | None,
confidence_interval: tuple[float, float] | None,
confidence_level: float,
n_observations: int,
status: RetentionUncertaintyStatus,
)
Sampling uncertainty of a frozen rule's geometric-mean retention on held-out true scores.
Produced by retention_uncertainty. The point estimate is the same
uncentred plug-in \(\hat\eta_D=(\det\hat I_Z/\det\hat V)^{1/d}\) that
information_report reports as geometric_mean_retention on a
full-rank sample; the standard error is the influence-function estimate
of RETENTION-PLUGIN-CLT-FROZEN-VECTOR (scalar case
RETENTION-PLUGIN-CLT-FROZEN-SCALAR), and the interval is the
untruncated two-sided Wald interval
\(\hat\eta_D\pm z_{1-\alpha/2}\,\widehat{\mathrm{SE}}\). It is never
clipped, so an endpoint can fall below zero or above one; that is a
property of the first-order interval, not a claim about the retention.
The interval covers sampling variability only: the rule is frozen, the rows are independent and equally weighted draws from the reference law, and the scores are the model's true scores. A classifier or other estimated score adds a separate reporting bias that no error bar on the proxy sample measures.
Attributes:
-
estimate(float | None) –Plug-in geometric-mean retention,
Nonewhen the rule declares too few cells or the full moment matrix is rank deficient, and exactly0.0by convention when the retained matrix is numerically rank deficient. -
standard_error(float | None) –Influence-function standard error,
0.0when the influence values cancel to rounding noise, andNonewhenever no first-order theory applies. -
confidence_interval(tuple[float, float] | None) –(lower, upper)Wald endpoints, orNonewhen the interval is unavailable. -
confidence_level(float) –Nominal two-sided level the interval was built for.
-
n_observations(int) –Number of evaluation rows the moments were formed from.
-
status(RetentionUncertaintyStatus) –"ok": estimate, standard error and interval are all available."insufficient_cells": the rule declares at mostdcells, so the population retention is zero at the reference law (FI-RANK-CEILING) and the plug-in is the biased endpoint estimator; nothing is reported."singular_full_information": the supplied scores lose a direction at the rank threshold, so the geometric-mean retention of allddirections is undefined and nothing is reported rather than a silently projected surrogate."singular_retained_information": the full matrix is regular but the between-cell matrix is numerically rank deficient on this sample, so the diagnostic reports zero by its numerical-rank convention and withholds the interval. The exact plug-in can still be positive below the threshold; the verdict does not identify the population rank (RETENTION-PLUGIN-SINGULAR-ENDPOINT-RATE)."degenerate_variance": the influence values vanish to rounding, so the interval is withheld; this is a numerical guard and does not assert that the population variance is zero.
EfficientScoreBound
dataclass
¶
EfficientScoreBound(
upper_bound: float,
labels: ndarray,
efficient_scores: ndarray,
n_bins: int,
interest: tuple[int, ...],
)
Certify a ceiling on profiled information from the full-data efficient score.
Let \(\hat s=s_\psi-B^\ast s_\lambda\) be the efficient score built from the
full-data information matrix, and let \(q\) be any hard rule with at most
n_bins cells. Efficient-score domination states
so maximizing the right-hand side over all n_bins-cell rules of
\(\hat s\) upper-bounds the profiled objective of every n_bins-cell rule
of the full score space. For one parameter of interest the right-hand side
is scalar, the maximizer has ordered interval cells, and the exact weighted
interval dynamic program attains it. upper_bound is the logarithm of
that maximum, in the same convention as PartitionResult.objective under
ProfiledDOptimality: an uncentered between-cell second moment of raw
score columns, never a mean-centered variance.
Attributes:
-
upper_bound(float) –Log-scale certified ceiling on the profiled objective.
-
labels(ndarray) –Interval labels of the efficient score, defined for every input row. Zero-weight rows carry the label of their nearest cell mean and never influence the bound. These labels are also a strong initializer: pass them as
initial_labelstooptimize_partitionunderProfiledDOptimality. -
efficient_scores(ndarray) –Full-information efficient scores with shape
[N, 1]. -
n_bins, interest–Cell budget and interest columns the bound was certified for.
Notes
The bound is a property of one weighted score table. Comparing it to a
partition of different scores or weights is meaningless, and gap_to
cannot detect that mismatch; it only checks the criterion convention and the
cell budget. Refinement monotonicity makes the bound valid for any partition
with at most n_bins cells.
gap_to ¶
gap_to(partition_result: PartitionResult) -> float
Return the certified slack between the bound and an achieved objective.
Parameters:
-
partition_result(PartitionResult) –Profiled-\(D_s\) result on the same weighted score table, with the same interest columns and at most
n_binscells.
Returns:
-
float–upper_boundminus the achieved profiled objective. The value is nonnegative up to floating-point error on valid inputs.
to_dict ¶
Return a JSON-compatible representation of the certified bound.
GeometryReport
dataclass
¶
GeometryReport(
maximum_voronoi_violation: float,
guaranteed_violation_gain: float,
maximum_violation_gain: float,
maximum_separation_residual: float,
violating_moves: int,
evaluated_moves: int,
voronoi_consistent: bool,
separation_certified: bool,
gain_tolerance: float,
)
Certify the self-consistent Voronoi geometry of a finite D partition.
At a one-point-exchange-stable, positive-definite D partition every
admissible move that violates the Mahalanobis-Voronoi rule of the terminal
metric \(I^{-1}\) would raise the log determinant by at least
\(\log(1+\alpha\beta q_\delta^2/4)>0\), where
\(q_\delta=(\mu_a-\mu_b)^\top I^{-1}(\mu_a-\mu_b)\) separates the two cell
means. Exact zero-tolerance stability under the merged-atom hypotheses
therefore forces strict Voronoi geometry, which is
what makes PartitionResult.compile_quantizer well posed. This report
measures both sides of that statement on the terminal state instead of
assuming them.
A finite solver stops at a tolerance, so this certificate states one too.
The theorem is exact, but the guaranteed gain of a violation shrinks with
the cell separation, and on a large sample \(q_\delta\) shrinks with the
sample size: once \(\log(1+\alpha\beta q_\delta^2/4)\) falls below the
solver's gain_tolerance, exchange stability at that tolerance no
longer forbids a row from sitting a hair past a cell boundary. Verifying
such a state at tolerance zero rejects a partition the solver never claimed
to have refined further, so every field below is judged against
gain_tolerance instead.
At positive tolerance this report covers admissible individual moves only. It does not certify that every prediction disagreement is admissible; the solver checks that separately and refuses singleton disagreements. It also supplies no bound on simultaneous relabeling or population loss.
All quadratic forms use the same metric and cell means the solver ended with, evaluated over the distinct positive-weight score atoms.
Attributes:
-
maximum_voronoi_violation(float) –Largest value over rows of the own-cell distance minus the smallest other-cell distance. A nonpositive value means every row already sits in its nearest cell under the terminal metric. It is
-inffor a single-cell partition, which has no alternative destination. This is a Mahalanobis distance gap, not a criterion gain, so it is a diagnostic and never the verdict. -
guaranteed_violation_gain(float) –Largest Theorem-3 lower bound \(\log(1+\alpha\beta q_\delta^2/4)\) over admissible Voronoi-violating moves, and exactly
0.0when no such move exists. -
maximum_violation_gain(float) –Largest exact log-determinant gain over the same admissible Voronoi-violating moves, and exactly
0.0when none exists. Theorem 3 bounds this from below, soguaranteed_violation_gain <= maximum_violation_gainalways holds. This is the quantity the solver drives below its tolerance, so it is the one the verdict uses. -
maximum_separation_residual(float) –Largest value over unordered cell pairs of \(q_\delta-(1/W_a+1/W_b)\). The leverage lemma makes this nonpositive for every labeling, so a positive value indicates numerical trouble rather than a better partition. It is
-inffor a single-cell partition. -
violating_moves, evaluated_moves–Number of admissible Voronoi-violating moves and of admissible moves. A move is admissible when its source cell keeps positive weight and its destination differs from its source.
-
voronoi_consistent(bool) –Whether
maximum_violation_gainis at mostgain_tolerance: no Voronoi violation is worth more than the solver's own stopping threshold. It isTruewhenever no row is misplaced at all. -
separation_certified(bool) –Whether
maximum_separation_residualrespects the leverage lemma up to a small relative floating-point tolerance. -
gain_tolerance(float) –Log-determinant gain tolerance this certificate holds at, taken from the configuration that produced the labels.
voronoi_consistentmeans self-consistent at this tolerance and claims nothing at tolerance zero.
to_dict ¶
Return a JSON-compatible Voronoi-geometry representation.
ProfiledGeometryReport
dataclass
¶
ProfiledGeometryReport(
metric: ndarray,
maximum_positive_violation: float,
maximum_theoretical_bound: float,
maximum_bound_residual: float,
violating_moves: int,
evaluated_moves: int,
bound_certified: bool,
)
Diagnose the finite efficient-semimetric gap of a profiled partition.
StabilityReport
dataclass
¶
StabilityReport(
stable: bool,
best_gain: float,
best_move: tuple[int, int] | None,
objective: float,
n_bins: int,
criterion: DOptimality | ProfiledDOptimality,
gain_tolerance: float,
)
Certify that no single-row relocation improves one supplied labeling.
The report is produced by exchange_stability_report from exactly one
complete exact scan, so it verifies labels of any origin: a guarded
Mahalanobis-Lloyd run that stopped early, an external tool, or a hand edit.
Stability is always a statement at a tolerance, never at tolerance zero, so the certificate carries the tolerance it was issued at.
Attributes:
-
stable(bool) –Whether no admissible relocation improves the criterion by more than
gain_tolerance. -
best_gain(float) –Largest exact objective gain found in the scan. It is
-infwhen the labeling admits no relocation at all. -
best_move(tuple[int, int] | None) –(row, destination)of that gain in original input row indexing, orNonewhen the labeling is stable. -
objective(float) –Exact criterion value of the supplied labeling, in the convention
PartitionResult.objectiveuses for the same criterion. -
n_bins(int) –Number of cells the labeling declares.
-
criterion(DOptimality | ProfiledDOptimality) –Criterion the scan certified against.
-
gain_tolerance(float) –Strict minimum gain the scan counted as an improvement.
stablemeansbest_gain <= gain_tolerance; a labeling certified at one tolerance is not certified at a smaller one.
PartitionCertificate
dataclass
¶
PartitionCertificate(
status: Literal["optimal", "budget_exhausted"],
objective: float,
labels: ndarray,
upper_bound: float,
gap: float,
nodes_explored: int,
incumbent_was_optimal: bool,
)
Report what a bounded global D search actually proved.
certify_partition explores hard labelings with the singleton-completion
upper bound: any completion of a partial assignment is coarser than the
partial cells together with singleton cells for the unassigned atoms, so
Loewner monotonicity of the log determinant makes
\(\log\det(I_{\text{partial}}+R_t)\) a valid ceiling for the whole subtree.
The search is exponential in the worst case and therefore explicitly
bounded; the certificate always states which of the two outcomes occurred.
Attributes:
-
status(Literal['optimal', 'budget_exhausted']) –"optimal"when the tree was exhausted, so no labeling beatsobjectiveby more than the configured gain tolerance."budget_exhausted"when the node budget stopped the search first. -
objective(float) –Best log determinant found, in the Fisher-whitened convention of
PartitionResult.objectiveunderDOptimality. -
labels(ndarray) –Labels attaining
objective, defined for every input row. Zero-weight rows carry the label of their nearest cell mean in the terminal metric and never influenced the search. -
upper_bound(float) –Global ceiling at termination. It equals
objectivefor a proved optimum and is otherwise the best bound still outstanding on an abandoned subtree. -
gap(float) –upper_boundminusobjective, nonnegative by construction and exactly zero for a proved optimum. -
nodes_explored(int) –Number of search nodes visited, including pruned children.
-
incumbent_was_optimal(bool) –Whether the search proved the starting incumbent optimal without improving it. It is
Falsewhenever the budget was exhausted, because an unfinished search proves nothing about the incumbent.
to_dict ¶
Return a JSON-compatible representation of the certificate.