Example #1
0
 def testUnscrambledHighDimSobol(self):
     engine = SobolEngine(1111)
     count1 = Counter(engine.draw().flatten().tolist())
     count2 = Counter(engine.draw().flatten().tolist())
     count3 = Counter(engine.draw().flatten().tolist())
     self.assertEqual(count1, Counter({0.5: 1111}))
     self.assertEqual(count2, Counter({0.25: 580, 0.75: 531}))
     self.assertEqual(count3, Counter({0.25: 531, 0.75: 580}))
Example #2
0
 def testScrambledDistributionSobol(self):
     engine = SobolEngine(10, scramble=True, seed=12345)
     draws = engine.draw(1000)
     self.assertTrue(
         np.allclose(np.mean(draws, axis=0), np.repeat(0.5, 10), atol=0.01))
     self.assertTrue(
         np.allclose(np.percentile(draws, 25, axis=0),
                     np.repeat(0.25, 10),
                     atol=0.01))
     self.assertTrue(
         np.allclose(np.percentile(draws, 75, axis=0),
                     np.repeat(0.75, 10),
                     atol=0.01))
Example #3
0
    def init_engine(self, n_tunable_features: int) -> SobolEngine:
        """Initialize singleton SobolEngine, only on gen.

        Args:
            n_tunable_features: The number of features which can be
                searched over.

        Returns:
            SobolEngine, which can generate Sobol points.

        """
        if not self._engine:
            self._engine = SobolEngine(  # pyre-ignore: .pyx not parsed properly.
                dimen=n_tunable_features,
                scramble=self.scramble,
                seed=self.seed).fast_forward(self.init_position)
        return self._engine
Example #4
0
    def testUnscrambledFastForwardAndResetSobol(self):
        engine_unscrambled_3d = SobolEngine(3).fast_forward(5)
        draws = engine_unscrambled_3d.draw(5)
        self.assertTrue(
            np.array_equal(self.draws_unscrambled_3d[5:10, :], draws))

        engine_unscrambled_3d.reset()
        even_draws = []
        for i in range(10):
            if i % 2 == 0:
                even_draws.append(engine_unscrambled_3d.draw())
            else:
                engine_unscrambled_3d.fast_forward(1)
        self.assertTrue(
            np.array_equal(
                self.draws_unscrambled_3d[[i for i in range(10)
                                           if i % 2 == 0], ],
                np.vstack(even_draws),
            ))
Example #5
0
 def testUnscrambledSobolBounds(self):
     engine = SobolEngine(1111)
     draws = engine.draw(1000)
     self.assertTrue(np.all(draws >= 0))
     self.assertTrue(np.all(draws <= 1))
Example #6
0
 def testUnscrambled3DAsyncSobol(self):
     engine_unscrambled_3d = SobolEngine(3)
     draws = np.vstack(engine_unscrambled_3d.draw() for i in range(10))
     self.assertTrue(np.array_equal(self.draws_unscrambled_3d, draws))
Example #7
0
 def test0Dim(self):
     engine = SobolEngine(0)
     draws = engine.draw(5)
     self.assertTrue(np.array_equal(np.empty((5, 0)), draws))
Example #8
0
 def setUp(self):
     engine_unscrambled_1d = SobolEngine(1)
     self.draws_unscrambled_1d = engine_unscrambled_1d.draw(10)
     engine_unscrambled_3d = SobolEngine(3)
     self.draws_unscrambled_3d = engine_unscrambled_3d.draw(10)
     engine_scrambled_1d = SobolEngine(1, scramble=True, seed=12345)
     self.draws_scrambled_1d = engine_scrambled_1d.draw(10)
     engine_scrambled_3d = SobolEngine(3, scramble=True, seed=12345)
     self.draws_scrambled_3d = engine_scrambled_3d.draw(10)