nlsq.utils.validators.InputValidator

class nlsq.utils.validators.InputValidator(fast_mode=True)[source]

Bases: object

Comprehensive input validation for curve fitting functions.

__init__(fast_mode=True)[source]

Initialize the input validator.

Parameters:

fast_mode (bool, default True) – If True, skip expensive validation checks for better performance. If False, perform all validation checks.

validate_curve_fit_inputs(f, xdata, ydata, p0=None, bounds=None, sigma=None, absolute_sigma=True, check_finite=True)[source]

Validate inputs for curve_fit function.

This method orchestrates the validation pipeline by calling focused helper methods for each validation step.

Parameters:
  • f (callable) – Model function to fit

  • xdata (array_like) – Independent variable data

  • ydata (array_like) – Dependent variable data

  • p0 (array_like, optional) – Initial parameter guess

  • bounds (tuple, optional) – Parameter bounds

  • sigma (array_like, optional) – Uncertainties in ydata

  • absolute_sigma (bool) – Whether sigma is absolute or relative

  • check_finite (bool) – Whether to check for finite values

Returns:

  • errors (list) – List of error messages (empty if no errors)

  • warnings (list) – List of warning messages

  • xdata_clean (np.ndarray) – Cleaned and validated xdata

  • ydata_clean (np.ndarray) – Cleaned and validated ydata

Return type:

tuple[list[str], list[str], ndarray, ndarray]

validate_security_constraints(n_points, n_params, bounds=None, p0=None)[source]

Validate security constraints to prevent DoS and numerical issues.

This method combines all security-focused validation checks.

Parameters:
  • n_points (int) – Number of data points

  • n_params (int) – Number of parameters

  • bounds (tuple | None, optional) – Parameter bounds

  • p0 (array_like | None, optional) – Initial parameter guess

Returns:

  • errors (list) – List of critical error messages

  • warnings (list) – List of warning messages

Return type:

tuple[list[str], list[str]]

validate_least_squares_inputs(fun, x0, bounds=None, method='trf', ftol=1e-08, xtol=1e-08, gtol=1e-08, max_nfev=None)[source]

Validate inputs for least_squares function.

This method orchestrates the validation pipeline by calling focused helper methods for each validation step.

Parameters:
  • fun (callable) – Residual function

  • x0 (array_like) – Initial parameter guess

  • bounds (tuple, optional) – Parameter bounds

  • method (str) – Optimization method

  • ftol (float) – Function tolerance

  • xtol (float) – Parameter tolerance

  • gtol (float) – Gradient tolerance

  • max_nfev (int, optional) – Maximum function evaluations

Returns:

  • errors (list) – List of error messages

  • warnings (list) – List of warning messages

  • x0_clean (np.ndarray) – Cleaned initial guess

Return type:

tuple[list[str], list[str], ndarray]