コード例 #1
0
 def test_example_runs_with_non_default_optimizer_kwargs(self):
     """Simple integration test for example with non default kwargs."""
     run_example(
         num_to_sample=1,
         verbose=False,
         testapp=self.testapp,
         gp_next_points_kwargs={
             'optimizer_info': {
                 'num_multistarts':
                 TEST_OPTIMIZER_MULTISTARTS,
                 'num_random_samples':
                 TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                 'optimizer_parameters':
                 TEST_GRADIENT_DESCENT_PARAMETERS._asdict(),
             }
         },
         gp_hyper_opt_kwargs={
             'optimizer_info': {
                 'num_multistarts':
                 TEST_OPTIMIZER_MULTISTARTS,
                 'num_random_samples':
                 TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                 'optimizer_parameters':
                 TEST_GRADIENT_DESCENT_PARAMETERS._asdict(),
             }
         },
         gp_mean_var_kwargs={},
         rest_port=1337,
     )
コード例 #2
0
ファイル: gp_hyper_opt_test.py プロジェクト: filthysocks/MOE
    def _build_json_payload(domain, covariance, historical_data):
        """Create a json_payload to POST to the /gp/hyper_opt endpoint with all needed info."""
        hyper_dim = domain.dim + 1
        dict_to_dump = {
            'gp_historical_info': historical_data.json_payload(),
            'covariance_info': covariance.get_json_serializable_info(),
            'domain_info': domain.get_json_serializable_info(minimal=True),
            'optimizer_info': {
                'optimizer_type': GRADIENT_DESCENT_OPTIMIZER,
                'num_multistarts': TEST_OPTIMIZER_MULTISTARTS,
                'num_random_samples': TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                'optimizer_parameters': dict(TEST_GRADIENT_DESCENT_PARAMETERS._asdict()),
                },
            'hyperparameter_domain_info': {
                'dim': hyper_dim,
                'domain_type': 'tensor_product',
                'domain_bounds': [],
                },
            }

        for _ in range(hyper_dim):
            dict_to_dump['hyperparameter_domain_info']['domain_bounds'].append({
                'min': 0.1,
                'max': 2.0,
                })
        return json.dumps(dict_to_dump)
コード例 #3
0
ファイル: gp_hyper_opt_test.py プロジェクト: Python3pkg/MOE
    def _build_json_payload(domain, covariance, historical_data):
        """Create a json_payload to POST to the /gp/hyper_opt endpoint with all needed info."""
        hyper_dim = domain.dim + 1
        dict_to_dump = {
            'gp_historical_info': historical_data.json_payload(),
            'covariance_info': covariance.get_json_serializable_info(),
            'domain_info': domain.get_json_serializable_info(minimal=True),
            'optimizer_info': {
                'optimizer_type':
                GRADIENT_DESCENT_OPTIMIZER,
                'num_multistarts':
                TEST_OPTIMIZER_MULTISTARTS,
                'num_random_samples':
                TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                'optimizer_parameters':
                dict(TEST_GRADIENT_DESCENT_PARAMETERS._asdict()),
            },
            'hyperparameter_domain_info': {
                'dim': hyper_dim,
                'domain_type': 'tensor_product',
                'domain_bounds': [],
            },
        }

        for _ in range(hyper_dim):
            dict_to_dump['hyperparameter_domain_info']['domain_bounds'].append(
                {
                    'min': 0.1,
                    'max': 2.0,
                })
        return json.dumps(dict_to_dump)
コード例 #4
0
 def test_example_runs(self):
     """Simple integration test for example."""
     run_example(
             verbose=False,
             testapp=self.testapp,
             optimizer_info={
                 'optimizer_type': GRADIENT_DESCENT_OPTIMIZER,
                 'num_multistarts': TEST_OPTIMIZER_MULTISTARTS,
                 'num_random_samples': TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                 'optimizer_parameters': TEST_GRADIENT_DESCENT_PARAMETERS._asdict(),
                 })
