cherab.inversion.regularization.GCVΒΆ

class cherab.inversion.regularization.GCVSourceΒΆ

Bases: Criterion

Generalized Cross-Validation (GCV) criterion.

Note

The theory and implementation of GCV criterion can be seen here.

Methods

gcv(solver,Β beta)

Calculate of GCV criterion function.

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

Find the optimal parameter by minimizing GCV with basinhopping.

plot_gcv()

Plot GCV as a function of the regularization parameter.

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

Calculate of GCV criterion function.

GCV function \(\mathcal{G}(\lambda)\) can be expressed with SVD components as:

\[\mathcal{G}(\lambda) = \frac{\rho}{\left[r - \sum_{i=1}^r f_{\lambda, i}\right]^2}.\]
Parameters:
solver: _SVDBaseΒΆ

An _SVDBase instance providing rho.

beta: floatΒΆ

Regularization parameter.

Returns:

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

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

Find the optimal parameter by minimizing GCV 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_gcv(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_gcv(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 GCV 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.