def sample_combination(num_imgs):
    if CHOOSE_UNIFORM:
        return sample_convex_combinations.sample(num_imgs)
    else:
        result = [0] * num_imgs
        result[random.randrange(num_imgs)] = 1
        return result
Beispiel #2
0
 def test_dimensions(self):
     for d in [1, 2, 3, 5, 10, 12, 19, 30]:
         with self.subTest(d=d):
             actual = sample_convex_combinations.sample(d, rng=dummy_rng)
             self.assertEqual(d, len(actual), actual)
             self.assertTrue(all(0.0 <= e <= 1.0 for e in actual), actual)
             self.assertAlmostEqual(1, sum(actual), actual)
Beispiel #3
0
 def test_dimensions(self):
     for d in [1, 2, 3, 5, 10, 12, 19, 30]:
         with self.subTest(d=d):
             actual = sample_convex_combinations.sample(d, span_origin=True)
             self.assertEqual(d, len(actual), actual)
             self.assertTrue(all(0.0 <= e <= 1.0 for e in actual), actual)
             # The following will fail 0.0002% of the time for no reason.
             # TODO: Find a better way to deal with it.
             self.assertTrue(0.000001 <= sum(actual) <= 0.999999, actual)
def gather(d, span_origin, asserter):
    actual = sample_convex_combinations.sample(d, span_origin=span_origin)

    # Various sanity-checks:
    asserter.assertEqual(d, len(actual), actual)
    asserter.assertTrue(all(0.0 <= e <= 1.0 for e in actual), actual)
    if span_origin:
        # The following will fail 0.0002% of the time for no reason.
        # TODO: Find a better way to deal with it.
        asserter.assertTrue(
            GATHER_FALSE_POSITIVE <= sum(actual) <= 1 - GATHER_FALSE_POSITIVE,
            actual)
    else:
        asserter.assertAlmostEqual(1.0, sum(actual), actual)

    return actual
Beispiel #5
0
 def test_call(self):
     self.assertEqual(3, len(sample_convex_combinations.sample(3)))
Beispiel #6
0
 def test_call(self):
     self.assertEqual(
         3, len(sample_convex_combinations.sample(3, span_origin=True)))