Esempio n. 1
0
 def test_0_linear(self):
     c0, c1, c00, c01, c10, sumsq = fit.linear(self.x, self.y)
     assert (Numeric.absolute(c0 - self.a) < self._eps)
     assert (Numeric.absolute(c1 - self.b) < self._eps)
     y, yerr = fit.est(1, c0, c1, c00, c01, c10)
     assert (Numeric.absolute(y - (self.a + self.b * 1)) < self._eps)
     assert (Numeric.absolute(yerr) < self._eps)
Esempio n. 2
0
 def test_0_linear(self):
     c0, c1, c00, c01, c10, sumsq =  fit.linear(self.x, self.y)
     assert(Numeric.absolute(c0 - self.a)<self._eps)
     assert(Numeric.absolute(c1 - self.b)<self._eps)
     y, yerr =  fit.est(1, c0, c1, c00, c01, c10)
     assert(Numeric.absolute(y - (self.a+self.b*1)) < self._eps)
     assert(Numeric.absolute(yerr) < self._eps)
Esempio n. 3
0
 def test_qawo(self):
     def f(x,y):
         return 1
     sys = integrate.gsl_function(f, None)
     table = integrate.qawo_table(1, 2*Numeric.pi, integrate.COSINE, 100)
     flag, result, error = integrate.qawo(sys, -Numeric.pi, 1e-8,  1e-8, 100, self.w, table)
     assert(Numeric.absolute(result) < 1e-7)
     assert(Numeric.absolute(error) < 1e-7)
Esempio n. 4
0
 def testQR_lssolve(self):
     A = array([[1, 2], [1, 3], [3, 4], [2, 5]], Float)
     b = array([1, 1, 1, 1], Float)
     (qr, tau) = QR_decomp(A)
     (x, res) = QR_lssolve(qr, tau, b)
     assert numx.absolute(x[0]) < 1e-7
     assert numx.absolute(x[1] - 0.25925) < 1e-4
     res2 = arrayCompare(res, [0.48148, 0.2222, -0.037037037, -0.296296], 4)
     self.failUnless(res2)
Esempio n. 5
0
 def testQR_lssolve(self):
     A = array([[1, 2], [1, 3], [3, 4], [2, 5]], Float)
     b = array([1, 1, 1, 1], Float)
     (qr, tau) = QR_decomp(A)
     (x, res) = QR_lssolve(qr, tau, b)
     assert (numx.absolute(x[0]) < 1e-7)
     assert (numx.absolute(x[1] - 0.25925) < 1e-4)
     res2 = arrayCompare(res, [0.48148, 0.2222, -0.037037037, -0.296296], 4)
     self.assertTrue(res2)
Esempio n. 6
0
 def test_0_qagiu(self):
     expected = 1./2.
     def f1(x,y):
         return 1. / (1.* x**2)
     
     sys = integrate.gsl_function(f1, None)
     flag, result, error = integrate.qagiu(sys, 2, 1e-8, 1e-8, 1000000, self.w)
     assert(Numeric.absolute(result - expected) < 1e-7)
     assert(Numeric.absolute(error) < 1e-7)
     self.w.get_size()
Esempio n. 7
0
 def test_1_qags(self):
     expected = -4.0
     def f(x, params):
         alpha = params
         return Numeric.log(alpha *x) / Numeric.sqrt(x)
     self.sys = integrate.gsl_function(f, 1)
     flag, result, error = integrate.qags(self.sys, 0, 1, 0, 1e-7, 1000,
                                          self.w, )
     assert(Numeric.absolute(result - expected) < 1e-7)
     assert(Numeric.absolute(error) < 1e-7)
     self.w.get_size()
Esempio n. 8
0
def display_results(title, result, error):
    print "%s ==================" % title
    print "result = % .6f" % result
    print "sigma  = % .6f" % error
    print "exact  = % .6f" % exact
    t = (result - exact, numx.absolute(result - exact) / error)
    print "error  = % .6f = %.1g sigma" % t
