Exemplo n.º 1
0
    def test_all_constant_liar_methods_function(self):
        """Test that each contant liar ``lie_method`` runs to completion. This is an integration test."""
        for test_case in self.gp_test_environments:
            python_domain, python_gp = test_case
            python_cov, historical_data = python_gp.get_core_data_copy()

            for constant_liar_method in CONSTANT_LIAR_METHODS:

                json_payload = self._build_json_payload(
                    python_domain,
                    python_cov,
                    historical_data,
                    2,  # num_to_sample
                    lie_method=constant_liar_method,
                )

                resp = self.testapp.post(GP_NEXT_POINTS_CONSTANT_LIAR_ENDPOINT,
                                         json_payload)
                resp_schema = GpNextPointsResponse()
                resp_dict = resp_schema.deserialize(json.loads(resp.body))

                assert 'points_to_sample' in resp_dict
                assert len(resp_dict['points_to_sample']) == 2  # num_to_sample
                assert len(resp_dict['points_to_sample'][0]) == python_gp.dim

                assert 'status' in resp_dict
                assert 'expected_improvement' in resp_dict['status']
                assert resp_dict['status']['expected_improvement'] >= 0.0
Exemplo n.º 2
0
    def test_interface_returns_same_as_cpp(self):
        """Integration test for the /gp/next_points/* endpoints."""
        for moe_route in ALL_NEXT_POINTS_MOE_ROUTES:
            for test_case in self.gp_test_environments:
                for num_to_sample in (1, 2, 4):
                    python_domain, python_gp = test_case
                    python_cov, historical_data = python_gp.get_core_data_copy()

                    # Next point from REST
                    if moe_route.route_name == GP_NEXT_POINTS_CONSTANT_LIAR_ROUTE_NAME:
                        json_payload = self._build_json_payload(
                            python_domain, python_cov, historical_data, num_to_sample, lie_value=0.0
                        )
                    elif moe_route.route_name == GP_NEXT_POINTS_EPI_ROUTE_NAME and num_to_sample > 1:
                        json_payload = self._build_json_payload(
                            python_domain, python_cov, historical_data, num_to_sample, l_bfgs_b=True
                        )
                    else:
                        json_payload = self._build_json_payload(
                            python_domain, python_cov, historical_data, num_to_sample
                        )
                    resp = self.testapp.post(moe_route.endpoint, json_payload)
                    resp_schema = GpNextPointsResponse()
                    resp_dict = resp_schema.deserialize(json.loads(resp.body))

                    assert "points_to_sample" in resp_dict
                    assert len(resp_dict["points_to_sample"]) == num_to_sample
                    assert len(resp_dict["points_to_sample"][0]) == python_gp.dim

                    assert "status" in resp_dict
                    assert "expected_improvement" in resp_dict["status"]
                    assert resp_dict["status"]["expected_improvement"] >= 0.0
Exemplo n.º 3
0
    def test_all_constant_liar_methods_function(self):
        """Test that each contant liar ``lie_method`` runs to completion. This is an integration test."""
        for test_case in self.gp_test_environments:
            python_domain, python_gp = test_case
            python_cov, historical_data = python_gp.get_core_data_copy()

            for constant_liar_method in CONSTANT_LIAR_METHODS:

                json_payload = self._build_json_payload(
                        python_domain,
                        python_cov,
                        historical_data,
                        2,  # num_to_sample
                        lie_method=constant_liar_method,
                        )

                resp = self.testapp.post(GP_NEXT_POINTS_CONSTANT_LIAR_ENDPOINT, json_payload)
                resp_schema = GpNextPointsResponse()
                resp_dict = resp_schema.deserialize(json.loads(resp.body))

                assert 'points_to_sample' in resp_dict
                assert len(resp_dict['points_to_sample']) == 2  # num_to_sample
                assert len(resp_dict['points_to_sample'][0]) == python_gp.dim

                assert 'status' in resp_dict
                assert 'expected_improvement' in resp_dict['status']
                assert resp_dict['status']['expected_improvement'] >= 0.0
Exemplo n.º 4
0
    def test_interface_returns_same_as_cpp(self):
        """Integration test for the /gp/next_points/* endpoints."""
        for moe_route in ALL_NEXT_POINTS_MOE_ROUTES:
            for test_case in self.gp_test_environments:
                for num_to_sample in (1, 2, 4):
                    python_domain, python_gp = test_case
                    python_cov, historical_data = python_gp.get_core_data_copy(
                    )

                    # Next point from REST
                    if moe_route.route_name == GP_NEXT_POINTS_CONSTANT_LIAR_ROUTE_NAME:
                        json_payload = self._build_json_payload(
                            python_domain,
                            python_cov,
                            historical_data,
                            num_to_sample,
                            lie_value=0.0)
                    elif moe_route.route_name == GP_NEXT_POINTS_EPI_ROUTE_NAME and num_to_sample > 1:
                        json_payload = self._build_json_payload(
                            python_domain,
                            python_cov,
                            historical_data,
                            num_to_sample,
                            l_bfgs_b=True)
                    else:
                        json_payload = self._build_json_payload(
                            python_domain, python_cov, historical_data,
                            num_to_sample)
                    resp = self.testapp.post(moe_route.endpoint, json_payload)
                    resp_schema = GpNextPointsResponse()
                    resp_dict = resp_schema.deserialize(json.loads(resp.body))

                    T.assert_in('points_to_sample', resp_dict)
                    T.assert_equal(len(resp_dict['points_to_sample']),
                                   num_to_sample)
                    T.assert_equal(len(resp_dict['points_to_sample'][0]),
                                   python_gp.dim)

                    T.assert_in('status', resp_dict)
                    T.assert_in('expected_improvement', resp_dict['status'])
                    T.assert_gte(resp_dict['status']['expected_improvement'],
                                 0.0)
Exemplo n.º 5
0
    def test_interface_returns_same_as_cpp(self):
        """Integration test for the /gp/next_points/* endpoints."""
        for moe_route in ALL_NEXT_POINTS_MOE_ROUTES:
            for test_case in self.gp_test_environments:
                for num_to_sample in (1, 2, 4):
                    python_domain, python_gp = test_case
                    python_cov, historical_data = python_gp.get_core_data_copy()

                    # Next point from REST
                    if moe_route.route_name == GP_NEXT_POINTS_CONSTANT_LIAR_ROUTE_NAME:
                        json_payload = self._build_json_payload(python_domain, python_cov, historical_data, num_to_sample, lie_value=0.0)
                    else:
                        json_payload = self._build_json_payload(python_domain, python_cov, historical_data, num_to_sample)
                    resp = self.testapp.post(moe_route.endpoint, json_payload)
                    resp_schema = GpNextPointsResponse()
                    resp_dict = resp_schema.deserialize(json.loads(resp.body))

                    T.assert_in('points_to_sample', resp_dict)
                    T.assert_equal(len(resp_dict['points_to_sample']), num_to_sample)
                    T.assert_equal(len(resp_dict['points_to_sample'][0]), python_gp.dim)

                    T.assert_in('status', resp_dict)
                    T.assert_in('expected_improvement', resp_dict['status'])
                    T.assert_gte(resp_dict['status']['expected_improvement'], 0.0)