python 曲线拟合参数能否为数组_Python曲线拟合库,允许我为参数分配边界

I'd like to be able to perform fits that allows me to fit an arbitrary curve function to data, and allows me to set arbitrary bounds on parameters, for example I want to fit function:

f(x) = a1(x-a2)^a3\cdot\exp(-\a4*x^a5)

and say:

a2 is in following range: (-1, 1)

a3 and a5 are positive

There is nice scipy curve_fit function, but it doesn't allow to specify parameter bounds. There also is nice http://code.google.com/p/pyminuit/ library that does generic minimalization, and it allows to set bounds on parameters, but in my case it did not coverge.

解决方案

Note: New in version 0.17 of SciPy

Let's suppose you want to fit a model to the data which looks like this:

y=a*t**alpha+b

and with the constraint on alpha

0

while other parameters a and b remains free. Then we should use the bounds option of curve_fit in the following fashion:

import numpy as np

from scipy.optimize import curve_fit

def func(t, a,alpha,b):

return a*t**alpha+b

param_bounds=([-np.inf,0,-np.inf],[np.inf,2,np.inf])

popt, pcov = curve_fit(func, xdata, ydata,bounds=param_bounds)

Source is here.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值