Esempio n. 9
0
    def test_qawf(self):
        def f2(x, y):
            return Numeric.sin(x) / x

        sys2 = integrate.gsl_function(f2, None)

        def f1(x, y):
            return 1 / x

        sys1 = integrate.gsl_function(f1, None)

        def f3(x, y):
            return 1 / -x

        sys3 = integrate.gsl_function(f3, None)

        pts = Numeric.array((-Numeric.pi, 0, Numeric.pi))
        flag, result1, error = integrate.qagp(sys2, pts, 1e-8, 1e-8, 100000,
                                              self.w)
        table1 = integrate.qawo_table(1, 100, integrate.SINE, 100)
        cyclew = integrate.workspace(1000000)
        flag, result2, error = integrate.qawf(sys1, Numeric.pi, 1e-8, 100,
                                              self.w, cyclew, table1)
        table2 = integrate.qawo_table(-1, 100, integrate.SINE, 100)
        flag, result3, error = integrate.qawf(sys3, Numeric.pi, 1e-8, 100,
                                              self.w, cyclew, table2)
        assert (Numeric.absolute(result1 + result2 + result3 - Numeric.pi) <
                1e-8)
Esempio n. 10
0
def display_results (title, result, error):
    print "%s ==================" %  title
    print "result = % .6f" % result
    print "sigma  = % .6f" % error
    print "exact  = % .6f" % exact
    t = (result - exact, numx.absolute(result - exact) / error)
    print "error  = % .6f = %.1g sigma" % t
Esempio n. 11
0
    def _CheckSinResult(self, f, l):
        a = numx.absolute(f)
        test = 0
        tmp1 = None
        tmp2 = None
        try:
            tmp1 = f[l].imag
            tmp2 = self.sin_n
            self.assertAlmostEqual(tmp1, tmp2, places=4)
            a[l] = 0

            n2 = self._GetN2()
            if (len(f) > n2 + 1):
                # Only for the complex transform
                tmp1 = f[self.n - l].imag
                tmp2 = self.sin_n_l
                self.assertAlmostEqual(tmp1, tmp2, places=4)
                a[self.n - l] = 0
            test = 1
        finally:
            if test == 0:
                print()
                print("Check Sin Result len(f) = %s, self.n/2 = %s", len(f),
                      self.n / 2)
                print(f[l])
                print("tmp1 = %s, tmp2 = %s" % (tmp1, tmp2))
                #print f[self.n-l]

        # Take the maximum
        test_val = self._CalculateAbsMax(a)
        self.assertAlmostEqual(1 + test_val, 1, places=4)
Esempio n. 12
0
 def _run(self, minimizer):
     m = 2.0
     a = 0.0
     b = 6.0
     m_expected = Numeric.pi
     minimizer.set(m, a, b)
     t1 = fn1(a, None)
     t2 = fn1(b, None)
     minimizer.set_with_values(m, fn1(m, None), a, t1, b, t2)
     #print "Testing minimizer ", minimizer.name()
     #print "%5s [%9s %9s]  %9s  %10s %9s" % ("iter", "upper", "lower", "min", "err", "err(est)")
     for iter in range(100):
         status = minimizer.iterate()
         a      = minimizer.x_lower()
         b      = minimizer.x_upper()
         m      = minimizer.minimum()
         status = minimize.test_interval(a, b, 0.001, 0)
         #if status == 0:
             #print "Converged: "
         #print "%5d [%.7f %.7f]  %.7f + % .6f % .6f" %(iter, a, b, m, m -m_expected, b - a)
         if status == 0:
             break
     else:
         raise ValueError, "Number of Iterations exceeded!"
     assert(Numeric.absolute(m - m_expected)<0.001)
Esempio n. 13
0
 def test_qng(self):
     def f1(x,y):
         return Numeric.sin(x)
     sys = integrate.gsl_function(f1, None)
     flag, result, error, method = integrate.qng(sys, 0, Numeric.pi, 1e-8, 1e-8)
     assert(Numeric.absolute(result - 2) < 1e-7)
     assert(error<1e-8)
