0

パラメータを共有する2つの異なる関数に2つのグラフを当てはめようとしています。関数は非常に複雑で、atan、ln、および分数が含まれます。Symfit はこの種のフィッティングに機能を提供しているように見えましたが、フィッティングは

RuntimeWarning: sqrt return np.sqrt(self.variance(param)) で無効な値が検出されました

そして終わらない。

より数値的に機能する別のフィッティング関数はありますか、それとも同じ機能を実現する scipy 関数はありますか?

# parameters
mag, theta, phi, mode_angle = parameters('mag, theta, phi,  mode_angle')

# setting initial parameter values and ranges 
phi.max = math.radians(360)
phi.min = 0
theta.max = math.radians(180)
theta.min = 0
theta.value = math.radians(70)
mode_angle.value = 0.4
mode_angle.min = 0.39
mode_angle.max = 0.47
mag.value = 1e-14
mag.max = 1e-10
mag.min = 1e-18
q0.value = 1e-9
q0.max = 1e-4
q0.min = 1e-13

# variables from two graphs that share the same x axis
x1, y1, y2 = variables('x1, y1, y2')
x = np.linspace(-108, 501-108, 501)

# model includes two functions that share the same parameters and x
model = {
    y1: func1(mag, theta, phi, mode_angle, x1),
    y2: func2(mag, theta, phi, mode_angle, x1)
}

# calling the fit
fit = Fit(model, 
          x1 = x,
          y1 = graph1_ydata, 
          y2 = graph2_ydata, 
          minimizer = DifferentialEvolution
         )

# fit execution
fit_result = fit.execute()

次のスニペットは、ゼロによる除算 (特異点) をすばやく見つけて解決できるため、非常に単純ですが、問題を説明する必要があります。同じ問題 (0 による除算またはおそらく負の根) も std に現れる可能性があります。開発者 計算。パラメータが多いと、これらの問題点を見つけるのがより複雑になります。

# Generating data
data_to_be_fitted=[]
xx = np.linspace(0.00001,12.00001, 400)
for i in range(0, len(xx)):
    data_to_be_fitted.append( 1/xx[i])

q, a = parameters('q, a')
x1, y= variables('x1, y')

# Model
model = {
    y: q/x1         # works with  q / (x-a)
}

# Parameters
q.value = 1
q.min = -1
q.max = 1
a.value = 1
a.min = -1
a.max = 1
# Fitting
x = np.linspace(0,12, 400)
fit = Fit(model, 
          x1 = x, 
          y = data_to_be_fitted
         )
fit_result = fit.execute()
print(fit_result)

フィッティングがフィッティング パラメータを提供してくれることを期待しています。私は、フィットが特異点にぶつかると思います。OK フィッティング変数 x をいくつか除外することで、ゼロ除算を回避しました。ただし、それにはフィッティング関数の検討が必要です。いくつかのパッケージソリューションが存在するかどうか、私はまだ疑問に思っています。

4

0 に答える 0