Python scipy.polyfit() Examples

The following are 2 code examples of scipy.polyfit(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module scipy , or try the search function .
Example #1
Source File: testCore.py    From pyGSTi with Apache License 2.0 6 votes vote down vote up
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 ) 
Example #2
Source File: test_odepack.py    From Assimulo with GNU Lesser General Public License v3.0 5 votes vote down vote up
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)      
        """