Esempio n. 14
0
 def _run(self, minimizer):
     m = 2.0
     a = 0.0
     b = 6.0
     m_expected = Numeric.pi
     minimizer.set(m, a, b)
     t1 = fn1(a, None)
     t2 = fn1(b, None)
     minimizer.set_with_values(m, fn1(m, None), a, t1, b, t2)
     #print "Testing minimizer ", minimizer.name()
     #print "%5s [%9s %9s]  %9s  %10s %9s" % ("iter", "upper", "lower", "min", "err", "err(est)")
     for iter in range(100):
         status = minimizer.iterate()
         a      = minimizer.x_lower()
         b      = minimizer.x_upper()
         m      = minimizer.minimum()
         status = minimize.test_interval(a, b, 0.001, 0)
         #if status == 0:
             #print "Converged: "
         #print "%5d [%.7f %.7f]  %.7f + % .6f % .6f" %(iter, a, b, m, m -m_expected, b - a)
         if status == 0:
             break
     else:
         raise ValueError("Number of Iterations exceeded!")
     assert(Numeric.absolute(m - m_expected)<0.001)
Esempio n. 15
0
 def run_qag(self, method):
     def f1(x,y):
         return Numeric.sin(x)
     sys = integrate.gsl_function(f1, None)
     flag, result, error = integrate.qag(sys, 0, Numeric.pi, 1e-8, 1e-8, 1000, method, self.w)
     assert(Numeric.absolute(result - 2) < 1e-7)
     assert(error<1e-8)
Esempio n. 16
0
    def _CalculateAbsMax(self, an_array):
        tmp = an_array.ravel()
        result = tmp.max()
        result = numx.absolute(result)

        l_shape = len(result.shape)
        self.assertEqual(l_shape, 0, "max array shape too long")
        return result
Esempio n. 17
0
 def test_qagp(self):
     def f1(x,y):
         return x / x
     sys = integrate.gsl_function(f1, None)
     pts = Numeric.array((-1, 0, 1))
     flag, result, error = integrate.qagp(sys, pts, 1e-8, 1e-8, 100000, self.w)
     assert(Numeric.absolute(result - 2.) < 1e-3)
     assert(error<1e-8)
Esempio n. 18
0
    def _run(self, solver):
        tmp = Numeric.array((-10., -5.), Float)
        solver.set(tmp)
        for iter in range(100):
            status = solver.iterate()
            r = solver.root()
            x = solver.getx()
            f = solver.getf()
            status = multiroots.test_residual(f, 1e-7)
            if status == 0:
                break
        else:
            raise ValueError("Number of Iterations exceeded!")

        assert (Numeric.absolute(x[0] - 1) < 1e-6)
        assert (Numeric.absolute(x[1] - 1) < 1e-6)
        assert (Numeric.absolute(f[0]) < 1e-6)
        assert (Numeric.absolute(f[1]) < 1e-6)
Esempio n. 19
0
    def test_0_qagil(self):
        expected = 1. / 2.

        def f1(x, y):
            return 1. / (1. * x**2)

        sys = integrate.gsl_function(f1, None)
        test = 0
        try:
            flag, result, error = integrate.qagil(sys, -2, 1e-8, 1e-8, 1000000,
                                                  self.w)
            test = 1
        finally:
            if test == 0:
                print(integrate.qagil(sys, -2, 1e-8, 1e-8, 1000000, self.w))
        assert (Numeric.absolute(result - expected) < 1e-7)
        assert (Numeric.absolute(error) < 1e-7)
        self.w.get_size()
Esempio n. 20
0
 def _run(self, solver):
     tmp = Numeric.array((-10., -5.), Float)
     solver.set(tmp)
     for iter in range(100):
         status = solver.iterate()
         r = solver.root()
         x = solver.getx()
         f = solver.getf()
         status = multiroots.test_residual(f, 1e-7)
         if status == 0:
             break
     else:
         raise ValueError, "Number of Iterations exceeded!"
 
     assert(Numeric.absolute(x[0] - 1)<1e-6)
     assert(Numeric.absolute(x[1] - 1)<1e-6)
     assert(Numeric.absolute(f[0])<1e-6)
     assert(Numeric.absolute(f[1])<1e-6)
