Criteria¶
A Criterion is the outer-loop validation oracle: it slices the full
Problem into a training subproblem, drives the inner solver, and
returns the criterion value (and, when asked, the hypergradient chained
through implicit_forward).
- class sparho.Criterion[source]¶
Bases:
ProtocolOuter-loop validation oracle.
Implementations:
HeldOutMSE,HeldOutLogistic,CrossVal.x0is an optional warm-start coefficient guess threaded through to the inner solver. Single-split criteria forward it directly;CrossValignores caller-suppliedx0because it manages its own per-fold cache.tolis an optional inner-solver tolerance that overrides the adapter’s default. Threaded through toSolver.__call__(tol=...). Used by HOAG-style outer loops to schedule inner accuracy across iterations.- __init__(*args, **kwargs)¶
- class sparho.CriterionResult[source]¶
Bases:
objectOutcome of
Criterion.value_and_hypergrad().coefandactive_setare reported from the last (or only) inner solve; forCrossValthey come from the final fold and are diagnostic only — the user is expected to refit on the full data atbest_hyperparamif a single final β is needed.
- class sparho.HeldOutMSE[source]¶
Bases:
objectHeld-out mean-squared-error.
C(β) = (1/|val|) Σ_{i ∈ val} (yᵢ − Xᵢ β)²— matches sklearn’smean_squared_error(no1/2). The gradient∂C/∂βcarries the factor of2.
- class sparho.HeldOutLogistic[source]¶
Bases:
objectHeld-out logistic loss:
C(β) = (1/|val|) Σᵢ log(1 + exp(−yᵢ Xᵢβ)).Labels assumed in
{−1, +1}(sparho’sLogisticLossconvention).
- class sparho.CrossVal[source]¶
Bases:
objectK-fold cross-validation aggregator.
Wraps a single-split base criterion class (typically
HeldOutMSE) over a tuple of(train_idx, val_idx)pairs. Both value and hypergradient are means across folds.Build via
kfold():cv = CrossVal.kfold(problem.n_samples, k=5)
For classification, pass
base=HeldOutLogistictokfold.Warm-start: with
warm_start=True, each fold’s previous-iterationβ*seeds the next inner solve at the same fold. Big wins when the inner solver dominates (sparse-X, small α, large active set); converges to the same answer aswarm_start=Falsebecause Lasso is convex. The cache is mutable but excluded from equality / hash so the dataclass remains a well-behaved value object.- folds: tuple[tuple[ndarray[tuple[Any, ...], dtype[int32]], ndarray[tuple[Any, ...], dtype[int32]]], ...]¶
- base: Callable[[ndarray[tuple[Any, ...], dtype[int32]], ndarray[tuple[Any, ...], dtype[int32]]], Criterion]¶
- classmethod kfold(n_samples, k=5, *, shuffle=True, random_state=0, base=<class 'sparho.criteria.HeldOutMSE'>, warm_start=False)[source]¶
Build a
CrossValfromsklearn.model_selection.KFold.
- __init__(folds, base=<class 'sparho.criteria.HeldOutMSE'>, warm_start=False, _cache=<factory>)¶
- Parameters:
- Return type:
None