0

我正在尝试使用 LMFIT 拟合模型,我可以轻松地执行以下操作:

def loss_function(params):
  residuals = []
  for x, measured in ...:
     y = predict(x, params)
     residuals.append(y - measured)
  return residuals

params = Parameters()
params.add(...)

model = Minimizer(loss_function, params)
result = model.minimize(method='leastsq')

并得到非常合理的结果

现在我还有一些与我的measured变量相关的不确定性(例如测量误差),所以我想通过与之相关的标准误差对残差中的点进行加权(假设它始终是测量值的 20%)。代码现在变成了这样:

def loss_function(params):
  residuals = []
  for x, measured in ...:
     y = predict(x, params)
     residuals.append((y - measured) / (measured * 0.2))
  return residuals

params = Parameters()
params.add(...)

model = Minimizer(loss_function, params)
result = model.minimize(method='leastsq')

问题是现在我得到完全不可靠的拟合结果。为什么?我怎样才能解决这个问题?

4

1 回答 1

0

What is the nature of "totally unreliable"? You would probably want the uncertainties in the data to be strictly positive -- using measured* 0.2 could allow negative values or zeros. Note that if there are NaNs or Infs in the residual, the fit will not work well, and almost certainly leave the parameter values at their starting values.

FWIW, you can pass on arguments to the objective function (for measurements, uncertainties, etc) using the fcn_args argument to Minimizer.

于 2016-06-15T02:24:15.773 回答