@@ -192,12 +192,16 @@ def __init__(self, peak_width_limits=(0.5, 12.0), max_n_peaks=np.inf, min_peak_h
192192 self ._gauss_overlap_thresh = 0.75
193193 # Parameter bounds for center frequency when fitting gaussians, in terms of +/- std dev
194194 self ._cf_bound = 1.5
195- # The maximum number of calls to the curve fitting function
196- self ._maxfev = 5000
197195 # The error metric to calculate, post model fitting. See `_calc_error` for options
198196 # Note: this is for checking error post fitting, not an objective function for fitting
199197 self ._error_metric = 'MAE'
200198
199+ ## PRIVATE CURVE_FIT SETTINGS
200+ # The maximum number of calls to the curve fitting function
201+ self ._maxfev = 5000
202+ # The tolerance setting for curve fitting (see scipy.curve_fit - ftol / xtol / gtol)
203+ self ._tol = 0.00001
204+
201205 ## RUN MODES
202206 # Set default debug mode - controls if an error is raised if model fitting is unsuccessful
203207 self ._debug = False
@@ -947,6 +951,7 @@ def _simple_ap_fit(self, freqs, power_spectrum):
947951 aperiodic_params , _ = curve_fit (get_ap_func (self .aperiodic_mode ),
948952 freqs , power_spectrum , p0 = guess ,
949953 maxfev = self ._maxfev , bounds = ap_bounds ,
954+ ftol = self ._tol , xtol = self ._tol , gtol = self ._tol ,
950955 check_finite = False )
951956 except RuntimeError as excp :
952957 error_msg = ("Model fitting failed due to not finding parameters in "
@@ -1005,6 +1010,7 @@ def _robust_ap_fit(self, freqs, power_spectrum):
10051010 aperiodic_params , _ = curve_fit (get_ap_func (self .aperiodic_mode ),
10061011 freqs_ignore , spectrum_ignore , p0 = popt ,
10071012 maxfev = self ._maxfev , bounds = ap_bounds ,
1013+ ftol = self ._tol , xtol = self ._tol , gtol = self ._tol ,
10081014 check_finite = False )
10091015 except RuntimeError as excp :
10101016 error_msg = ("Model fitting failed due to not finding "
@@ -1152,6 +1158,7 @@ def _fit_peak_guess(self, guess):
11521158 try :
11531159 gaussian_params , _ = curve_fit (gaussian_function , self .freqs , self ._spectrum_flat ,
11541160 p0 = guess , maxfev = self ._maxfev , bounds = gaus_param_bounds ,
1161+ ftol = self ._tol , xtol = self ._tol , gtol = self ._tol ,
11551162 check_finite = False )
11561163 except RuntimeError as excp :
11571164 error_msg = ("Model fitting failed due to not finding "
0 commit comments