Ejemplo n.º 1
0
    def test_naive(self):
        np.random.seed(1)
        for _ in range(0, TEST_REPEATS):
            v1 = np.random.rand(TEST_LENGTH)
            v2 = np.random.rand(TEST_LENGTH)

            with timer('numpy'):
                real = np.convolve(v1, v2)
            with timer('log'):
                hopeful = np.exp(naive.convolve_naive(np.log(v1), np.log(v2)))
            self.assertTrue(np.allclose(real, hopeful))
Ejemplo n.º 2
0
    def test_naive(self):
        np.random.seed(1)
        for _ in range(0, TEST_REPEATS):
            v1 = np.random.rand(TEST_LENGTH)
            v2 = np.random.rand(TEST_LENGTH)

            with timer('numpy'):
                real = np.convolve(v1, v2)
            with timer('log'):
                hopeful = np.exp(naive.convolve_naive(np.log(v1), np.log(v2)))
            self.assertTrue(np.allclose(real, hopeful))
Ejemplo n.º 3
0
def sisfft_(self, beta, s0, L):
    np.random.seed(1)
    for _ in range(0, TEST_REPEATS):
        v = np.random.rand(TEST_LENGTH)
        v /= v.sum()

        with timer('naive'):
            real = utils.log_sum(log_power_naive(np.log(v), L)[s0:])
        with timer('sisfft'):
            hopeful = sisfft.pvalue(np.log(v), s0, L, beta)
        logging.debug('true pvalue %.20f', real)
        abs_diff = utils.logsubexp(max(real, hopeful), min(real, hopeful))
        threshold = np.log(beta) + real
        self.assertLessEqual(abs_diff, threshold,
                             '%s isn\'t close to %s (distance %s, should be less than %s)' \
                             % (hopeful, real, abs_diff, threshold))
Ejemplo n.º 4
0
def sisfft_(self, beta, s0, L):
    np.random.seed(1)
    for _ in range(0, TEST_REPEATS):
        v = np.random.rand(TEST_LENGTH)
        v /= v.sum()

        with timer('naive'):
            real = utils.log_sum(log_power_naive(np.log(v), L)[s0:])
        with timer('sisfft'):
            hopeful = sisfft.pvalue(np.log(v), s0, L, beta)
        logging.debug('true pvalue %.20f', real)
        abs_diff = utils.logsubexp(max(real, hopeful), min(real, hopeful))
        threshold = np.log(beta) + real
        self.assertLessEqual(abs_diff, threshold,
                             '%s isn\'t close to %s (distance %s, should be less than %s)' \
                             % (hopeful, real, abs_diff, threshold))
Ejemplo n.º 5
0
def afftc_square_(self, beta, delta):
    np.random.seed(1)
    for _ in range(0, TEST_REPEATS):
        v = np.random.rand(TEST_LENGTH)
        v /= v.sum()

        with timer('naive'):
            real = np.convolve(v, v)
        with timer('afftc'):
            hopeful = np.exp(afftc.convolve_square(np.log(v), beta, delta))

        lower = (1 - beta) * real - 2 * delta
        upper = (1 + beta) * real
        between = (lower <= hopeful) & (hopeful <= upper)
        not_between = np.invert(between)
        self.assertTrue(between.all(),
                        '%s\n%s' % (hopeful[not_between], real[not_between]))
Ejemplo n.º 6
0
def afftc_square_(self, beta, delta):
    np.random.seed(1)
    for _ in range(0, TEST_REPEATS):
        v = np.random.rand(TEST_LENGTH)
        v /= v.sum()

        with timer('naive'):
            real = np.convolve(v, v)
        with timer('afftc'):
            hopeful = np.exp(afftc.convolve_square(np.log(v), beta, delta))

        lower = (1 - beta) * real - 2 * delta
        upper = (1 + beta) * real
        between = (lower <= hopeful) & (hopeful <= upper)
        not_between = np.invert(between)
        self.assertTrue(between.all(),
                        '%s\n%s' % (hopeful[not_between], real[not_between]))
Ejemplo n.º 7
0
def afftc_no_lower_bound_(self, beta):
    np.random.seed(1)
    for _ in range(0, TEST_REPEATS):
        v1 = np.random.rand(TEST_LENGTH)
        v1 /= v1.sum()
        v2 = np.random.rand(TEST_LENGTH)
        v2 /= v2.sum()

        with timer('naive'):
            real = np.convolve(v1, v2)
        with timer('afftc'):
            hopeful = np.exp(afftc.convolve(np.log(v1), np.log(v2), beta, None))

        lower = (1 - beta) * real
        upper = (1 + beta) * real
        between = (lower <= hopeful) & (hopeful <= upper)
        not_between = np.invert(between)
        self.assertTrue(between.all(),
                        '%s\n%s' % (hopeful[not_between], real[not_between]))
Ejemplo n.º 8
0
def conv_power_(self, beta, delta, L):
    np.random.seed(1)
    for _ in range(0, TEST_REPEATS):
        v = np.random.rand(TEST_LENGTH)
        v /= v.sum()

        with timer('naive'):
            real = power_naive(v, L)
        with timer('sisfft'):
            hopeful = np.exp(sisfft.conv_power(np.log(v), L, beta, delta))

        lower = (1 - beta) * real - delta
        upper = (1 + beta) * real
        between = (lower <= hopeful) & (hopeful <= upper)
        not_between = np.invert(between)
        self.assertTrue(
            between.all(), '%s\n%s\n%s\n%s\n%s' %
            (len(not_between), hopeful[not_between], lower[not_between],
             real[not_between], upper[not_between]))
Ejemplo n.º 9
0
def afftc_no_lower_bound_(self, beta):
    np.random.seed(1)
    for _ in range(0, TEST_REPEATS):
        v1 = np.random.rand(TEST_LENGTH)
        v1 /= v1.sum()
        v2 = np.random.rand(TEST_LENGTH)
        v2 /= v2.sum()

        with timer('naive'):
            real = np.convolve(v1, v2)
        with timer('afftc'):
            hopeful = np.exp(afftc.convolve(np.log(v1), np.log(v2), beta,
                                            None))

        lower = (1 - beta) * real
        upper = (1 + beta) * real
        between = (lower <= hopeful) & (hopeful <= upper)
        not_between = np.invert(between)
        self.assertTrue(between.all(),
                        '%s\n%s' % (hopeful[not_between], real[not_between]))
Ejemplo n.º 10
0
def conv_power_(self, beta, delta, L):
    np.random.seed(1)
    for _ in range(0, TEST_REPEATS):
        v = np.random.rand(TEST_LENGTH)
        v /= v.sum()

        with timer('naive'):
            real = power_naive(v, L)
        with timer('sisfft'):
            hopeful = np.exp(sisfft.conv_power(np.log(v), L, beta, delta))

        lower = (1 - beta) * real - delta
        upper = (1 + beta) * real
        between = (lower <= hopeful) & (hopeful <= upper)
        not_between = np.invert(between)
        self.assertTrue(between.all(),
        '%s\n%s\n%s\n%s\n%s' % (
                            len(not_between),
                            hopeful[not_between],
                            lower[not_between], real[not_between], upper[not_between]))