def test_optimizer_copy(acq_func): # Checks that the base estimator, the objective and target values # are copied correctly. base_estimator = ExtraTreesRegressor(random_state=2) opt = Optimizer([(-2.0, 2.0)], base_estimator, acq_func=acq_func, n_initial_points=1, acq_optimizer="sampling") # run three iterations so that we have some points and objective values if "ps" in acq_func: opt.run(bench1_with_time, n_iter=3) else: opt.run(bench1, n_iter=3) opt_copy = opt.copy() copied_estimator = opt_copy.base_estimator_ if "ps" in acq_func: assert_true(isinstance(copied_estimator, MultiOutputRegressor)) # check that the base_estimator is not wrapped multiple times is_multi = isinstance(copied_estimator.estimator, MultiOutputRegressor) assert_false(is_multi) else: assert_false(isinstance(copied_estimator, MultiOutputRegressor)) assert_array_equal(opt_copy.Xi, opt.Xi) assert_array_equal(opt_copy.yi, opt.yi)
def test_optimizer_copy(acq_func): # Checks that the base estimator, the objective and target values # are copied correctly. base_estimator = ExtraTreesRegressor(random_state=2) opt = Optimizer([(-2.0, 2.0)], base_estimator, acq_func=acq_func, n_initial_points=1, acq_optimizer="sampling") # run three iterations so that we have some points and objective values if "ps" in acq_func: opt.run(bench1_with_time, n_iter=3) else: opt.run(bench1, n_iter=3) opt_copy = opt.copy() copied_estimator = opt_copy.base_estimator_ if "ps" in acq_func: assert isinstance(copied_estimator, MultiOutputRegressor) # check that the base_estimator is not wrapped multiple times is_multi = isinstance(copied_estimator.estimator, MultiOutputRegressor) assert not is_multi else: assert not isinstance(copied_estimator, MultiOutputRegressor) assert_array_equal(opt_copy.Xi, opt.Xi) assert_array_equal(opt_copy.yi, opt.yi)
def test_optimizer_copy(acq_func): opt = Optimizer([(-2.0, 2.0)], acq_func=acq_func) opt_copy = opt.copy() base_est = opt_copy.base_estimator_ if "ps" in acq_func: assert_true(isinstance(base_est, MultiOutputRegressor)) # check that the base_estimator is not wrapped multiple times assert_false(isinstance(base_est.estimator, MultiOutputRegressor)) else: assert_false(isinstance(base_est, MultiOutputRegressor))