Esempio n. 21
0
 def _run(self, solver):
     #x = Numeric.array((1.0, .4, .1))
     x = Numeric.array((1.0, 0.0, 0.0))
     solver.set(x)
     #g.title('Start')
     #g.plot(Gnuplot.Data(self.data[0], self.data[1]),
     #       Gnuplot.Data(self.data[0], testfunc(self.data[0]),
     #                    with = 'line'),
     #       )
     #raw_input()
     #print "Testing solver ", solver.name() 
     #print "%5s %9s %9s  %9s  %10s" % ("iter", "A", "lambda", "b", "|f(x)|")
     for iter in range(20):
         status = solver.iterate()
         assert(status == 0 or status == -2)
         x  = solver.getx()
         dx = solver.getdx()
         f  = solver.getf()
         J  = solver.getJ()
         tdx = multifit_nlin.gradient(J, f)
         status = multifit_nlin.test_delta(dx, x, 1e-8, 1e-8)
         #status = multifit_nlin.test_gradient(dx, 1e-4)
         fn = Numeric.sqrt(Numeric.sum(f*f))
         #g.title('Iteration')
         if status == 0:
             break
         #print "%5d % .7f % .7f  % .7f  % .7f" %(iter, x[0], x[1], x[2], fn)
         #g.plot(Gnuplot.Data(self.data[0], self.data[1]),
         #       Gnuplot.Data(self.data[0],
         #                    testfunc(self.data[0], x[0], x[1], x[2]),
         #                    with = 'line', title='iteration ' + str(iter)),
         #       )
         #raw_input()
     else:
         raise ValueError, "Number of Iterations exceeded!"
     #print "Convereged :"        
     #print "%5d % .7f % .7f  %.7f  % .7f" %(iter, x[0], x[1], x[2], fn)
     assert(Numeric.absolute(x[0] - self.A) < _eps)
     assert(Numeric.absolute(x[1] - self.lambda_) < _eps)
     assert(Numeric.absolute(x[2] - self.b) < _eps)
     #J = solver.getJ()
     #print "shape = ", J.shape
     covar =  multifit_nlin.covar(solver.getJ(), 0.0)
Esempio n. 22
0
 def _run(self, solver):
     #x = Numeric.array((1.0, .4, .1))
     x = Numeric.array((1.0, 0.0, 0.0))
     solver.set(x)
     #g.title('Start')
     #g.plot(Gnuplot.Data(self.data[0], self.data[1]),
     #       Gnuplot.Data(self.data[0], testfunc(self.data[0]),
     #                    with = 'line'),
     #       )
     #raw_input()
     #print "Testing solver ", solver.name()
     #print "%5s %9s %9s  %9s  %10s" % ("iter", "A", "lambda", "b", "|f(x)|")
     for iter in range(20):
         status = solver.iterate()
         assert (status == 0 or status == -2)
         x = solver.getx()
         dx = solver.getdx()
         f = solver.getf()
         J = solver.getJ()
         tdx = multifit_nlin.gradient(J, f)
         status = multifit_nlin.test_delta(dx, x, 1e-8, 1e-8)
         #status = multifit_nlin.test_gradient(dx, 1e-4)
         fn = Numeric.sqrt(Numeric.sum(f * f))
         #g.title('Iteration')
         if status == 0:
             break
         #print "%5d % .7f % .7f  % .7f  % .7f" %(iter, x[0], x[1], x[2], fn)
         #g.plot(Gnuplot.Data(self.data[0], self.data[1]),
         #       Gnuplot.Data(self.data[0],
         #                    testfunc(self.data[0], x[0], x[1], x[2]),
         #                    with = 'line', title='iteration ' + str(iter)),
         #       )
         #raw_input()
     else:
         raise ValueError, "Number of Iterations exceeded!"
     #print "Convereged :"
     #print "%5d % .7f % .7f  %.7f  % .7f" %(iter, x[0], x[1], x[2], fn)
     assert (Numeric.absolute(x[0] - self.A) < _eps)
     assert (Numeric.absolute(x[1] - self.lambda_) < _eps)
     assert (Numeric.absolute(x[2] - self.b) < _eps)
     #J = solver.getJ()
     #print "shape = ", J.shape
     covar = multifit_nlin.covar(solver.getJ(), 0.0)
