forcefinder.core.auto_regularization#

Contains helper functions for performing automatic regularization with the truncated singular value decomposition, ridge regression (Tikhonov), and the elastic net. These functions are intended to work with data from a SourcePathReceiver object.

Copyright 2025 National Technology & Engineering Solutions of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains certain rights in this software.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Functions#

tikhonov_full_path_for_l_curve(frfs, response[, ...])

Performs the inverse force estimation problem and computes the necessary residual and

compute_regularized_residual_penalty_for_l_curve(frfs, ...)

Computes the residual and penalty from the regularized SVD components of an FRF

compute_regularized_svd_inv(frfs[, ...])

Computes the inverted regularized SVD components for an automatic Tikhonov

mean_squared_error(validation_frfs, ...)

Computes the mean squared error of the validation response(s) from the

leave_one_out_cv(frfs, response[, ...])

Estimates the error in a force estimation problem with leave one out cross

k_fold_cv(frfs, response[, number_folds, random_seed, ...])

Estimates the error in a force estimation problem with K-fold cross

l_curve_optimal_regularization(regularization_values, ...)

Selects the optimal regularization parameter using L-curve methods.

broadcasting_l_curve_criterion(x_axis, y_axis, ...[, ...])

Finds the "optimal" regularization value from an L-curve via the

broadcasting_l_curve_by_distance(x_axis, y_axis, ...)

Finds the "optimal" regularization from an L-curve by finding the parameter

select_model_by_information_criterion(H, x, f, method)

Performs model selection with the desired information criterion.

compute_tikhonov_regularized_frf_pinv(frfs[, ...])

Computes the Tikhonov regularized FRF pseudo-inverse for many regularization parameters.

compute_regularized_forces(regularized_frf_inverse, ...)

Computes the forces from a regularized inverse of an FRF matrix.

l_curve_selection(regularization_values, penalty, ...)

Selects the optimal regularization parameter and forces using L-curve methods.

l_curve_criterion(x_axis, y_axis, regularization_values)

Finds the "optimal" regularization value from an L-curve via the

optimal_l_curve_by_distance(x_axis, y_axis, ...)

Finds the "optimal" regularization from an L-curve by finding the parameter

compute_residual_penalty_for_l_curve(frfs, forces, ...)

Computes the residual and penalty for an inverse force estimation problem

Module Contents#

tikhonov_full_path_for_l_curve(frfs, response, low_regularization_limit=None, high_regularization_limit=None, number_regularization_values=100)[source]#

Performs the inverse force estimation problem and computes the necessary residual and penalty for model selection with the L-curve criterion.

Parameters:
  • frfs (ndarray) – The array of FRFs for the inverse force estimation problem, should be organized [number of lines, number of responses, number of references].

  • response (ndarray) – The response to compute the forces from. Should be sized [number of lines, number of responses] for linear spectra or [number of lines, number of responses, number of responses] for power spectra.

  • low_regularization_limit (ndarray, optional) – The low regularization limit to search through. This should be a 1d array with a length that matches the number of frequency lines in the SourcePathReceiver object. The default is the smallest singular value of the frf array (on a frequency-frequency basis).

  • high_regularization_limit (ndarray, optional) – The high regularization limit to search through. This should be a 1d array with a length that matches the number of frequency lines in the SourcePathReceiver object. The default is the largest singular value of the frf array (on a frequency-frequency basis).

  • number_regularization_values (int, optional) – The number of regularization parameters to search over, where the potential parameters are geometrically spaced between the low and high regularization limits. The default is 100.

Returns:

  • regularization_values (ndarray) – The regularization parameters that were used in the inverse. It is sized [number of parameters, number of lines].

  • residual (ndarray) – The residual error (i.e., sum squared error) between the computed and truth response. It is sized [number of parameters, number of lines].

  • penalty (ndarray) – The penalty to use in the L-curve parameter selection, which is the squared sum of the forces. It is sized [number of parameters, number of lines].

Notes

The regularization values are spread over a geometric sequence that spans the low and high regularization limits.

