昨日 Python を使い始めたばかりですが、scipy.integrate.odeint.
関数を定義しました
def SIR(x, t, beta, gamma, mu, M):
numpy.arrayオブジェクトx、t、およびM;を取ります。およびスカラー浮動小数点数beta、gamma、およびmu。
Mサイズです(60,60)が、問題ないと思います。
xとtはどちらもシングルトンではなく、 x.shapebeing(180,)とt.shapebeing(5000,)です。私はそれらがそれぞれ形状を持つように単一の次元を与えようとしました(180,1)が(5000,1)、それでも同じエラーが発生します:
In [1]: run measles_age.py
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/IPython/utils/py3compat.py in execfile(fname, *where)
173 else:
174 filename = fname
--> 175 __builtin__.execfile(filename, *where)
/Users/qcaudron/Documents/SIR/measles_age.py in <module>()
111
112
--> 113 x = integrate.odeint(SIR, x0, t, args=(beta, gamma, mu, M));
114
115 # plot(t, x);
/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/scipy/integrate/odepack.py in odeint(func, y0, t, args, Dfun, col_deriv, full_output, ml, mu, rtol, atol, tcrit, h0, hmax, hmin, ixpr, mxstep, mxhnil, mxordn, mxords, printmessg)
141 output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu,
142 full_output, rtol, atol, tcrit, h0, hmax, hmin,
--> 143 ixpr, mxstep, mxhnil, mxordn, mxords)
144 if output[-1] < 0:
145 print _msgs[output[-1]]
SIRreturn だけの場合でもこのエラーが発生し、すべての引数をそれとxは別に削除すると、次のようになります。xt
def SIR(x, t):
return x;
ご覧のとおり、エラーの原因となっている行は
x = integrate.odeint(SIR, x0, t, args=(beta, gamma, mu, M));
編集 :
メソッドの完全なコードを追加するように求められましたSIR。比較的長いので、完全な .py スクリプトをペーストビンにドロップしました:
http://pastebin.com/RphJbCHN
再度、感謝します。