Esempio n. 23
0
 def _run(self, solver):
     tmp = Numeric.array((5., 7.), Float)
     solver.set(tmp, 0.01, 1e-4)
     #print "Testing solver ", solver.name() 
     #print "%5s %9s %9s  %9s %9s %9s" % ("iter", "x", "y", "f", "dx", "dy")
     for iter in range(200):
         status = solver.iterate()
         gradient = solver.gradient()
         x = solver.getx()
         f = solver.getf()
         status = multiminimize.test_gradient(gradient, 1e-3)
         if status == 0:
             break
         #print "%5d % .7f % .7f  % .7f % .7f % .7f" %(iter, x[0], x[1], f, gradient[0], gradient[1])
     else:
         raise ValueError, "Number of Iterations exceeded!"
     assert(Numeric.absolute(x[0] - 1)<1e-3)
     assert(Numeric.absolute(x[1] - 2)<1e-3)
     assert(Numeric.absolute(f - 30)<1e-3)
     assert(Numeric.absolute(gradient[0])<1e-3)
     assert(Numeric.absolute(gradient[1])<1e-3)
Esempio n. 24
0
 def _run(self, solver):
     x = Numeric.array((1.0, 0.0, 0.0))
     solver.set(x)
     for iter in range(20):
         status = solver.iterate()
         assert (status == 0 or status == -2)
         x = solver.getx()
         dx = solver.getdx()
         f = solver.getf()
         J = solver.getJ()
         tdx = multifit_nlin.gradient(J, f)
         status = multifit_nlin.test_delta(dx, x, 1e-8, 1e-8)
         fn = Numeric.sqrt(Numeric.sum(f * f))
         if status == 0:
             break
     else:
         raise ValueError("Number of Iterations exceeded!")
     assert (Numeric.absolute(x[0] - self.A) < _eps)
     assert (Numeric.absolute(x[1] - self.lambda_) < _eps)
     assert (Numeric.absolute(x[2] - self.b) < _eps)
     covar = multifit_nlin.covar(solver.getJ(), 0.0)
Esempio n. 25
0
def run_vegas():
    s = monte.vegas(3)
    s.init()

    res, err = s.integrate(G, xl, xu, 10000, r)
    display_results ("vegas warm-up", res, err)

    print "converging..."
    while 1:
        res, err = s.integrate(G, xl, xu, calls/5, r)
        chisq = s.get_chisq()
        print "result = % .6f sigma = % .6f chisq/dof = %.1f" % (res, err, chisq);
        if (numx.absolute(chisq - 1.0) <= 0.5):    
            display_results("vegas final", res, err)
            break
Esempio n. 26
0
def run_vegas():
    s = monte.vegas(3)
    s.init()

    res, err = s.integrate(G, xl, xu, 10000, r)
    display_results("vegas warm-up", res, err)

    print "converging..."
    while 1:
        res, err = s.integrate(G, xl, xu, calls / 5, r)
        chisq = s.get_chisq()
        print "result = % .6f sigma = % .6f chisq/dof = %.1f" % (res, err, chisq)
        if numx.absolute(chisq - 1.0) <= 0.5:
            display_results("vegas final", res, err)
            break
Esempio n. 27
0
 def _run(self, solver):
     solver.set(0.0, 5.0)
     iter = 0
     r_expected = Numeric.sqrt(5.0)
     #print "Testing solver ", solver.name()
     #print "%5s [%9s %9s]  %9s  %10s %9s" % ("iter", "upper", "lower", "root", "err", "err(est)")
     for iter in range(100):
         status = solver.iterate()
         x_lo = solver.x_lower()
         x_up = solver.x_upper()
         status = roots.test_interval(x_lo, x_up, 0, 0.001)
         r = solver.root()
         if status == 0:
             break
     else:
         raise ValueError("Exeeded maximum number of iterations!")
     assert (Numeric.absolute(r - r_expected) < _eps)
Esempio n. 28
0
    def _CheckCosResult(self, f, l):
        # Take all data
        a = numx.absolute(f)

        self.assertAlmostEqual(f[l].real, self.n / 2, places=4)
        stmp = ["%s" % a[l]]
        a[l] = 0
        stmp.append("should be zero %s" % (a[l], ))
        n2 = self._GetN2()
        if (len(f) > n2 + 1):
            # Only for the complex transform
            self.assertAlmostEqual(f[self.n - l].real, self.n / 2, places=4)
            a[self.n - l] = 0
        # Take the maximum
        test = 0
        test_val = self._CalculateAbsMax(a)
        self.assertAlmostEqual(1 + test_val, 1, places=4)
