たとえば、私はデータを持っています:
x y1 y2 y1
---------------------
1 5 8 -
2 4 - 4
3 7 7 10
4 9 4 12
5 10 - 20
6 15 - 21
ここで、x は x 軸で、y1、y2、y3 は 3 つの異なるデータ セットであり、これらは一緒に適合されます。
簡単にするために、フィッティング コードの縮小バージョンを次に示します。
def gauss_dataset(params, i, x):
"""calc gaussian from params for data set i
using simple, hardwired naming convention"""
x = params['x_%i' % (i+1)].value
y = params['x_%i' % (i+1)].value
return x + y
def objective(params, x, data):
""" calculate total residual for fits to several data sets held
in a 2-D array, and modeled by Gaussian functions"""
ndata, nx = data.shape
resid = 0.0*data[:]
# make residual per data set
for i in range(ndata):
resid[i, :] = data[i, :] - gauss_dataset(params, i, x)
# now flatten this to a 1D array, as minimize() needs
return resid.flatten()
x = np.linspace(0, 50, 50)
data = []
...
# Rearange data
for col in range(0, data_sets):
for row in range (0, size_rows):
data[col][row] = intens[row][col+1]
# create 5 sets of parameters, one per data set
fit_params = Parameters()
for iy, y in enumerate(data):
fit_params.add( 'x_%i' % (iy+1))
fit_params.add( 'y_%i' % (iy+1))
# run the global fit to all the data sets
minimize(objective, fit_params, args=(x, data))
in minimize(objective, fit_params, args=(x, data))
:
data
is data[y][z]: y - データ セット、z - そのデータ セット内のデータ。そしてx
x軸です。
不足しているデータ ポイントを無視するか、スクリプトを書き直して、各データが独自の x 軸を持つように、Python スクリプト lmfit 最小化を変更するにはどうすればよいですか?:
x1 y1 x2 y2 x3 y3
-----------------------------
1 5 1 8 2 4-
2 4 3 7 3 10
3 7 4 4 4 12
4 9 5 20
5 10 6 21
6 15
また、複数の最小化フィットを使用することはできません (スクリプトは実際には上記よりも複雑です)。 )) は有効な回答ではありません。