2 つのモデル関数で 2 つのデータ セットを適合させようとしています。を使ってやってみましたsymfit
。ここにコード:
from symfit import variables, parameters, Fit, cos, sin, pi, sqrt, asin
import numpy as np
n0 = 1.5
data = np.genfromtxt('some data')
data = 1000 * data
pos=[]
for j in range( len(data) ):
pos.append( np.arcsin( np.sin( np.deg2rad( data[j,0]/1000 ) )/1.5 ) )
m1=[]
for j in range( len(data) ):
m1.append( data[j,1] )
p1=[]
for j in range( len(data) ):
p1.append(data[j,3])
zero=[]
for j in range( len(data) ):
zero.append(data[j,5])
y0, lam, d0, deltan, per = parameters('y0, lam, d0, deltan, per')
theta, rM1, rP1 = variables('theta, rM1, rP1')
model_dict={
rM1: y0+((pi*deltan*d0)/(lam*cos(theta)))**2.*sin(sqrt(((pi*deltan*d0)/(lam*cos(theta)))**2.+((pi*d0*(-asin(lam/(2*per*n0))-theta))/per)**2.))**2./(((pi*deltan*d0)/(lam*cos(theta)))**2.+((pi*d0*(-asin(lam/(2*per*n0))-theta))/per)**2.),
rP1: y0+((pi*deltan*d0)/(lam*cos(theta)))**2.*sin(sqrt(((pi*deltan*d0)/(lam*cos(theta)))**2.+((pi*d0*(asin(lam/(2*per*n0))-theta))/per)**2.))**2./(((pi*deltan*d0)/(lam*cos(theta)))**2.+((pi*d0*(asin(lam/(2*per*n0))-theta))/per)**2.)
}
fit = Fit(model_dict, theta=pos, rM1=m1, rP1=p1)
fit_result = fit.execute()
print(fit_result)
しかし、次のエラーが表示されます。
AttributeError: 'Variable' object has no attribute 'cos'
cos関数を削除すると、他の同様のエラーが発生sqrt
しsin
ます。コードの何が問題なのかわかりません!
PS:symfit.cos
などを使用した後、次の結果が得られます。
/anaconda2/lib/python2.7/site-packages/numpy/__init__.py:1: RuntimeWarning: invalid value encountered in arcsin
としても
/anaconda2/lib/python2.7/site-packages/numpy/__init__.py:1: RuntimeWarning: invalid value encountered in sqrt
出力は次のとおりです。
Parameter Value Standard Deviation
d0 1.727015e+00 nan
deltan 1.880867e-02 3.534201e-03
lam 3.890715e-01 nan
per 6.123022e-01 nan
y0 -1.686541e-03 4.810316e-03
Fitting status message: Desired error not necessarily achieved due to precision loss.
Number of iterations: 105
Regression Coefficient: 0.100163679536
標準偏差を追加すると、次のようになりました。
Parameter Value Standard Deviation
d0 nan nan
deltan nan nan
lam nan nan
per nan nan
y0 nan nan
Fitting status message: Desired error not necessarily achieved due to precision loss.
Number of iterations: 112
Regression Coefficient: nan