The high and low regularization parameter limits cannot be set to zero in this function. Any values that are zero are reset to machine epsilon.

compute_regularized_residual_penalty_for_l_curve(frfs, response, Uh, regularized_S, V)[source]#

Computes the residual and penalty from the regularized SVD components of an FRF for an automatic Tikhonov regularization problem.

Parameters:
  • frfs (ndarray) – The array of FRFs for the inverse force estimation problem, should be organized [number of lines, number of responses, number of references].

  • response (ndarray) – The response to compute the forces from. Should be sized [number of lines, number of responses] for linear spectra or [number of lines, number of responses, number of responses] for power spectra.

  • Uh (ndarray) – The conjugate-transpose of the left singular vectors of the supplied FRFs. It is shaped [number of lines, number of responses, number of references].

  • V (ndarray) – The right singular vectors of the supplied FRFs. It is shaped [number of lines, number of references, number of references].

  • regularized_S (ndarray) – The inverted and Tikhonov regularized singular values of the supplied FRFs. It is shaped [number of values, number of lines, number of references].

Returns:

  • regularization_values (ndarray) – The regularization parameters that were used in the inverse. It is sized [number of parameters, number of lines].

  • residual (ndarray) – The residual error (i.e., sum squared error) between the computed and truth response. It is sized [number of parameters, number of lines].

  • penalty (ndarray) – The penalty to use in the L-curve parameter selection, which is the squared sum of the forces. It is sized [number of parameters, number of lines].

compute_regularized_svd_inv(frfs, low_regularization_limit=None, high_regularization_limit=None, number_regularization_values=100)[source]#

Computes the inverted regularized SVD components for an automatic Tikhonov regularization problem.

Parameters:
  • frfs (ndarray) – The array of FRFs for the inverse force estimation problem, should be organized [number of lines, number of responses, number of references].

  • low_regularization_limit (ndarray, optional) – The low regularization limit to search through. This should be a 1d array with a length that matches the number of frequency lines in the SourcePathReceiver object. The default is the smallest singular value of the frf array (on a frequency-frequency basis).

  • high_regularization_limit (ndarray, optional) – The high regularization limit to search through. This should be a 1d array with a length that matches the number of frequency lines in the SourcePathReceiver object. The default is the largest singular value of the frf array (on a frequency-frequency basis).

  • number_regularization_values (int, optional) – The number of regularization parameters to search over, where the potential parameters are geometrically spaced between the low and high regularization limits. The default is 100.

Returns:

  • regularization_values (ndarray) – The regularization parameters that were used in the inverse. It is sized [number of parameters, number of lines].

  • Uh (ndarray) – The conjugate-transpose of the left singular vectors of the supplied FRFs. It is shaped [number of lines, number of responses, number of references].

  • V (ndarray) – The right singular vectors of the supplied FRFs. It is shaped [number of lines, number of references, number of references].

  • regularized_S (ndarray) – The inverted and Tikhonov regularized singular values of the supplied FRFs. It is shaped [number of values, number of lines, number of references].

Notes

The regularization values are spread over a geometric sequence that spans the low and high regularization limits.

The high and low regularization parameter limits cannot be set to zero in this function. Any values that are zero are reset to machine epsilon.

mean_squared_error(validation_frfs, validation_response, frf_inverse, training_response)[source]#

Computes the mean squared error of the validation response(s) from the inverse problem.

Parameters:
  • validation_frfs (ndarray) – The FRFs that are used to compute the predicted response(s) from the predicted forces. Should be sized [number of lines, number of validation responses, number of references].

  • validation_response (ndarray) – The validation response to compare the predicted response against. Should be sized [number of lines, number of validation responses].

  • frf_inverse (ndarray) – The inverted FRFs that are used to compute the predicted forces. Should be sized [number of lines, number of references, number of training responses].

  • training_response (ndarray) – The training responses that are used to compute the predicted forces. Should be sized [number of lines, number of training responses].

Returns:

