3838]
3939
4040
41+ class DummyAnalyticAcquisitionFunction (AnalyticAcquisitionFunction ):
42+ def forward (self , X ):
43+ pass
44+
45+
4146class TestAnalyticAcquisitionFunction (BotorchTestCase ):
4247 def test_abstract_raises (self ):
4348 with self .assertRaises (TypeError ):
4449 AnalyticAcquisitionFunction ()
50+ # raise if model is multi-output, but no objective is given
51+ mean = torch .zeros (1 , 2 )
52+ variance = torch .ones (1 , 2 )
53+ mm = MockModel (MockPosterior (mean = mean , variance = variance ))
54+ with self .assertRaises (UnsupportedError ):
55+ DummyAnalyticAcquisitionFunction (model = mm )
4556
4657
4758class TestExpectedImprovement (BotorchTestCase ):
@@ -113,9 +124,8 @@ def test_expected_improvement_batch(self):
113124 mean2 = torch .rand (3 , 1 , 2 , device = self .device , dtype = dtype )
114125 variance2 = torch .rand (3 , 1 , 2 , device = self .device , dtype = dtype )
115126 mm2 = MockModel (MockPosterior (mean = mean2 , variance = variance2 ))
116- module2 = ExpectedImprovement (model = mm2 , best_f = 0.0 )
117127 with self .assertRaises (UnsupportedError ):
118- module2 ( X )
128+ ExpectedImprovement ( model = mm2 , best_f = 0.0 )
119129
120130 # test objective (single-output)
121131 mean = torch .tensor ([[[0.5 ]], [[0.25 ]]], device = self .device , dtype = dtype )
@@ -172,9 +182,8 @@ def test_posterior_mean(self):
172182 # check for proper error if multi-output model
173183 mean2 = torch .rand (1 , 2 , device = self .device , dtype = dtype )
174184 mm2 = MockModel (MockPosterior (mean = mean2 ))
175- module2 = PosteriorMean (model = mm2 )
176185 with self .assertRaises (UnsupportedError ):
177- module2 ( X )
186+ PosteriorMean ( model = mm2 )
178187
179188 def test_posterior_mean_batch (self ):
180189 for dtype in (torch .float , torch .double ):
@@ -189,9 +198,8 @@ def test_posterior_mean_batch(self):
189198 # check for proper error if multi-output model
190199 mean2 = torch .rand (3 , 1 , 2 , device = self .device , dtype = dtype )
191200 mm2 = MockModel (MockPosterior (mean = mean2 ))
192- module2 = PosteriorMean (model = mm2 )
193201 with self .assertRaises (UnsupportedError ):
194- module2 ( X )
202+ PosteriorMean ( model = mm2 )
195203
196204
197205class TestProbabilityOfImprovement (BotorchTestCase ):
@@ -217,9 +225,8 @@ def test_probability_of_improvement(self):
217225 mean2 = torch .rand (1 , 2 , device = self .device , dtype = dtype )
218226 variance2 = torch .ones_like (mean2 )
219227 mm2 = MockModel (MockPosterior (mean = mean2 , variance = variance2 ))
220- module2 = ProbabilityOfImprovement (model = mm2 , best_f = 0.0 )
221228 with self .assertRaises (UnsupportedError ):
222- module2 ( X )
229+ ProbabilityOfImprovement ( model = mm2 , best_f = 0.0 )
223230
224231 def test_probability_of_improvement_batch (self ):
225232 for dtype in (torch .float , torch .double ):
@@ -237,9 +244,8 @@ def test_probability_of_improvement_batch(self):
237244 mean2 = torch .rand (3 , 1 , 2 , device = self .device , dtype = dtype )
238245 variance2 = torch .ones_like (mean2 )
239246 mm2 = MockModel (MockPosterior (mean = mean2 , variance = variance2 ))
240- module2 = ProbabilityOfImprovement (model = mm2 , best_f = 0.0 )
241247 with self .assertRaises (UnsupportedError ):
242- module2 ( X )
248+ ProbabilityOfImprovement ( model = mm2 , best_f = 0.0 )
243249
244250
245251class TestUpperConfidenceBound (BotorchTestCase ):
@@ -265,9 +271,8 @@ def test_upper_confidence_bound(self):
265271 mean2 = torch .rand (1 , 2 , device = self .device , dtype = dtype )
266272 variance2 = torch .rand (1 , 2 , device = self .device , dtype = dtype )
267273 mm2 = MockModel (MockPosterior (mean = mean2 , variance = variance2 ))
268- module2 = UpperConfidenceBound (model = mm2 , beta = 1.0 )
269274 with self .assertRaises (UnsupportedError ):
270- module2 ( X )
275+ UpperConfidenceBound ( model = mm2 , beta = 1.0 )
271276
272277 def test_upper_confidence_bound_batch (self ):
273278 for dtype in (torch .float , torch .double ):
@@ -287,9 +292,8 @@ def test_upper_confidence_bound_batch(self):
287292 mean2 = torch .rand (3 , 1 , 2 , device = self .device , dtype = dtype )
288293 variance2 = torch .rand (3 , 1 , 2 , device = self .device , dtype = dtype )
289294 mm2 = MockModel (MockPosterior (mean = mean2 , variance = variance2 ))
290- module2 = UpperConfidenceBound (model = mm2 , beta = 1.0 )
291295 with self .assertRaises (UnsupportedError ):
292- module2 ( X )
296+ UpperConfidenceBound ( model = mm2 , beta = 1.0 )
293297
294298
295299class TestConstrainedExpectedImprovement (BotorchTestCase ):
0 commit comments