尝试使用 curve_fit (scipy API,用于拟合 sigmoid)和 numpy 的固定种子,但结果仍然有所不同。有没有办法让它完全确定性?
根据评论中的要求,这是一个最小的工作示例:
from scipy.optimize import curve_fit
import numpy as np
def sigmoid(x, b, mu, max_kr):
if isinstance(x, list) or isinstance(x, np.ndarray):
return [sigmoid(xx, b, mu, max_kr) for xx in x]
else:
return max_kr/(1+10**(mu*(-x+b)))
def fit_sigmoid(points):
xs, ys = list(zip(*points))
err = None
popt, pcov = curve_fit(sigmoid, xs, ys, bounds=([-np.inf, 0, 0], [np.inf, np.inf, 1]), ftol=len(xs)*1e-6)
b, mu, max_kr = popt
return mu
np.random.seed = 12
points1 = [(4.0, 1.0), (1.0, 8.340850913002296e-05), (3.0, 0.9793319563421965), (0.0, …Run Code Online (Sandbox Code Playgroud)