mean_squared_error – The mean squared error of the predicted response. It is a 1D array that is sized the number of lines.

Return type:

ndarray

Notes

This function assumes that there are at least two DOFs in the training response.

leave_one_out_cv(frfs, response, low_regularization_limit=None, high_regularization_limit=None, number_regularization_values=100, error_function=mean_squared_error)[source]#

Estimates the error in a force estimation problem with leave one out cross validation.

Parameters:
  • frfs (ndarray) – The full FRF array to use in the inverse problem. It should be sized [number of lines, number of responses, number of references].

  • response (ndarray) – The full response array to use in the inverse problem. It should be sized [number of lines, number of responses].

  • low_regularization_limit (ndarray, optional) – The low regularization limit to search through. This should be a 1d array with a length that matches the number of frequency lines in the SourcePathReceiver object. The default is the smallest singular value of the frf array (on a frequency-frequency basis).

  • high_regularization_limit (ndarray, optional) – The high regularization limit to search through. This should be a 1d array with a length that matches the number of frequency lines in the SourcePathReceiver object. The default is the largest singular value of the frf array (on a frequency-frequency basis).

  • number_regularization_values (int, optional) – The number of regularization parameters to search over, where the potential parameters are geometrically spaced between the low and high regularization limits. The default is 100.

  • error_function (function, optional) –

    The function that is used to compute the error in the inverse problem. The function should take the following parameters:

    • validation_frfs

      ndarray that is sized [number of lines, number of validation responses, number of references].

    • validation_response

      ndarray that is sized [number of lines, number of responses].

    • frf_inverse

      ndarray that is sized [number of lines, number of references, number of training responses].

    • training_response

      ndarray that is sized [number of lines, number of training responses, 1].

    The function should output a 1d array of the computed error that is sized number of lines. The default function computes the residual squared error.

Returns:

  • regularization_values (ndarray) – The regularization values for the inverse problem. It is sized [number_regularization_values, number of lines].

  • error (ndarray) – The prediction error from the inverse problem. It is sized [number_regularization_values, number of responses, number of lines].

k_fold_cv(frfs, response, number_folds=None, random_seed=randbits(128), low_regularization_limit=None, high_regularization_limit=None, number_regularization_values=100, error_function=mean_squared_error)[source]#

Estimates the error in a force estimation problem with K-fold cross validation.

Parameters:
  • frfs (ndarray) – The full FRF array to use in the inverse problem. It should be sized [number of lines, number of responses, number of references].

  • response (ndarray) – The full response array to use in the inverse problem. It should be sized [number of lines, number of responses].

  • number_folds (int) – The number of folds to use in the cross validation. The number of response DOFs must be evenly divisible by the number of folds.

  • random_seed (int) – The seed for the random number generator that selects response DOFs that are used in the different folds of the cross validation. The default is a randomly selected integer.

  • low_regularization_limit (ndarray, optional) – The low regularization limit to search through. This should be a 1d array with a length that matches the number of frequency lines in the SourcePathReceiver object. The default is the smallest singular value of the frf array (on a frequency-frequency basis).

  • high_regularization_limit (ndarray, optional) – The high regularization limit to search through. This should be a 1d array with a length that matches the number of frequency lines in the SourcePathReceiver object. The default is the largest singular value of the frf array (on a frequency-frequency basis).

  • number_regularization_values (int, optional) – The number of regularization parameters to search over, where the potential parameters are geometrically spaced between the low and high regularization limits. The default is 100.

  • error_function (function, optional) –

    The function that is used to compute the error in the inverse problem. The function should take the following parameters:

    • validation_frfs

      ndarray that is sized [number of lines, number of validation responses, number of references].

    • validation_response

      ndarray that is sized [number of lines, number of responses].

    • frf_inverse

      ndarray that is sized [number of lines, number of references, number of training responses].

    • training_response

      ndarray that is sized [number of lines, number of training responses, 1].

    The function should return a 1d array with the computed errors that is sized number of lines. The default function computes the mean squared error.