コード例 #5
0
 def test_example_runs(self):
     """Simple integration test for example."""
     run_example(
             num_points_to_sample=1,
             verbose=False,
             testapp=self.testapp,
             optimizer_info={
                 'num_multistarts': TEST_OPTIMIZER_MULTISTARTS,
                 'num_random_samples': TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                 'optimizer_parameters': TEST_GRADIENT_DESCENT_PARAMETERS._asdict(),
                 },
             rest_port=1337,
     )
コード例 #6
0
 def test_example_runs_with_non_default_optimizer_kwargs(self):
     """Simple integration test for example with non default kwargs."""
     run_example(
             num_to_sample=1,
             verbose=False,
             testapp=self.testapp,
             gp_next_points_kwargs={
                 'optimizer_info': {
                     'num_multistarts': TEST_OPTIMIZER_MULTISTARTS,
                     'num_random_samples': TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                     'optimizer_parameters': TEST_GRADIENT_DESCENT_PARAMETERS._asdict(),
                     }
                 },
             gp_hyper_opt_kwargs={
                 'optimizer_info': {
                     'num_multistarts': TEST_OPTIMIZER_MULTISTARTS,
                     'num_random_samples': TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                     'optimizer_parameters': TEST_GRADIENT_DESCENT_PARAMETERS._asdict(),
                     }
                 },
             gp_mean_var_kwargs={},
             rest_port=1337,
             )
コード例 #7
0
    def test_optimizer_params_passed_through(self):
        """Test that the optimizer parameters get passed through to the endpoint."""
        # TODO(GH-305): turn this into a unit test by going through OptimizableGpPrettyView
        # and mocking out dependencies (instead of awkwardly constructing a more complex object).
        test_case = self.gp_test_environments[0]
        num_to_sample = 1

        python_domain, python_gp = test_case
        python_cov, historical_data = python_gp.get_core_data_copy()

        # Test default test parameters get passed through
        json_payload = json.loads(
            self._build_json_payload(python_domain, python_cov,
                                     historical_data, num_to_sample))

        request = pyramid.testing.DummyRequest(post=json_payload)
        request.json_body = json_payload
        view = GpNextPointsPrettyView(request)
        # get_params_from_request() requires this field is set. value is arbitrary for now.
        # TODO(GH-305): mock out this and other members
        view._route_name = GP_NEXT_POINTS_CONSTANT_LIAR_ROUTE_NAME
        params = view.get_params_from_request()
        _, optimizer_parameters, num_random_samples = _make_optimizer_parameters_from_params(
            params)
        test_param_dict = TEST_GRADIENT_DESCENT_PARAMETERS._asdict()
        test_param_dict['num_multistarts'] = TEST_OPTIMIZER_MULTISTARTS
        assert optimizer_parameters._get_member_dict() == test_param_dict

        # Test arbitrary parameters get passed through
        for i, key in enumerate(test_param_dict.iterkeys()):
            test_param_dict[key] /= 2
        test_num_multistarts = test_param_dict.pop('num_multistarts')

        json_payload['optimizer_info'][
            'num_multistarts'] = test_num_multistarts
        json_payload['optimizer_info'][
            'optimizer_parameters'] = test_param_dict

        request = pyramid.testing.DummyRequest(post=json_payload)
        request.json_body = json_payload
        view = GpNextPointsPrettyView(request)
        # get_params_from_request() requires this field is set. value is arbitrary for now.
        # TODO(GH-305): mock out this and other members
        view._route_name = GP_NEXT_POINTS_CONSTANT_LIAR_ROUTE_NAME
        params = view.get_params_from_request()
        _, optimizer_parameters, num_random_samples = _make_optimizer_parameters_from_params(
            params)

        test_param_dict['num_multistarts'] = test_num_multistarts
        assert optimizer_parameters._get_member_dict() == test_param_dict