Esempio n. 29
0
 def _run(self, solver):
     solver.set(0.0, 5.0)
     iter = 0
     r_expected = Numeric.sqrt(5.0)
     #print "Testing solver ", solver.name() 
     #print "%5s [%9s %9s]  %9s  %10s %9s" % ("iter", "upper", "lower", "root", "err", "err(est)")
     for iter in range(100):           
         status = solver.iterate()
         x_lo = solver.x_lower()
         x_up = solver.x_upper()
         status = roots.test_interval(x_lo, x_up, 0, 0.001)
         r = solver.root()
         if status == 0:
             break
     else:
         raise ValueError, "Exeeded maximum number of iterations!"
     assert(Numeric.absolute(r-r_expected) < _eps)
Esempio n. 30
0
def run(array):
    # Initalise the wavelet and the workspace
    w = wavelet.daubechies(4)
    ws = wavelet.workspace(len(array))
    
    # Transform forward
    result = w.transform_forward(array, ws)

    # Select the largest 20 coefficients
    abscoeff = numx.absolute(result)
    indices  = numx.argsort(abscoeff) # ascending order

    tmp = numx.zeros(result.shape, numx.float_)
    for i in indices[-20:]:
        tmp[i] = result[i] # Set all others to zero

    # And back
    result2 = w.transform_inverse(tmp, ws)
Esempio n. 31
0
def run(array):
    # Initalise the wavelet and the workspace
    w = wavelet.daubechies(4)
    ws = wavelet.workspace(len(array))

    # Transform forward
    result = w.transform_forward(array, ws)

    # Select the largest 20 coefficients
    abscoeff = numx.absolute(result)
    indices = numx.argsort(abscoeff)  # ascending order

    tmp = numx.zeros(result.shape, numx.float_)
    for i in indices[-20:]:
        tmp[i] = result[i]  # Set all others to zero

    # And back
    result2 = w.transform_inverse(tmp, ws)
Esempio n. 32
0
 def test_qawf(self):
     def f2(x,y):
         return Numeric.sin(x) / x
     sys2 = integrate.gsl_function(f2, None)
     def f1(x,y):
         return 1 / x        
     sys1 = integrate.gsl_function(f1, None)
     def f3(x,y):
         return 1 / -x        
     sys3 = integrate.gsl_function(f3, None)
     
     pts = Numeric.array((-Numeric.pi, 0, Numeric.pi))
     flag, result1, error = integrate.qagp(sys2, pts, 1e-8, 1e-8, 100000, self.w)
     table1 = integrate.qawo_table(1, 100, integrate.SINE, 100)        
     cyclew = integrate.workspace(1000000)
     flag, result2, error = integrate.qawf(sys1, Numeric.pi, 1e-8,  100, self.w, cyclew, table1)
     table2 = integrate.qawo_table(-1, 100, integrate.SINE, 100)        
     flag, result3, error = integrate.qawf(sys3, Numeric.pi, 1e-8,  100, self.w, cyclew, table2)
     assert(Numeric.absolute(result1+result2+result3 - Numeric.pi) < 1e-8)
Esempio n. 33
0
 def _CheckCosResult(self, f, l):
     # Take all data
     a = numx.absolute(f)
     assert (fcmp(f[l].real, self.n / 2, self._eps) == 0)
     stmp = ["%s" % a[l]]
     a[l] = 0
     stmp.append("should be zero %s" % (a[l], ))
     if (len(f) > self.n / 2 + 1):
         # Only for the complex transform
         assert (fcmp(f[self.n - l].real, self.n / 2, self._eps) == 0)
         a[self.n - l] = 0
     # Take the maximum
     test = 0
     try:
         assert (MLab.max(a) < self._eps)
         test = 1
     finally:
         if test == 0:
             print "Check Cos Result",
             printvec(a, 0, self._eps)
             print string.join(stmp)
Esempio n. 34
0
 def _CheckCosResult(self, f, l):
     # Take all data
     a = numx.absolute(f)
     assert(fcmp(f[l].real, self.n/2, self._eps) == 0)
     stmp = ["%s" % a[l]]
     a[l] = 0
     stmp.append("should be zero %s" % (a[l],))
     if(len(f) > self.n/2 + 1):
             # Only for the complex transform
             assert(fcmp(f[self.n-l].real, self.n/2, self._eps) == 0)
             a[self.n-l] = 0
     # Take the maximum
     test = 0
     try:
         assert(MLab.max(a) < self._eps)
         test = 1
     finally:
         if test == 0:
             print "Check Cos Result",
             printvec(a, 0, self._eps)
             print string.join(stmp)