Returns:

  • regularization_values (ndarray) – The regularization values for the inverse problem. It is sized [number_regularization_values, number of lines].

  • error (ndarray) – The prediction error from the inverse problem. It is sized [number_regularization_values, number of folds, number of lines].

Raises:

ValueError – If the number of response DOFs is not evenly divisible by the number of folds.

Notes

The response DOFs for the cross validation folds are selected by a random number generator. This can lead to different results for multiple function runs, since the default behavior is to use a different random number generator every time the function is ran. A random seed can be supplied to avoid the variability in the response DOF selection. However, different computers may still select different response DOFs for the different folds (even with the same seed), for a variety of reasons.

l_curve_optimal_regularization(regularization_values, penalty, residual, l_curve_type='forces', optimality_condition='curvature')[source]#

Selects the optimal regularization parameter using L-curve methods.

Parameters:
  • regularization_values (ndarray) – The regularization values that were searched over. This should be sized [number of regularization values, number of frequency lines].

  • penalty (ndarray) – The penalty from the regularized least squares problem. This should be sized [number of regularization values, number of frequency lines].

  • residual (ndarray) – The residual from the regularized least squares problem (typically the mean squared error). This should be sized [number of regularization values, number of frequency lines].

  • l_curve_type (str) –

    The type of L-curve that is used to find the “optimal regularization parameter. The available types are:

    • forces (default)

      This L-curve is constructed with the “size” of the forces on the Y-axis and the regularization parameter on the X-axis [ar_lcor_3].

    • standard

      This L-curve is constructed with the residual squared error on the X-axis and the “size” of the forces on the Y-axis [ar_lcor_1], [ar_lcor_2].

  • optimality_condition (str) –

    The method that is used to find an “optimal” regularization parameter. The options are:

    • curvature (default)

      This method searches for the regularization parameter that results in maximum curvature of the L-curve. It is also referred to as the L-curve criterion.

    • distance

      This method searches for the regularization parameter that minimizes the distance between the L-curve and a “virtual origin”. A virtual origin is used, because the L-curve is scaled and offset to always range from zero to one, in this case.

Returns:

optimal_regularization – A vector of the optimal regularization values, as defined by the L-curve. The length matches that number of frequency lines.

Return type:

ndarray

Raises:

ValueError

If any of the following occurs:

  • If the requested L-curve type is not available.

  • If the requested optimality condition is not available.

References

[ar_lcor_1]

P.C. Hansen and D.P. O’Leary, “The Use of the L-Curve in the Regularization of Discrete Ill-Posed Problems,” SIAM Journal on Scientific Computing, vol. 14, no. 6, pp. 1487-1503, 1993.

[ar_lcor_2]

P.C. Hansen, “The L-curve and its use in the numerical treatment of inverse problems,” in Computational Inverse Problems in Electrocardiology,” WIT Press, 2000, pp. 119-142.

[ar_lcor_3]

M. Rezghi and S. Hosseini, “A new variant of L-curve for Tikhonov regularization,” Journal of Computational and Applied Mathematics, vol. 231, pp. 914-924, 2008.

broadcasting_l_curve_criterion(x_axis, y_axis, regularization_values, return_curvature=False)[source]#

Finds the “optimal” regularization value from an L-curve via the location where its curvature is at a maximum (the L-curve criterion) [ar_blcc_1], [ar_blcc_2].

Parameters:
  • x_axis (ndarray) – This is a vector that defines the X-axis of the L-curve. The variable that is used for this depends on the type of L-curve that is being used. This should be sized [number of regularization values, number of frequency lines].

  • y_axis (ndarray) – This is a vector that defines the Y-axis of the L-curve. The variable that is used for this depends on the type of L-curve that is being used. This should be sized [number of regularization values, number of frequency lines].

  • regularization_values (ndarray) – This is a vector of regularization values that were used in the linear regression problem that created the L-curve. This should be sized [number of regularization values, number of frequency lines].

  • return_curvature (bool) – Whether or not to return the computed curvature function. The default is False.