コード例 #8
0
    def _build_json_payload(self,
                            domain,
                            covariance,
                            historical_data,
                            num_to_sample,
                            lie_value=None,
                            lie_method=None,
                            l_bfgs_b=False):
        """Create a json_payload to POST to the /gp/next_points/* endpoint with all needed info."""
        if l_bfgs_b:
            dict_to_dump = {
                'num_to_sample': num_to_sample,
                'mc_iterations': TEST_EXPECTED_IMPROVEMENT_MC_ITERATIONS,
                'gp_historical_info': historical_data.json_payload(),
                'covariance_info': covariance.get_json_serializable_info(),
                'domain_info': domain.get_json_serializable_info(),
                'optimizer_info': {
                    'num_multistarts': TEST_OPTIMIZER_MULTISTARTS,
                    'num_random_samples': TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                    'optimizer_parameters':
                    dict(TEST_LBFGSB_PARAMETERS._asdict()),
                },
                'mvndst_parameters': {
                    'releps': 1.0,
                    'maxpts_per_dim': 200,
                },
            }
        else:
            dict_to_dump = {
                'num_to_sample': num_to_sample,
                'mc_iterations': TEST_EXPECTED_IMPROVEMENT_MC_ITERATIONS,
                'gp_historical_info': historical_data.json_payload(),
                'covariance_info': covariance.get_json_serializable_info(),
                'domain_info': domain.get_json_serializable_info(),
                'optimizer_info': {
                    'num_multistarts':
                    TEST_OPTIMIZER_MULTISTARTS,
                    'num_random_samples':
                    TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                    'optimizer_parameters':
                    dict(TEST_GRADIENT_DESCENT_PARAMETERS._asdict()),
                },
            }

        if lie_value is not None:
            dict_to_dump['lie_value'] = lie_value
        if lie_method is not None:
            dict_to_dump['lie_method'] = lie_method

        return json.dumps(dict_to_dump)
コード例 #9
0
ファイル: gp_next_points_test.py プロジェクト: Zenodia/MOE
    def test_optimizer_params_passed_through(self):
        """Test that the optimizer parameters get passed through to the endpoint."""
        # TODO(GH-305): turn this into a unit test by going through OptimizableGpPrettyView
        # and mocking out dependencies (instead of awkwardly constructing a more complex object).
        test_case = self.gp_test_environments[0]
        num_to_sample = 1

        python_domain, python_gp = test_case
        python_cov, historical_data = python_gp.get_core_data_copy()

        # Test default test parameters get passed through
        json_payload = json.loads(self._build_json_payload(python_domain, python_cov, historical_data, num_to_sample))

        request = pyramid.testing.DummyRequest(post=json_payload)
        request.json_body = json_payload
        view = GpNextPointsPrettyView(request)
        # get_params_from_request() requires this field is set. value is arbitrary for now.
        # TODO(GH-305): mock out this and other members
        view._route_name = GP_NEXT_POINTS_CONSTANT_LIAR_ROUTE_NAME
        params = view.get_params_from_request()
        _, optimizer_parameters, num_random_samples = _make_optimizer_parameters_from_params(params)
        test_param_dict = TEST_GRADIENT_DESCENT_PARAMETERS._asdict()
        test_param_dict["num_multistarts"] = TEST_OPTIMIZER_MULTISTARTS
        assert optimizer_parameters._get_member_dict() == test_param_dict

        # Test arbitrary parameters get passed through
        for i, key in enumerate(test_param_dict.iterkeys()):
            test_param_dict[key] /= 2
        test_num_multistarts = test_param_dict.pop("num_multistarts")

        json_payload["optimizer_info"]["num_multistarts"] = test_num_multistarts
        json_payload["optimizer_info"]["optimizer_parameters"] = test_param_dict

        request = pyramid.testing.DummyRequest(post=json_payload)
        request.json_body = json_payload
        view = GpNextPointsPrettyView(request)
        # get_params_from_request() requires this field is set. value is arbitrary for now.
        # TODO(GH-305): mock out this and other members
        view._route_name = GP_NEXT_POINTS_CONSTANT_LIAR_ROUTE_NAME
        params = view.get_params_from_request()
        _, optimizer_parameters, num_random_samples = _make_optimizer_parameters_from_params(params)

        test_param_dict["num_multistarts"] = test_num_multistarts
        assert optimizer_parameters._get_member_dict() == test_param_dict
