pysolvegn.perform_Lcurve_analysis#
- perform_Lcurve_analysis(data_term, reg_term, x0, reg_weights, *, n_labels=10, optimal=False, logarithmic=True, **kwargs)[source]#
Optimize the regularization factor using the L-curve method with the Gauss-Newton optimization method.
The L-curve method is a graphical method for selecting the optimal regularization parameter in ill-posed problems. It consists in plotting the norm of the residuals against the norm of the regularization term for different values of the regularization parameter, and selecting the value that corresponds to the corner of the L-curve, which represents a good balance between fitting the data and regularizing the solution.
The optimization is performed by minimizing the residuals between the transformed input points and the output points for each chain solving iteratively a linearized version of the problem at each iteration for different values of the regularization factor, and then selecting the optimal regularization factor based on the L-curve.
Note
For better visualization of the L-curve, providing a logarithmic range of regularization weights is recommended, as the L-curve typically spans several orders of magnitude in the regularization parameter.
- Parameters:
data_term (Term) – The term representing the data fitting part of the least squares problem.
reg_term (Term) – The term representing the regularization part of the least squares problem. The weight of this term will be varied to perform the L-curve analysis.
x0 (ArrayLike) – The initial guess for the parameters of the optimization. Shape (n_parameters,).
reg_weights (ArrayLike) – An array of regularization weights to evaluate for the L-curve analysis.
n_labels (Integral, optional (default=10)) – The number of labels to display on the L-curve plot for the regularization factors. Default is 10.
optimal (bool, optional (default=True)) – If True, the function will compute the optimal regularization factor and parameters, and display them on the L-curve plot.
logarithmic (bool, optional (default=True)) – If True, the L-curve plot will use a logarithmic scale for the regularization weights. This is recommended for better visualization, as the L-curve typically spans several orders of magnitude in the regularization parameter.
**kwargs (Any) – Additional keyword arguments to pass to the optimization function for each regularization factor. This can include stopping criteria, verbosity level, logger, etc.
- Returns:
The function does not return anything, but it prints the optimal regularization factor and parameters, and displays the L-curve plot.
- Return type:
None
Notes
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.
1.0.0: Refactored to use the new Term and solve API, added L-curve analysis and optimal regularization selection.