78
78
LinearMCObjective ,
79
79
ScalarizedPosteriorTransform ,
80
80
)
81
- from botorch .acquisition .preference import AnalyticExpectedUtilityOfBestOption
81
+ from botorch .acquisition .preference import (
82
+ AnalyticExpectedUtilityOfBestOption ,
83
+ qExpectedUtilityOfBestOption ,
84
+ )
82
85
from botorch .acquisition .utils import (
83
86
expand_trace_observations ,
84
87
project_to_target_fidelity ,
@@ -393,7 +396,10 @@ def test_construct_inputs_noisy_ei(self) -> None:
393
396
with self .assertRaisesRegex (ValueError , "Field `X` must be shared" ):
394
397
c (model = mock_model , training_data = self .multiX_multiY )
395
398
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
397
403
# create dummy modellist gp
398
404
n = 10
399
405
X = torch .linspace (0 , 0.95 , n ).unsqueeze (dim = - 1 )
@@ -409,21 +415,44 @@ def test_construct_inputs_constrained_analytic_eubo(self) -> None:
409
415
)
410
416
self .assertEqual (model .num_outputs , 6 )
411
417
412
- c = get_acqf_input_constructor (AnalyticExpectedUtilityOfBestOption )
413
418
mock_pref_model = self .mock_model
414
419
# assume we only have a preference model with 2 outcomes
415
420
mock_pref_model .dim = 2
416
421
mock_pref_model .datapoints = torch .tensor ([])
417
422
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 )
425
453
426
454
# test previous_winner
455
+ c = get_acqf_input_constructor (AnalyticExpectedUtilityOfBestOption )
427
456
previous_winner = torch .randn (mock_pref_model .dim )
428
457
kwargs = c (
429
458
model = model ,
@@ -434,18 +463,6 @@ def test_construct_inputs_constrained_analytic_eubo(self) -> None:
434
463
# test instantiation
435
464
AnalyticExpectedUtilityOfBestOption (** kwargs )
436
465
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
-
449
466
450
467
class TestMCAcquisitionFunctionInputConstructors (InputConstructorBaseTestCase ):
451
468
def test_construct_inputs_mc_base (self ) -> None :
@@ -1419,7 +1436,7 @@ def test_eubo(self) -> None:
1419
1436
pref_model .dim = 2
1420
1437
pref_model .datapoints = torch .tensor ([])
1421
1438
1422
- classes = [AnalyticExpectedUtilityOfBestOption ]
1439
+ classes = [AnalyticExpectedUtilityOfBestOption , qExpectedUtilityOfBestOption ]
1423
1440
self ._test_constructor_base (
1424
1441
classes = classes ,
1425
1442
model = model ,
0 commit comments