def testFit(self, mock_init):
        ma = DiscreteModelBridge()
        ma._training_data = self.observations
        model = mock.create_autospec(DiscreteModel, instance=True)
        ma._fit(model, self.search_space, self.observation_features,
                self.observation_data)
        self.assertEqual(ma.parameters, ["x", "y", "z"])
        self.assertEqual(sorted(ma.outcomes), ["a", "b"])
        Xs = {
            "a": [[0, "foo", True], [1, "foo", True], [1, "bar", True]],
            "b": [[0, "foo", True], [1, "foo", True]],
        }
        Ys = {"a": [[1.0], [2.0], [3.0]], "b": [[-1.0], [-2.0]]}
        Yvars = {"a": [[1.0], [2.0], [3.0]], "b": [[6.0], [7.0]]}
        parameter_values = [[0.0, 1.0], ["foo", "bar"], [True]]
        model_fit_args = model.fit.mock_calls[0][2]
        for i, x in enumerate(model_fit_args["Xs"]):
            self.assertEqual(x, Xs[ma.outcomes[i]])
        for i, y in enumerate(model_fit_args["Ys"]):
            self.assertEqual(y, Ys[ma.outcomes[i]])
        for i, v in enumerate(model_fit_args["Yvars"]):
            self.assertEqual(v, Yvars[ma.outcomes[i]])
        self.assertEqual(model_fit_args["parameter_values"], parameter_values)

        sq_feat = ObservationFeatures({})
        sq_data = self.observation_data[0]
        with self.assertRaises(ValueError):
            ma._fit(
                model,
                self.search_space,
                self.observation_features + [sq_feat],
                self.observation_data + [sq_data],
            )
Example #2
0
 def testUpdate(self, mock_init):
     sq_feat = ObservationFeatures({})
     sq_data = self.observation_data[0]
     ma = DiscreteModelBridge()
     ma._training_data = self.observations
     model = mock.create_autospec(DiscreteModel, instance=True)
     ma._fit(model, self.search_space, self.observation_features,
             self.observation_data)
     ma._update([sq_feat], [sq_data])
     self.assertEqual(ma.parameters, ["x", "y", "z"])
     self.assertEqual(sorted(ma.outcomes), ["a", "b"])
     self.assertEqual(ma.training_in_design, [True, True, True, False])
Example #3
0
 def testUpdate(self, mock_init):
     ma = DiscreteModelBridge()
     ma._training_data = self.observations
     model = mock.create_autospec(DiscreteModel, instance=True)
     ma._fit(model, self.search_space, self.observation_features,
             self.observation_data)
     new_feat = ObservationFeatures(parameters={
         "x": 0,
         "y": "bar",
         "z": True
     })
     new_data = ObservationData(metric_names=["a"],
                                means=np.array([3.0]),
                                covariance=np.array([[3.0]]))
     ma._update([new_feat], [new_data])
     self.assertEqual(ma.parameters, ["x", "y", "z"])
     self.assertEqual(sorted(ma.outcomes), ["a", "b"])