本文整理匯總了Python中scipy.polyfit方法的典型用法代碼示例。如果您正苦於以下問題:Python scipy.polyfit方法的具體用法?Python scipy.polyfit怎麽用?Python scipy.polyfit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scipy
的用法示例。
在下文中一共展示了scipy.polyfit方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_LGST_1overSqrtN_dependence
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import polyfit [as 別名]
def test_LGST_1overSqrtN_dependence(self):
my_datagen_gateset = self.model.depolarize(op_noise=0.05, spam_noise=0)
# !!don't depolarize spam or 1/sqrt(N) dependence saturates!!
nSamplesList = np.array([ 16, 128, 1024, 8192 ])
diffs = []
for nSamples in nSamplesList:
ds = pygsti.construction.generate_fake_data(my_datagen_gateset, self.lgstStrings, nSamples,
sampleError='binomial', seed=100)
mdl_lgst = pygsti.do_lgst(ds, self.fiducials, self.fiducials, self.model, svdTruncateTo=4, verbosity=0)
mdl_lgst_go = pygsti.gaugeopt_to_target(mdl_lgst, my_datagen_gateset, {'spam':1.0, 'gate': 1.0}, checkJac=True)
diffs.append( my_datagen_gateset.frobeniusdist(mdl_lgst_go) )
diffs = np.array(diffs, 'd')
a, b = polyfit(np.log10(nSamplesList), np.log10(diffs), deg=1)
#print "\n",nSamplesList; print diffs; print a #DEBUG
self.assertLess( a+0.5, 0.05 )
示例2: test_rkstarter
# 需要導入模塊: import scipy [as 別名]
# 或者: from scipy import polyfit [as 別名]
def test_rkstarter(self):
"""
This test checks the correctness of the Nordsieck array generated
from a RK starter
"""
pass
"""
A=N.array([[0.,1.],[-4.,0.]])
def f(t,x,sw0):
return N.dot(A,N.array(x))
H = 1.e-8
# Compute the exact solution at h=0,H/4,H/2,3H/4,H
T=N.array([0.,H/4.,H/2.,3./4.*H,H])
y0=N.array([1.,0.])
from scipy.linalg import expm
exact=N.array([N.dot(expm(A*t),y0) for t in T])
#polynomial interpolation
from scipy import polyfit
coeff = polyfit(T,exact,4)
d1coeff=N.array([4,3,2,1]).reshape(-1,1)*coeff[:-1,:]
d2coeff=N.array([3,2,1]).reshape(-1,1)*d1coeff[:-1,:]
d3coeff=N.array([2,1]).reshape(-1,1)*d2coeff[:-1,:]
d4coeff=N.array([1]).reshape(-1,1)*d3coeff[:-1,:]
h=H/4.
nordsieck_at_0=N.array([coeff[-1,:],h*d1coeff[-1,:],h**2/2.*d2coeff[-1,:],
h**3/6.*d3coeff[-1,:],h**4/24.*d4coeff[-1,:]])
rkNordsieck=odepack.RKStarterNordsieck(f,H)
computed=rkNordsieck(0,y0)
numpy.testing.assert_allclose(computed[1], nordsieck_at_0, atol=H/100., verbose=True)
"""