Esempio n. 35
0
 def _run(self, solver):
     x = 5.0
     solver.set(x)
     r_expected = Numeric.sqrt(5.0)
     #print "Testing solver ", solver.name() 
     #print "%5s %9s  %10s %9s" % ("iter", "root", "err", "err(est)")
     ok = 1
     for iter in range(10):
         status = solver.iterate()
         x0 = x
         x = solver.root()
         status = roots.test_delta(x, x0, 0.0, 1e-3)
         r = solver.root()
         if status == 0:
             #print "Convereged :"
             ok = 0
         #print "%5d  %.7f  % .6f % .6f" %(iter, r, r -r_expected, x - x0)
         if ok == 0:
             break
     else:
         raise ValueError, "Exeeded maximum number of iterations!"
     assert(Numeric.absolute(r-r_expected) < _eps)
Esempio n. 36
0
 def _run(self, solver):
     x = 5.0
     solver.set(x)
     r_expected = Numeric.sqrt(5.0)
     #print "Testing solver ", solver.name()
     #print "%5s %9s  %10s %9s" % ("iter", "root", "err", "err(est)")
     ok = 1
     for iter in range(10):
         status = solver.iterate()
         x0 = x
         x = solver.root()
         status = roots.test_delta(x, x0, 0.0, 1e-3)
         r = solver.root()
         if status == 0:
             #print "Convereged :"
             ok = 0
         #print "%5d  %.7f  % .6f % .6f" %(iter, r, r -r_expected, x - x0)
         if ok == 0:
             break
     else:
         raise ValueError("Exeeded maximum number of iterations!")
     assert (Numeric.absolute(r - r_expected) < _eps)
Esempio n. 37
0
    def _CheckSinResult(self, f, l):
        a = numx.absolute(f)
        test = 0
        tmp1 = None
        tmp2 = None
        try:
            tmp1 = f[l].imag
            tmp2 = self.sin_n
            flag = fcmp(tmp1, tmp2, self._eps)
            assert (flag == 0)
            a[l] = 0
            if (len(f) > self.n / 2 + 1):
                # Only for the complex transform
                tmp1 = f[self.n - l].imag
                tmp2 = self.sin_n_l
                flag = fcmp(tmp1, tmp2, self._eps)
                assert (flag == 0)
                a[self.n - l] = 0
            test = 1
        finally:
            if test == 0:
                print
                print "Check Sin Result len(f) = %s, self.n/2 = %s", len(
                    f), self.n / 2
                print f[l]
                print "tmp1 = %s, tmp2 = %s, flag = %s" % (tmp1, tmp2, flag)
                #print f[self.n-l]

        # Take the maximum
        test = 0
        try:
            assert (MLab.max(a) < self._eps)
            test = 1
        finally:
            if test == 0:
                printvec(a, 0, self._eps)
                print MLab.max(a)
Esempio n. 38
0
 def _CheckSinResult(self, f, l):
     a = numx.absolute(f)
     test = 0
     tmp1 = None
     tmp2 = None
     try:
         tmp1 = f[l].imag
         tmp2 = self.sin_n
         flag = fcmp(tmp1, tmp2, self._eps)
         assert(flag == 0)
         a[l] = 0
         if(len(f) > self.n/2 + 1):
             # Only for the complex transform
             tmp1 = f[self.n-l].imag
             tmp2 = self.sin_n_l
             flag = fcmp(tmp1, tmp2, self._eps)
             assert(flag == 0)
             a[self.n-l] = 0
         test = 1
     finally:
         if test == 0:
             print 
             print "Check Sin Result len(f) = %s, self.n/2 = %s", len(f), self.n/2                
             print f[l]
             print "tmp1 = %s, tmp2 = %s, flag = %s" % (tmp1, tmp2, flag)
             #print f[self.n-l]
             
     # Take the maximum
     test = 0
     try:
         assert(MLab.max(a) < self._eps)
         test = 1
     finally:
         if test == 0:
             printvec(a, 0, self._eps)
             print MLab.max(a)
