我试图将高斯图和洛伦兹图拟合成一组共振数据,但是scipy.optimize.curve_fit函数返回错误' OptimizeWarning:无法估计参数的协方差&# 39 ;.我需要参数的协方差来计算拟合中的误差 - 任何想法如何摆脱它?
我的代码是:
popt1,pcov1 = opt.curve_fit(gaussianfit, E, I, p0=[E0,I0,sigma])
errorp1 = (pcov1)**0.5
print 'error in gaussian fit =', errorp1
plt.plot(E, gaussianfit(E,*popt1), '-', label='Gaussian Fit')
popt2,pcov2 = opt.curve_fit(lorentzfit, E, I, p0=[E0,I0,gamma])
errorp2 = (pcov2)**0.5
print 'error in combined fit =', errorp2
plt.plot(E, lorentzfit(E,*popt2),'-', label='Lorentzian Fit')
#plot gaussian and lorentzian fits combined
errorp = (pcov1 + pcov2)**0.5
print 'error in lorentzian fit =', errorp #print error
plt.plot(E, (gaussianfit(E,*popt1) + lorentzfit(E,*popt2))/2, '-', `label='Combined fit')
感谢您的帮助! :)
答案 0 :(得分:0)
就我而言,为参数const fs = require('fs');
let data = "";
process.stdin.setEncoding('utf-8');
process.stdin.on('data', chunk => {
// I'm just collecting the chunks into 'data',
// but you might choose to do some processing here
data += chunk;
});
process.stdin.on('end', () => {
// do some more processing here, if needed
fs.writeFileSync('output.json', data);
});
添加合理的初始猜测有助于避免使用selenium-webdriver | node index.js
。如果不提供p0
,该算法可能会发出警告并返回所有参数等于1的数组。