コード例 #10
0
ファイル: gp_hyper_opt_test.py プロジェクト: kastnerkyle/MOE
    def _build_json_payload(self, domain, covariance, historical_data):
        """Create a json_payload to POST to the /gp/hyper_opt endpoint with all needed info."""
        hyper_dim = domain.dim + 1
        dict_to_dump = {
            "gp_historical_info": historical_data.json_payload(),
            "covariance_info": covariance.get_json_serializable_info(),
            "domain_info": domain.get_json_serializable_info(minimal=True),
            "optimizer_info": {
                "optimizer_type": GRADIENT_DESCENT_OPTIMIZER,
                "num_multistarts": TEST_OPTIMIZER_MULTISTARTS,
                "num_random_samples": TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                "optimizer_parameters": dict(TEST_GRADIENT_DESCENT_PARAMETERS._asdict()),
            },
            "hyperparameter_domain_info": {"dim": hyper_dim, "domain_type": "tensor_product", "domain_bounds": []},
        }

        for _ in range(hyper_dim):
            dict_to_dump["hyperparameter_domain_info"]["domain_bounds"].append({"min": 0.1, "max": 2.0})
        return json.dumps(dict_to_dump)
コード例 #11
0
ファイル: gp_hyper_opt_test.py プロジェクト: Python3pkg/MOE
    def test_optimizer_params_passed_through(self):
        """Test that the optimizer parameters get passed through to the endpoint."""
        test_case = self.gp_test_environments[0]

        python_domain, python_gp = test_case
        python_cov, historical_data = python_gp.get_core_data_copy()

        # Test default test parameters get passed through
        json_payload = json.loads(
            self._build_json_payload(python_domain, python_cov,
                                     historical_data))

        request = pyramid.testing.DummyRequest(post=json_payload)
        request.json_body = json_payload
        view = GpHyperOptView(request)
        params = view.get_params_from_request()
        _, optimizer_parameters, num_random_samples = _make_optimizer_parameters_from_params(
            params)

        test_param_dict = TEST_GRADIENT_DESCENT_PARAMETERS._asdict()
        test_param_dict['num_multistarts'] = TEST_OPTIMIZER_MULTISTARTS
        assert optimizer_parameters._get_member_dict() == test_param_dict

        # Test arbitrary parameters get passed through
        for i, key in enumerate(iter(test_param_dict.keys())):
            test_param_dict[key] /= 2
        test_num_multistarts = test_param_dict.pop('num_multistarts')

        json_payload['optimizer_info'][
            'num_multistarts'] = test_num_multistarts
        json_payload['optimizer_info'][
            'optimizer_parameters'] = test_param_dict

        request = pyramid.testing.DummyRequest(post=json_payload)
        request.json_body = json_payload
        view = GpHyperOptView(request)
        params = view.get_params_from_request()
        _, optimizer_parameters, num_random_samples = _make_optimizer_parameters_from_params(
            params)

        test_param_dict['num_multistarts'] = test_num_multistarts
        assert optimizer_parameters._get_member_dict() == test_param_dict
コード例 #12
0
ファイル: gp_next_points_test.py プロジェクト: TimDumol/MOE
    def _build_json_payload(self, domain, covariance, historical_data, num_to_sample, lie_value=None, lie_method=None):
        """Create a json_payload to POST to the /gp/next_points/* endpoint with all needed info."""
        dict_to_dump = {
            'num_to_sample': num_to_sample,
            'mc_iterations': TEST_EXPECTED_IMPROVEMENT_MC_ITERATIONS,
            'gp_historical_info': historical_data.json_payload(),
            'covariance_info': covariance.get_json_serializable_info(),
            'domain_info': domain.get_json_serializable_info(),
            'optimizer_info': {
                'num_multistarts': TEST_OPTIMIZER_MULTISTARTS,
                'num_random_samples': TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                'optimizer_parameters': dict(TEST_GRADIENT_DESCENT_PARAMETERS._asdict()),
                },
            }

        if lie_value is not None:
            dict_to_dump['lie_value'] = lie_value
        if lie_method is not None:
            dict_to_dump['lie_method'] = lie_method

        return json.dumps(dict_to_dump)
