Beispiel #1
0
 def test_botorch_ackley(self):
     ackley = FromBotorch(botorch_synthetic_function=botorch_synthetic.Ackley())
     self.assertEqual(ackley.name, "FromBotorch_Ackley")
     self.assertAlmostEqual(ackley(1.0, 2.0), 5.422131717799505)
     self.assertAlmostEqual(ackley(x1=1.0, x2=2.0), 5.422131717799505)
     self.assertAlmostEqual(ackley(np.array([1, 2])), 5.422131717799505)
     self.assertAlmostEqual(ackley(np.array([[1, 2], [1, 2]]))[0], 5.422131717799505)
     self.assertAlmostEqual(ackley.domain[0], (-32.768, 32.768), places=3)
     self.assertEqual(ackley.required_dimensionality, 2)
     self.assertEqual(ackley.fmin, 0.0)
     with self.assertRaisesRegex(NotImplementedError, "Ackley does not specify"):
         ackley.maximums
     with self.assertRaisesRegex(NotImplementedError, "Ackley does not specify"):
         ackley.minimums
     with self.assertRaisesRegex(NotImplementedError, "Ackley does not specify"):
         ackley.fmax
Beispiel #2
0
                      (4 * np.pi**2) * x_1**2 + 5.0 / np.pi * x_1 - 6.0)**2 +
                     10 * (1 - 1.0 / (8 * np.pi)) * np.cos(x_1) + 10)


class Aug_Branin(SyntheticFunction):
    """Augmented Branin function (3-dimensional with infinitely many global minima)."""

    _required_dimensionality = 3
    _domain = [(-5, 10), (0, 15), (0, 1)]
    _minimums = [(-np.pi, 12.275, 1), (np.pi, 2.275, 1), (9.42478, 2.475, 1)]
    _fmin = 0.397887
    _fmax = 308.129

    @copy_doc(SyntheticFunction._f)
    def _f(self, X: np.ndarray) -> float:
        x_1 = X[0]
        x_2 = X[1]
        return float((x_2 -
                      (5.1 / (4 * np.pi**2) - 0.1 *
                       (1 - X[-1])) * x_1**2 + 5.0 / np.pi * x_1 - 6.0)**2 +
                     10 * (1 - 1.0 / (8 * np.pi)) * np.cos(x_1) + 10)


hartmann6 = Hartmann6()
aug_hartmann6 = Aug_Hartmann6()
branin = Branin()
aug_branin = Aug_Branin()

# Synthetic functions constructed from BoTorch.
ackley = from_botorch(botorch_synthetic_function=botorch_synthetic.Ackley())
    # pyre-fixme[15]: `_required_dimensionality` overrides attribute defined in
    #  `SyntheticFunction` inconsistently.
    _required_dimensionality = 3
    # pyre-fixme[15]: `_domain` overrides attribute defined in `SyntheticFunction`
    #  inconsistently.
    _domain = [(-5, 10), (0, 15), (0, 1)]
    _minimums = [(-np.pi, 12.275, 1), (np.pi, 2.275, 1), (9.42478, 2.475, 1)]
    # pyre-fixme[15]: `_fmin` overrides attribute defined in `SyntheticFunction`
    #  inconsistently.
    _fmin = 0.397887
    # pyre-fixme[15]: `_fmax` overrides attribute defined in `SyntheticFunction`
    #  inconsistently.
    _fmax = 294.0

    @copy_doc(SyntheticFunction._f)
    def _f(self, X: np.ndarray) -> float:
        x_1 = X[0]
        x_2 = X[1]
        return float((x_2 -
                      (5.1 / (4 * np.pi**2) - 0.1 *
                       (1 - X[-1])) * x_1**2 + 5.0 / np.pi * x_1 - 6.0)**2 +
                     10 * (1 - 1.0 / (8 * np.pi)) * np.cos(x_1) + 10)


hartmann6 = Hartmann6()
aug_hartmann6 = Aug_Hartmann6()
branin = Branin()
aug_branin = Aug_Branin()
ackley = FromBotorch(botorch_synthetic_function=botorch_synthetic.Ackley())
Beispiel #4
0
    AlignedAugHartmann6(),
    # Ax support.
    "hartmann6":
    Hartmann6(),  # d: 6; [(0, 1) for i in range(6)]
    "AugHartmann6":
    Aug_Hartmann6(),  # d: 7; [(0, 1) for i in range(7)]
    "branin":
    Branin(),  # d: 2; [(-5, 10), (0, 15)]
    "AugBranin":
    Aug_Branin(),  # d: 3; [(-5, 10), (0, 15), (0, 1)]

    # From Botorch
    # # dim; _optimal_value; _bounds; _optimizers;
    # (2); 0.0; [(-32.768, 32.768),(-32.768, 32.768)]; [(0.0, 0.0)]
    "ackley2":
    from_botorch(botorch_synthetic_function=botorch_synthetic.Ackley(dim=2)),
    "ackley3":
    from_botorch(botorch_synthetic_function=botorch_synthetic.Ackley(dim=3)),
    "ackley4":
    from_botorch(botorch_synthetic_function=botorch_synthetic.Ackley(dim=4)),
    "ackley7":
    from_botorch(botorch_synthetic_function=botorch_synthetic.Ackley(dim=7)),
    # 2; 0.0; [(-4.5, 4.5), (-4.5, 4.5)]; [(3.0, 0.5)]
    "beale":
    from_botorch(botorch_synthetic_function=botorch_synthetic.Beale()),
    # 2; 0.0; [(-15.0, -5.0), (-3.0, 3.0)]; [(-10.0, 1.0)]
    "bukin":
    from_botorch(botorch_synthetic_function=botorch_synthetic.Bukin()),
    # 8; 0.8; [(-1.0, 1.0) for _ in range(8)]; [tuple(0.0 for _ in range(8))]
    "cosine8":
    from_botorch(botorch_synthetic_function=botorch_synthetic.Cosine8()),