Tried using curve_fit (scipy API, for fitting a sigmoid) with fixed seed for numpy, but still the results vary somewhat. Is there any way to make it deterministic completely?
As requested in the comments, here's a minimal working example:
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, 8.340850913002296e-05), (-1.0, 0.0), (2.0, 0.010306481917677357)]
points2 = [(4.0, 1.0), (-1.0, 0.0), (3.0, 0.9793319563421965), (0.0, 8.340850913002296e-05), (1.0, 8.340850913002296e-05), (2.0, 0.010306481917677357)]
print(fit_sigmoid(points1))
print(fit_sigmoid(points2))
Seems like the order of the points matters. Out of curiousness, what's the reason behind this?