本文整理汇总了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)
"""