回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在使用Scipy将我的数据调整为函数。函数给出了两个参数的值,在本例中,<strong><em>a</em></strong>和<strong><em>b</em></strong>。我想使用bound参数来限制这些参数可以接受的值,每个参数都有自己的可接受值范围。在</p>
<p>可接受值:15<;a<;50和0.05<;b<;0.2</p>
<p>我想知道如何实现它们。官方文档只显示了如何对1个参数执行这些操作。这个问题类似于:<a href="https://stackoverflow.com/questions/16760788/python-curve-fit-library-that-allows-me-to-assign-bounds-to-parameters">Python curve fit library that allows me to assign bounds to parameters</a>。它也只处理1个参数的边界。在</p>
<p>以下是我尝试的:</p>
<pre><code>def Ebfit(x,a,b):
Eb_mean = a*(0.0256/kt) # Eb at bake temperature
Eb_sigma = b*Eb_mean
Foursigma = 4*Eb_sigma
Eb_a = np.linspace(Eb_mean-Foursigma,Eb_mean+Foursigma,N_Device)
dEb = Eb_a[1] - Eb_a[0]
pdfEb_a = spys.norm.pdf(Eb_a,Eb_mean,Eb_sigma)
## Retention Time
DMom = np.zeros(len(x),float)
tau = (1/f0)*np.exp(Eb_a)
for bb in range(len(x)):
DMom[bb]= (1 - 2*(sum(pdfEb_a*(1 - np.exp(np.divide(-x[bb],tau))))*dEb))
return DMom
time = datafile['time'][0:501]
Moment = datafile['25Oe'][0:501]
params,extras = curve_fit(Ebfit,time,Moment, p0=[20,0.1], bounds=[(15,50),(0.05,0.2)])
</code></pre>
<p>我还尝试了以下变体,以确定括号是否是问题所在:</p>
^{pr2}$
<p>但是对于所有这些变化我都得到了同样的错误</p>
<blockquote>
<p>ValueError: Each lower bound mush be strictly less than each upper
bound.</p>
</blockquote>
<p>它只适用于单个绑定,例如:</p>
<pre><code>params,extras = curve_fit(Ebfit,time,Moment, p0=[20,0.1], bounds=[0,50])
</code></pre>
<p>感谢任何帮助。
谢谢您!在</p>