Returns:

  • optimal_regularization (ndarray) – This is the optimal regularization value based on the L-curve criterion. It is sized [number of frequency lines]

  • idx (ndarray) – The index that correspond to the optimal curvature. It is sized [number of frequency lines]

  • curvature (ndarray, optional) – A vector of the curvature of the L-curve for the give sequence of regularization_values. This is not returned by default. It is sized [number of regularization values, number of frequency lines].

Notes

The code will automatically skip frequency lines where the regularization parameter doesn’t change (e.g., 0 Hz).

References

[ar_blcc_1]

P.C. Hansen and D.P. O’Leary, “The Use of the L-Curve in the Regularization of Discrete Ill-Posed Problems,” SIAM Journal on Scientific Computing, vol. 14, no. 6, pp. 1487-1503, 1993.

[ar_blcc_2]

P.C. Hansen, “The L-curve and its use in the numerical treatment of inverse problems,” in Computational Inverse Problems in Electrocardiology,” WIT Press, 2000, pp. 119-142.

broadcasting_l_curve_by_distance(x_axis, y_axis, regularization_values)[source]#

Finds the “optimal” regularization from an L-curve by finding the parameter that puts the curve closest to the “virtual origin”.

Parameters:
  • x_axis (ndarray) – This is a vector that defines the X-axis of the L-curve. The variable that is used for this depends on the L-curve type this should be sized [number of regularization values, number of frequency lines].

  • y_axis (ndarray) – This is a vector that defines the Y-axis of the L-curve. The variable that is used for this depends on the L-curve type this should be sized [number of regularization values, number of frequency lines].

  • regularization_values (ndarray) – This is a vector of regularization values that were used in the linear regression problem that created the L-curve. This should be sized [number of regularization values, number of frequency lines].

Returns:

  • optimal_regularization (float) – This is the optimal regularization value based on the L-curve distance from the origin.

  • idx (int) – The index that correspond to the optimal curvature.

Notes

This technique applies a scale and offset to the L-curve so the X and Y-axis always ranges from zero to one. This is required to obtain predictable behavior from the method, but can also distort the shape of the curve.

select_model_by_information_criterion(H, x, f, method)[source]#

Performs model selection with the desired information criterion.

Parameters:
  • H (ndarray) – The FRFs that were used to estimate the forces, sized: [number_lines, number_responses, number_references].

  • x (ndarray) – The responses that were used in the force estimation, sized: [number_lines, number_responses].

  • f (ndarray) – The estimated forces from the model, sized: [number_lines, number_models, number_references]

  • method (str) –

    The desired information criterion, the available options are:

    • ’BIC’

      The Bayesian information criterion

    • ’AIC’

      The Akaike information criterion

    • ’AICC’

      The corrected Akaike information criterion

Returns:

selected_forces – The forces that were selected using the desired model, sized: [number_lines, number_references]

Return type:

ndarray

Raises:

NotImplementedError – If the supplied responses are a CPSD matrix.

compute_tikhonov_regularized_frf_pinv(frfs, low_regularization_limit=None, high_regularization_limit=None, number_regularization_values=100)[source]#

Computes the Tikhonov regularized FRF pseudo-inverse for many regularization parameters.

Parameters:
  • frfs (ndarray) – The array of FRFs to be inverted, should be organized [number of lines, number of responses, number of references].

  • low_regularization_limit (ndarray) – The low regularization limit to search through. This should be a 1d array with a length that matches the number of frequency lines in the SourcePathReceiver object. The default is the smallest singular value of the frf array (on a frequency-frequency basis).

  • high_regularization_limit (ndarray) – The high regularization limit to search through. This should be a 1d array with a length that matches the number of frequency lines in the SourcePathReceiver object. The default is the largest singular value of the frf array (on a frequency-frequency basis).

  • number_regularization_values (int) – The number of regularization parameters to search over, where the potential parameters are geometrically spaced between the low and high regularization limits. The default is 100.

