nlsq.precision.bound_inference.infer_bounds¶
- nlsq.precision.bound_inference.infer_bounds(xdata, ydata, p0, safety_factor=10.0, enforce_positivity=True)[source]¶
Infer reasonable parameter bounds from data and initial guess.
This is a convenience function that creates a BoundsInference instance and returns the inferred bounds.
- Parameters:
xdata (array_like) – Independent variable data
ydata (array_like) – Dependent variable data
p0 (array_like) – Initial parameter guess
safety_factor (float, optional) – Multiplier for bound ranges (larger = more conservative). Default: 10.0
enforce_positivity (bool, optional) – Force all bounds to be non-negative if p0 is positive. Default: True
- Returns:
lower_bounds (ndarray) – Lower bounds for each parameter
upper_bounds (ndarray) – Upper bounds for each parameter
- Return type:
Examples
Basic usage:
>>> import numpy as np >>> x = np.linspace(0, 10, 100) >>> y = 2.5 * np.exp(-0.5 * x) + 1.0 >>> p0 = [2.0, 0.5, 1.0] >>> bounds = infer_bounds(x, y, p0) >>> print(f"Lower: {bounds[0]}") >>> print(f"Upper: {bounds[1]}")
With custom safety factor:
>>> bounds = infer_bounds(x, y, p0, safety_factor=20.0) # More conservative
Allow negative parameters:
>>> bounds = infer_bounds(x, y, p0, enforce_positivity=False)