cherab.inversion.regularization.criteria.PRESSΒΆ

class cherab.inversion.regularization.criteria.PRESSSourceΒΆ

Bases: Criterion

Predicted Residual Error Sum of Squares (PRESS) criterion.

The PRESS criterion, also known as ordinary cross-validation, selects the regularization parameter \(\lambda\) by minimizing the leave-one-out cross-validation error.

Note

The theory and implementation of the PRESS criterion are described in the PRESS theory page.

Methods

optimize(solver,Β bounds[,Β stepsize])

Find the optimal parameter by minimizing PRESS with basinhopping.

plot_press()

Plot PRESS as a function of the regularization parameter.

press(solver,Β beta)

Calculate the PRESS criterion function.

press(solver: _SVDBase, beta: float) floatSourceΒΆ

Calculate the PRESS criterion function.

The PRESS function \(\mathcal{P}(\lambda)\) can be expressed with SVD components as:

\[\mathcal{P}(\lambda) = \left\| \left[ \mathrm{Diag}\!\left( \mathbf{I} - \mathbf{U}\mathbf{F}_\lambda\mathbf{U}^\mathsf{T} \right) \right]^{-1} \!\left( \mathbf{I} - \mathbf{U}\mathbf{F}_\lambda\mathbf{U}^\mathsf{T} \right)\hat{\mathbf{b}} \right\|_2^2,\]

where \(\hat{\mathbf{b}} = \mathbf{B}\mathbf{b}\) (or simply \(\mathbf{b}\) when \(\mathbf{B} = \mathbf{I}\)) and \(\mathrm{Diag}(\mathbf{M})\) denotes the diagonal matrix formed from the diagonal entries of \(\mathbf{M}\).

Parameters:
solver: _SVDBaseΒΆ

An _SVDBase instance providing U, filter, data, etc.

beta: floatΒΆ

Regularization parameter \(\lambda\).

Returns:

float – Value of PRESS function at a given regularization parameter.

Raises:

RuntimeError – If solver.data is not set.

optimize(solver: _SVDBase, bounds: tuple[float, float], stepsize: float = 10, **kwargs: Any) tuple[float, OptimizeResult]SourceΒΆ

Find the optimal parameter by minimizing PRESS with basinhopping.

Parameters:
solver: _SVDBaseΒΆ

An _SVDBase instance.

bounds: tuple[float, float]ΒΆ

(log10_lower, log10_upper) search interval.

stepsize: float = 10ΒΆ

Step-size for the underlying global optimizer.

**kwargs: AnyΒΆ

Extra arguments forwarded to the optimizer.

Returns:

  • lambda_opt (float) – Optimal regularization parameter.

  • result (OptimizeResult) – Optimizer result object returned by basinhopping.

plot_press(solver: _SVDBase | None = None, axes: None = None, bounds: Collection[float | None] | None = None, n_beta: int = 500, show_min_line: bool = True) tuple[Axes, Figure]SourceΒΆ
plot_press(solver: _SVDBase | None = None, axes: Axes | None = None, bounds: Collection[float | None] | None = None, n_beta: int = 500, show_min_line: bool = True) Axes

Plot PRESS as a function of the regularization parameter.

Parameters:
solver: _SVDBase | None = NoneΒΆ

An _SVDBase instance. If None, the last solver used in optimize() is used.

axes: None = NoneΒΆ
axes: Axes | None = None

Matplotlib axes to plot on. If None, a new figure and axes are created.

bounds: Collection[float | None] | None = NoneΒΆ

Boundary pair of log10 of regularization parameters, by default None. If None, the bounds are generated by the solver as described in SVD._generate_bounds(). If you set the bounds like (-10, None), the higher bound is set to \(\log_{10}\sigma_1^2\). Raise an error if a >= b in (a, b).

n_beta: int = 500ΒΆ

Number of regularization parameters, by default 500.

show_min_line: bool = TrueΒΆ

Whether to show a vertical line at the optimal regularization parameter.

Returns:

  • axes (Axes) – A matplotlib Axes object.

  • fig (Figure) – A matplotlib figure object if axes is None, otherwise None.