Esempio n. 39
0
 def test_2_poly_dd(self):    
     assert(Numeric.absolute(self.dd.eval(Numeric.pi)) < _eps)
Esempio n. 40
0
#!/usr/bin/env python
import pygsl._numobj as Numeric
import pygsl.monte as monte
import pygsl.rng

import unittest


def g(k, params):
    return k[0]


sys = monte.gsl_monte_function(g, None, 1)
r = pygsl.rng.mt19937_1999()
xl = [
    0,
]
xu = [
    1,
]
exact = 0.5
accepted_error = 0.2
s = monte.plain(1)
s.init()
calls = 100
res, err = s.integrate(sys, xl, xu, calls, r)
assert (Numeric.absolute(res - exact) < accepted_error)
Esempio n. 41
0
 def test_3_poly_dd(self):    
     assert(Numeric.absolute(self.dd.eval(Numeric.pi/2)-1)  < _eps)
Esempio n. 42
0
 def test_wlinear(self):
     c, cov, chisq = multifit.wlinear(self.X, self.w, self.y, self.ws)
     assert(Numeric.absolute(c[0] - self.a) < self._eps)
     assert(Numeric.absolute(c[1] - self.b) < self._eps)
Esempio n. 43
0
 def test_1_wlinear(self):
     c1,  c11, chisq = fit.wmul(self.x, self.w, self.y)
     assert(Numeric.absolute(c1 - self.b)<self._eps)
     y, yerr =  fit.mul_est(1, c1, c11)
     assert(Numeric.absolute(y - (self.a+self.b*1)) < self._eps)
Esempio n. 44
0
 def test_0_linear(self):
     c1, c11, sumsq =  fit.mul(self.x, self.y)
     assert(Numeric.absolute(c1 - self.b)<self._eps)
     y, yerr =  fit.mul_est(1, c1, c11)
     assert(Numeric.absolute(y - (self.a+self.b*1)) < self._eps)
     assert(Numeric.absolute(yerr) < self._eps)
Esempio n. 45
0
 def test_2_poly_dd(self):    
     assert(Numeric.absolute(self.dd.eval(Numeric.pi)) < _eps)
Esempio n. 46
0
#!/usr/bin/env python
import pygsl._numobj as Numeric
import pygsl.monte as monte
import pygsl.rng

import unittest

def g(k, params):
    return k[0]

sys =  monte.gsl_monte_function(g, None, 1)
r = pygsl.rng.mt19937_1999()
xl = [ 0, ]
xu = [ 1, ]
exact = 0.5
accepted_error = 0.2
s = monte.Plain(1)
s.init()
calls = 100
status, res, err = s.integrate(sys, xl, xu, calls, r)
assert(Numeric.absolute(res - exact) < accepted_error)


Esempio n. 47
0
 def test_3_poly_dd(self):    
     assert(Numeric.absolute(self.dd.eval(Numeric.pi/2)-1)  < _eps)
Esempio n. 48
0
 def testRun(self):
     self._init_impl()
     calls = 100
     res, err = self.s.integrate(self.sys, self.xl, self.xu, calls, self.r)
     assert (Numeric.absolute(res - self.exact) < self.accepted_error)
Esempio n. 49
0
    def testRun(self):
        self._init_impl()
        calls = 100
        res, err = self.s.integrate(self.sys, self.xl, self.xu, calls,
				    self.r)
        assert(Numeric.absolute(res - self.exact) < self.accepted_error)
Esempio n. 50
0
    def test_result(self):
        calls = 100
	res, err = self.s.integrate(self.sys, self.xl, self.xu, calls,
                                       self.r)
        assert(type(self.s.get_result()) == types.FloatType)
        assert(Numeric.absolute(self.s.get_result() - res) < 0.01)
Esempio n. 51
0
 def Metric(self, outer):     
     return numx.absolute(self._data - outher.GetData())
Esempio n. 52
0
 def test_result(self):
     calls = 100
     res, err = self.s.integrate(self.sys, self.xl, self.xu, calls, self.r)
     assert (type(self.s.get_result()) == types.FloatType)
     assert (Numeric.absolute(self.s.get_result() - res) < 0.01)