Attempting to fit a model to observational data. The code uses data in the range of 0.5 to 1.0 for the independent variable with scipy curve_fit and numerical integration. The function to be integrated also includes an unknown parameter, then subjecting the integrand to evaluation using the trig function sinh(integrand).
After applying curve_fit I get an error message of "loop of ufunc does not support argument 0 of type function which has no callable sinh method". Have I hit a dead end with Python 3? Hope not.
This evaluation code is
#O_m, Hu are unknown parameters to be estimated with model, data
def integr(x,O_m): return intg.quad(lambda x: 1/x(np.sqrt((O_m/x) (1-O_m))) , x, 1, args=(0.02))[0]
O_m = 0.02 #Guess for value of O_m, which shall lie between 0.01 and 1.0
def funcX(x,O_m): result = np.asarray([integr(xx,O_m) for xx in x]) * np.sqrt(abs(1-O_m)) return result
litsped=299793 #the constant speed of light in a vacuum (m/s)
def funcY(x,Hu,O_m): return (litsped/(x * Hu * np.sqrt(abs(1-O_m))))*np.sinh(funcX)
init_guess = [65,0.02] bnds=([50,0.001],[80,1.0])
params, pcov = curve_fit(funcY, xdata, ydata, p0 = init_guess, bounds = bnds, sigma = error, absolute_sigma = True)
ans_Hu, ans_O_m = params
perr = np.sqrt(np.diag(pcov))
CodePudding user response:
Some more information would be useful, e.g. what is your xdata/ydata? Could you rewrite your code as a minimal reproducable example?
P.S. you can format things on stackoverflow as code by writing ``` before and after the code for better readability ;)
CodePudding user response:
Some of the data are here, enough to view the trend and both integration limits
xdata = [1.0,0.9841,0.9747, 0.9569, 0.9305,0.9083, 0.7246,0.6993, 0.5076]
ydata = [0.0, 71.45,118.58, 240.99, 363.08,480.84,2118.36, 3235.94,7550.92]
error = [0.01, 3.95, 12.58, 18.89, 28.45, 33.24, 195.38,373.37,1046.52]