7878 LinearMCObjective ,
7979 ScalarizedPosteriorTransform ,
8080)
81- from botorch .acquisition .preference import AnalyticExpectedUtilityOfBestOption
81+ from botorch .acquisition .preference import (
82+ AnalyticExpectedUtilityOfBestOption ,
83+ qExpectedUtilityOfBestOption ,
84+ )
8285from botorch .acquisition .utils import (
8386 expand_trace_observations ,
8487 project_to_target_fidelity ,
@@ -393,7 +396,10 @@ def test_construct_inputs_noisy_ei(self) -> None:
393396 with self .assertRaisesRegex (ValueError , "Field `X` must be shared" ):
394397 c (model = mock_model , training_data = self .multiX_multiY )
395398
396- def test_construct_inputs_constrained_analytic_eubo (self ) -> None :
399+ def test_construct_inputs_eubo (self ) -> None :
400+ """test input constructor for analytical EUBO and MC qEUBO"""
401+
402+ # Set up
397403 # create dummy modellist gp
398404 n = 10
399405 X = torch .linspace (0 , 0.95 , n ).unsqueeze (dim = - 1 )
@@ -409,21 +415,44 @@ def test_construct_inputs_constrained_analytic_eubo(self) -> None:
409415 )
410416 self .assertEqual (model .num_outputs , 6 )
411417
412- c = get_acqf_input_constructor (AnalyticExpectedUtilityOfBestOption )
413418 mock_pref_model = self .mock_model
414419 # assume we only have a preference model with 2 outcomes
415420 mock_pref_model .dim = 2
416421 mock_pref_model .datapoints = torch .tensor ([])
417422
418- # test basic construction
419- kwargs = c (model = model , pref_model = mock_pref_model )
420- self .assertIsInstance (kwargs ["outcome_model" ], FixedSingleSampleModel )
421- self .assertIs (kwargs ["pref_model" ], mock_pref_model )
422- self .assertIsNone (kwargs ["previous_winner" ])
423- # test instantiation
424- AnalyticExpectedUtilityOfBestOption (** kwargs )
423+ for eubo_acqf in (
424+ AnalyticExpectedUtilityOfBestOption ,
425+ qExpectedUtilityOfBestOption ,
426+ ):
427+ c = get_acqf_input_constructor (eubo_acqf )
428+
429+ # test model only (i.e., PBO) construction
430+ kwargs = c (model = mock_pref_model )
431+ self .assertIsNone (kwargs ["outcome_model" ])
432+
433+ # test basic construction
434+ kwargs = c (model = model , pref_model = mock_pref_model )
435+ self .assertIsInstance (kwargs ["outcome_model" ], FixedSingleSampleModel )
436+ self .assertIs (kwargs ["pref_model" ], mock_pref_model )
437+ if eubo_acqf is AnalyticExpectedUtilityOfBestOption :
438+ self .assertIsNone (kwargs ["previous_winner" ])
439+ # test instantiation
440+ eubo_acqf (** kwargs )
441+
442+ # test sample_multiplier
443+ torch .manual_seed (123 )
444+ kwargs = c (
445+ model = model ,
446+ pref_model = mock_pref_model ,
447+ sample_multiplier = 1e6 ,
448+ )
449+ # w by default is drawn from std normal and very unlikely to be > 10.0
450+ self .assertTrue ((kwargs ["outcome_model" ].w .abs () > 10.0 ).all ())
451+ # Check w has the right dimension that agrees with the preference model
452+ self .assertEqual (kwargs ["outcome_model" ].w .shape [- 1 ], mock_pref_model .dim )
425453
426454 # test previous_winner
455+ c = get_acqf_input_constructor (AnalyticExpectedUtilityOfBestOption )
427456 previous_winner = torch .randn (mock_pref_model .dim )
428457 kwargs = c (
429458 model = model ,
@@ -434,18 +463,6 @@ def test_construct_inputs_constrained_analytic_eubo(self) -> None:
434463 # test instantiation
435464 AnalyticExpectedUtilityOfBestOption (** kwargs )
436465
437- # test sample_multiplier
438- torch .manual_seed (123 )
439- kwargs = c (
440- model = model ,
441- pref_model = mock_pref_model ,
442- sample_multiplier = 1e6 ,
443- )
444- # w by default is drawn from std normal and very unlikely to be > 10.0
445- self .assertTrue ((kwargs ["outcome_model" ].w .abs () > 10.0 ).all ())
446- # Check w has the right dimension that agrees with the preference model
447- self .assertEqual (kwargs ["outcome_model" ].w .shape [- 1 ], mock_pref_model .dim )
448-
449466
450467class TestMCAcquisitionFunctionInputConstructors (InputConstructorBaseTestCase ):
451468 def test_construct_inputs_mc_base (self ) -> None :
@@ -1419,7 +1436,7 @@ def test_eubo(self) -> None:
14191436 pref_model .dim = 2
14201437 pref_model .datapoints = torch .tensor ([])
14211438
1422- classes = [AnalyticExpectedUtilityOfBestOption ]
1439+ classes = [AnalyticExpectedUtilityOfBestOption , qExpectedUtilityOfBestOption ]
14231440 self ._test_constructor_base (
14241441 classes = classes ,
14251442 model = model ,
0 commit comments