Exemplo n.º 1
0
def test_integration():
    """Test for polynomial interation
    """

    BP = Ostap.Math.Bernstein

    b = BP(5, 0, 2)
    for i in b:
        b[i] = random.uniform(-10, 10)

    from ostap.math.integral import romberg

    for i in range(500):

        ##  note:  x1 <  x2
        x1 = random.uniform(b.xmin(), b.xmax())
        x2 = random.uniform(x1, b.xmax())

        i1 = b.integral(x1, x2)
        i2 = romberg(b, x1, x2)

        dd = (i1 - i2)
        ds = (abs(i1) + abs(i2))
        if abs(dd) > ds * 1.e-7:
            raise ValueError('Invalid Integrals!')

    logger.info('Integration     is  OK')
Exemplo n.º 2
0
def test_integration():
    """Test for polynomial interation
    """

    logger = getLogger("test_integration")

    BP = Ostap.Math.Bernstein

    b = BP(5, 0, 2)
    for i in b:
        b[i] = random.uniform(-1, 50)

    from ostap.math.integral import romberg

    xmax = b.xmin() + 0.9 * (b.xmax() - b.xmin())
    for i in range(500):

        ##  note:  x1 <  x2
        x1 = random.uniform(b.xmin(), xmax)
        x2 = random.uniform(x1, b.xmax())

        i1 = b.integral(x1, x2)
        i2 = romberg(b, x1, x2)

        dd = (i1 - i2)
        ds = (abs(i1) + abs(i2))
        if 0 < ds < abs(dd) * 10**6:
            raise ValueError('Invalid Integrals! %s  %s' % (dd, ds * 1.e-6))

    logger.info('Integration     is OK')
Exemplo n.º 3
0
def test_integral():

    from math import sin, cos, exp, log, pi, e

    from ostap.math.integral import integral, romberg
    funcs = [(sin, 0, pi, 2), (cos, 0, pi, 0), (exp, 0, 1, e - 1),
             (log, 1.e-50, 1, -1)]

    for entry in funcs:

        args = entry[:3]
        vi = integral(*entry[:3], err=True)
        vr = romberg(*entry[:3], err=True, maxdepth=100)

        value = entry[3]
        func = 'int(%s,%g,%g)' % (entry[0].__name__, entry[1], entry[2])
        logger.info('%20s: I        %-20s %-20s' % (func, vi, vr))
        logger.info('%20s: Delta    %-20s %-20s' %
                    (func, vi - value, vr - value))
        logger.info('%20s: Delta/I  %-20s %-20s' % (func,
                                                    (vi - value) / vi.error(),
                                                    (vr - value) / vr.error()))