pysolvegn.perform_Lcurve_analysis#

perform_Lcurve_analysis(data_term, reg_term, p0, reg_weights, parametrization=None, *, n_labels=10, optimal=False, logarithmic=True, **kwargs)[source]#

Analyze the regularization parameter using the L-curve method.

The L-curve is a graphical method for selecting a regularization parameter in ill-posed or poorly conditioned least-squares problems. It consists in solving the regularized problem for a range of regularization weights and plotting the data-fitting norm against the regularization norm.

For each regularization weight \(\lambda\), the function solves the corresponding regularized least-squares problem using pysolvegn.solve().

The regularization weight is varied over the values provided in reg_weights. A separate Gauss-Newton optimization is performed for each value.

If a parametrization is provided, the optimization is performed in the input parameter space of the parametrization, while the residual and Jacobian functions of the terms are evaluated using the corresponding output parameters.

The parameter transformation is defined as:

\[\mathbf{p}_{out} = P(\mathbf{p}_{in}).\]

The resulting solutions are used to construct the L-curve, whose corner provides a heuristic estimate of a suitable regularization parameter.

Note

The L-curve is generally most informative when the regularization weights span several orders of magnitude. Providing logarithmically spaced values through reg_weights is therefore recommended.

Parameters:
  • data_term (Term) – The term representing the data-fitting part of the least-squares problem. This term is kept unchanged throughout the L-curve analysis.

  • reg_term (Term) – The term representing the regularization part of the least-squares problem. Its weight is varied according to the values in reg_weights. The term must be compatible with the Term API used by pysolvegn.solve().

  • p0 (ArrayLike) – The initial input parameters for the optimization, with shape (n_parameters,). The same initial parameters are used for each regularization weight. If parametrization is None, p0 directly represents the parameters passed to the residual and Jacobian functions. If a parametrization is provided, p0 represents the input parameters \(\mathbf{p}_{in}\) of the parametrization.

  • reg_weights (ArrayLike) – A one-dimensional array containing the regularization weights to evaluate for the L-curve analysis. Each value defines one regularized optimization problem and therefore one point of the L-curve. The values should normally be strictly positive. A logarithmically spaced range is recommended when logarithmic=True.

  • parametrization (Optional[Parametrization], optional (default=None)) – Parametrization defining the transformation from the input parameters optimized by pysolvegn.solve() to the output parameters passed to the residual and Jacobian functions of the terms. The same parametrization is used for every optimization performed during the L-curve analysis.

  • n_labels (Integral, optional (default=10)) – Number of regularization-weight labels displayed on the L-curve plot. This controls only the number of labels displayed on the plot, not the number of regularization weights evaluated.

  • optimal (bool, optional (default=False)) – If True, estimate the corner of the L-curve from its curvature. The estimated optimal regularization weight is displayed on the L-curve together with the corresponding solution. If False, the L-curve is displayed without selecting an optimal regularization weight.

  • logarithmic (bool, optional (default=True)) – If True, display the regularization-weight axis using a logarithmic scale. This is recommended when reg_weights spans several orders of magnitude.

  • **kwargs (Any) – Additional keyword arguments passed directly to pysolvegn.solve() for every regularization weight (convergence criteria, damping, verbosity, …).

Returns:

The function does not return the computed L-curve data or the optimized parameter vectors. It displays the L-curve and, when optimal=True, reports the estimated optimal regularization weight and the corresponding solution.

Return type:

None

Notes

For each regularization weight \(\lambda\), the function solves an independent regularized least-squares problem.

The problem solved for a given \(\lambda\) can be written as:

\[\min_{\mathbf{p}_{in}} \frac{1}{2} \left[ F_{data} \left( P(\mathbf{p}_{in}) \right) + \lambda F_{reg} \left( P(\mathbf{p}_{in}) \right) \right],\]

where \(P\) is the optional parametrization.

The data and regularization terms therefore operate in the output parameter space, while the Gauss-Newton solver optimizes the input parameter space.

The costs \(F_{data}\) and \(F_{reg}\) (without weight) used to build the L-curve are evaluated at the output parameters returned by pysolvegn.solve() (SolveResult.term_parameters). A warning is printed (verbosity >= 1) for the regularization weights whose optimization did not converge (SolveResult.success is False).

For each regularization weight \(\lambda\), let

\[\mathbf{p}_{in,\lambda}\]

denote the optimized input parameter vector.

If a parametrization is provided, the corresponding output parameters are:

\[\mathbf{p}_{out,\lambda} = P( \mathbf{p}_{in,\lambda} ).\]

To mathematically determine the L-curve’s corner, its curvature is derived, and the corner is defined as the point where the curvature is maximal.

Lets note:

\[\rho(\lambda) = \sqrt{\|R_{data}\|^2} \quad \text{and} \quad \eta(\lambda) = \sqrt{\|R_{reg}\|^2}\]

First we build the logarithmic L-curve such as:

\[\hat{\rho}(\lambda) = \log(\rho(\lambda)) \quad \text{and} \quad \hat{\eta}(\lambda) = \log(\eta(\lambda))\]

The L-curve is then defined as the parametric curve:

\[\Gamma(\lambda) = (\hat{\rho}(\lambda)/2, \hat{\eta}(\lambda)/2)\]

Then the curvature of the L-curve is defined as follows:

\[\kappa(\lambda) = \frac{(\hat{\rho}/2)''(\hat{\eta}/2)' - (\hat{\rho}/2)'(\hat{\eta}/2)''}{((\hat{\rho}/2)'^2 + (\hat{\eta}/2)'^2)^{3/2}}\]
\[\kappa(\lambda) = 2 \frac{\hat{\rho}''\hat{\eta}' - \hat{\rho}'\hat{\eta}''}{(\hat{\rho}'^2 + \hat{\eta}'^2)^{3/2}}\]

The optimal regularization factor is then defined as the value of \(\lambda\) that maximizes the curvature \(\kappa(\lambda)\).

Warning

The L-curve method is a heuristic method for selecting the regularization parameter, and it may not always provide the optimal solution.

Version#

  • 0.0.1: Initial version.

  • 0.1.0: Refactored to use the new Term and solve API, added L-curve analysis and optimal regularization selection.

  • 0.3.0: Modifying function according to new nomenclature.