コード例 #13
0
ファイル: gp_next_points_test.py プロジェクト: Zenodia/MOE
    def _build_json_payload(
        domain, covariance, historical_data, num_to_sample, lie_value=None, lie_method=None, l_bfgs_b=False
    ):
        """Create a json_payload to POST to the /gp/next_points/* endpoint with all needed info."""
        if l_bfgs_b:
            dict_to_dump = {
                "num_to_sample": num_to_sample,
                "mc_iterations": TEST_EXPECTED_IMPROVEMENT_MC_ITERATIONS,
                "gp_historical_info": historical_data.json_payload(),
                "covariance_info": covariance.get_json_serializable_info(),
                "domain_info": domain.get_json_serializable_info(),
                "optimizer_info": {
                    "num_multistarts": TEST_OPTIMIZER_MULTISTARTS,
                    "num_random_samples": TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                    "optimizer_parameters": dict(TEST_LBFGSB_PARAMETERS._asdict()),
                },
                "mvndst_parameters": {"releps": 1.0, "maxpts_per_dim": 200},
            }
        else:
            dict_to_dump = {
                "num_to_sample": num_to_sample,
                "mc_iterations": TEST_EXPECTED_IMPROVEMENT_MC_ITERATIONS,
                "gp_historical_info": historical_data.json_payload(),
                "covariance_info": covariance.get_json_serializable_info(),
                "domain_info": domain.get_json_serializable_info(),
                "optimizer_info": {
                    "num_multistarts": TEST_OPTIMIZER_MULTISTARTS,
                    "num_random_samples": TEST_OPTIMIZER_NUM_RANDOM_SAMPLES,
                    "optimizer_parameters": dict(TEST_GRADIENT_DESCENT_PARAMETERS._asdict()),
                },
            }

        if lie_value is not None:
            dict_to_dump["lie_value"] = lie_value
        if lie_method is not None:
            dict_to_dump["lie_method"] = lie_method

        return json.dumps(dict_to_dump)
コード例 #14
0
ファイル: gp_hyper_opt_test.py プロジェクト: Allensmile/MOE
    def test_optimizer_params_passed_through(self):
        """Test that the optimizer parameters get passed through to the endpoint."""
        test_case = self.gp_test_environments[0]

        python_domain, python_gp = test_case
        python_cov, historical_data = python_gp.get_core_data_copy()

        # Test default test parameters get passed through
        json_payload = json.loads(self._build_json_payload(python_domain, python_cov, historical_data))

        request = pyramid.testing.DummyRequest(post=json_payload)
        request.json_body = json_payload
        view = GpHyperOptView(request)
        params = view.get_params_from_request()
        _, optimizer_parameters, num_random_samples = _make_optimizer_parameters_from_params(params)

        test_param_dict = TEST_GRADIENT_DESCENT_PARAMETERS._asdict()
        test_param_dict['num_multistarts'] = TEST_OPTIMIZER_MULTISTARTS
        assert optimizer_parameters._get_member_dict() == test_param_dict

        # Test arbitrary parameters get passed through
        for i, key in enumerate(test_param_dict.iterkeys()):
            test_param_dict[key] /= 2
        test_num_multistarts = test_param_dict.pop('num_multistarts')

        json_payload['optimizer_info']['num_multistarts'] = test_num_multistarts
        json_payload['optimizer_info']['optimizer_parameters'] = test_param_dict

        request = pyramid.testing.DummyRequest(post=json_payload)
        request.json_body = json_payload
        view = GpHyperOptView(request)
        params = view.get_params_from_request()
        _, optimizer_parameters, num_random_samples = _make_optimizer_parameters_from_params(params)

        test_param_dict['num_multistarts'] = test_num_multistarts
        assert optimizer_parameters._get_member_dict() == test_param_dict