Returns:

  • regularized_frf_pinv (ndarray) – Regularized pseudo-inverse of the FRF array. It is sized [number of parameters, number of lines, number of responses, number of references].

  • lambda_values (ndarray) – The regularization parameters that were used in the inverse. It is sized [number of parameters, number of lines].

compute_regularized_forces(regularized_frf_inverse, response)[source]#

Computes the forces from a regularized inverse of an FRF matrix.

Parameters:
  • regularized_frf_inverse (ndarray) – Regularized pseudo-inverse of the FRF array. Should be sized [number of parameters, number of lines, number of references, number of responses].

  • response (ndarray) – The response to compute the forces from. Should be sized [number of lines, number of responses] for linear spectra or [number of lines, number of responses, number of responses] for power spectra.

Returns:

regularized_forces – The regularized forces from the supplied parameters. It is sized [number of parameters, number of lines, number of references] for linear spectra or [number of parameters, number of lines, number of references, number of references] for power spectra.

Return type:

ndarray

l_curve_selection(regularization_values, penalty, residual, forces_full_path, l_curve_type='forces', optimality_condition='curvature', curvature_method='numerical')[source]#

Selects the optimal regularization parameter and forces using L-curve methods.

Parameters:
  • regularization_values (ndarray) – The regularization values that were searched over. This should be sized [number of frequency lines, number of regularization values]

  • penalty (ndarray) – The penalty from the regularized least squares problem. This should be sized [number of frequency lines, number of regularization values]

  • residual (ndarray) – The residual from the regularized least squares problem (typically the mean squared error). This should be sized [number of frequency lines, number of regularization values]

  • forces_full_path (ndarray) – The forces that were estimated in the regularized least squares problem. It should be sized such that the number of frequency lines is on the first axis and the number of regularization values is on the second axis.

  • l_curve_type (str) –

    The type of L-curve that is used to find the “optimal regularization parameter. The available types are:

    • forces (default)

      This L-curve is constructed with the “size” of the forces on the Y-axis and the regularization parameter on the X-axis [ar_lcs_3].

    • standard

      This L-curve is constructed with the residual squared error on the X-axis and the “size” of the forces on the Y-axis [ar_lcs_1], [ar_lcs_2].

  • optimality_condition (str) –

    The method that is used to find an “optimal” regularization parameter. The options are:

    • curvature (default)

      This method searches for the regularization parameter that results in maximum curvature of the L-curve. It is also referred to as the L-curve criterion.

    • distance

      This method searches for the regularization parameter that minimizes the distance between the L-curve and a “virtual origin”. A virtual origin is used, because the L-curve is scaled and offset to always range from zero to one, in this case.

  • curvature_method (str) –

    The method that is used to compute the curvature of the L-curve, in the case that the curvature is used to find the optimal regularization parameter. The options are:

    • numerical (default)

      This method computes the curvature of the L-curve via numerical derivatives

    • cubic_spline

      This method fits a cubic spline to the L-curve the computes the curvature from the cubic spline (this might perform better if the L-curve isn’t “smooth”)

Raises:

ValueError

If any of the following occurs:

  • If the requested L-curve type is not available.

  • If the requested optimality condition is not available.

Returns:

  • chosen_force (ndarray) – The force at the optimal regularization value, as defined by the L-curve. It is sized [number of frequency lines, force array size].

  • optimal_regularization (ndarray) – A vector of the optimal regularization values, as defined by the L-curve. The length matches that number of frequency lines.

Notes

This function can handle forces as either power spectra or linear spectra.

References

[ar_lcs_1]

P.C. Hansen and D.P. O’Leary, “The Use of the L-Curve in the Regularization of Discrete Ill-Posed Problems,” SIAM Journal on Scientific Computing, vol. 14, no. 6, pp. 1487-1503, 1993.

[ar_lcs_2]

P.C. Hansen, “The L-curve and its use in the numerical treatment of inverse problems,” in Computational Inverse Problems in Electrocardiology,” WIT Press, 2000, pp. 119-142.

[ar_lcs_3]

M. Rezghi and S. Hosseini, “A new variant of L-curve for Tikhonov regularization,” Journal of Computational and Applied Mathematics, vol. 231, pp. 914-924, 2008.

l_curve_criterion(x_axis, y_axis, regularization_values, method='numerical', return_curvature=False)[source]#

Finds the “optimal” regularization value from an L-curve via the location where its curvature is at a maximum (the L-curve criterion) [ar_lcc_1], [ar_lcc_2].

Parameters:
  • x_axis (ndarray) – This is a vector that defines the X-axis of the L-curve. The variable that is used for this depends on the type of L-curve that is being used.

  • y_axis (ndarray) – This is a vector that defines the Y-axis of the L-curve. The variable that is used for this depends on the type of L-curve that is being used.

  • regularization_values (ndarray) – This is a vector of regularization values that were used in the linear regression problem that created the L-curve.

  • method (str) –

    This is the method by which the curvature is computed, the available methods are:

    • numerical (default)

      This method computes the curvature of the L-curve via numerical derivatives

    • cubic_spline

      This method fits a cubic spline to the L-curve the computes the curvature from the cubic spline (this might perform better if the L-curve isn’t “smooth”)

Returns:

  • optimal_regularization (float) – This is the optimal regularization value based on the L-curve criterion.

  • idx (int) – The index that correspond to the optimal curvature.

  • curvature (ndarray) – A vector of the curvature of the L-curve for the give sequence of regularization_values.

References

[ar_lcc_1]

P.C. Hansen and D.P. O’Leary, “The Use of the L-Curve in the Regularization of Discrete Ill-Posed Problems,” SIAM Journal on Scientific Computing, vol. 14, no. 6, pp. 1487-1503, 1993.

[ar_lcc_2]

P.C. Hansen, “The L-curve and its use in the numerical treatment of inverse problems,” in Computational Inverse Problems in Electrocardiology,” WIT Press, 2000, pp. 119-142.

optimal_l_curve_by_distance(x_axis, y_axis, regularization_values)[source]#

Finds the “optimal” regularization from an L-curve by finding the parameter that puts the curve closest to the “virtual origin”.

Parameters:
  • x_axis (ndarray) – This is a vector that defines the X-axis of the L-curve. The variable that is used for this depends on the type of L-curve that is being used.

  • y_axis (ndarray) – This is a vector that defines the Y-axis of the L-curve. The variable that is used for this depends on the type of L-curve that is being used.

  • regularization_values (ndarray) – This is a vector of regularization values that were used in the linear regression problem that created the L-curve.

Returns:

  • optimal_regularization (float) – This is the optimal regularization value based on the L-curve distance from the origin.

  • idx (int) – The index that correspond to the optimal curvature.

Notes

This technique applies a scale and offset to the L-curve so the X and Y-axis always ranges from zero to one. This is required to obtain predictable behavior from the method, but can also distort the shape of the curve.

compute_residual_penalty_for_l_curve(frfs, forces, response)[source]#

Computes the residual and penalty for an inverse force estimation problem in preparation for model selection with the L-curve criterion.

Parameters:
  • frfs (ndarray) – The FRFs that are used to compute the system response. Should be sized [number of lines, number of responses, number of references].

  • forces (ndarray) – The estimated forces from the inverse problem. Should be sized [number of parameters, number of lines, number of references] for linear spectra or [number of parameters, number of lines, number of references, number of references] for power spectra

  • response (ndarray) – The “truth” responses to compare the computed responses to. Should be sized [number of lines, number of responses] for linear spectra or [number of lines, number of responses, number of responses] for power spectra.

Returns:

  • residual (ndarray) – The residual error (i.e., sum squared error) between the computed and truth response. It is sized [number of parameters, number of lines].

  • penalty (ndarray) – The penalty to use in the L-curve parameter selection, which is the squared sum of the forces. It is sized [number of parameters, number of lines].

Notes

The returned residual and penalty are the squared norm of the residual error vector and force vector, respectively.