@@ -278,25 +278,28 @@ def test_convert_with_origin_reference(self):
278278 pytrials = []
279279 pytrials .append (
280280 pyvizier .Trial ().complete (
281- pyvizier .Measurement (metrics = {'max' : 4 .0 , 'min' : 2 .0 })
281+ pyvizier .Measurement (metrics = {'max' : 8 .0 , 'min' : 0 .0 })
282282 )
283283 )
284284 pytrials .append (
285285 pyvizier .Trial ().complete (
286- pyvizier .Measurement (metrics = {'max' : 3 .0 , 'min' : - 1 .0 })
286+ pyvizier .Measurement (metrics = {'max' : 6 .0 , 'min' : - 2 .0 })
287287 )
288288 )
289289 pytrials .append (
290290 pyvizier .Trial ().complete (
291- pyvizier .Measurement (metrics = {'max' : 4.0 , 'min' : - 2 .0 })
291+ pyvizier .Measurement (metrics = {'max' : 4.0 , 'min' : - 4 .0 })
292292 )
293293 )
294294
295295 curve = generator .convert (pytrials )
296296 np .testing .assert_array_equal (curve .xs , [1 , 2 , 3 ])
297- np .testing .assert_array_almost_equal (
298- curve .ys , [[0.0 , 3.0 , 8.0 ]], decimal = 0.5
299- )
297+ # After the sign of the minimization metric is flipped, the three metric
298+ # points are (8, 0), (6, 2), (4, 4). After normalization, they become
299+ # (4, 0), (3, 1), (2, 2). The origin is (0, 0). The sequence of hypervolume
300+ # is expected to be (0, 3.5, 6.0). However, we allow a large error because
301+ # the hypervolume computation is approximate.
302+ np .testing .assert_array_almost_equal (curve .ys , [[0.0 , 3.5 , 6.0 ]], decimal = 0 )
300303
301304 def test_convert_with_reference (self ):
302305 generator = convergence .HypervolumeCurveConverter (
@@ -313,25 +316,29 @@ def test_convert_with_reference(self):
313316 pytrials = []
314317 pytrials .append (
315318 pyvizier .Trial ().complete (
316- pyvizier .Measurement (metrics = {'max' : 4 .0 , 'min' : 2 .0 })
319+ pyvizier .Measurement (metrics = {'max' : 8 .0 , 'min' : 0 .0 })
317320 )
318321 )
319322 pytrials .append (
320323 pyvizier .Trial ().complete (
321- pyvizier .Measurement (metrics = {'max' : 3 .0 , 'min' : - 1 .0 })
324+ pyvizier .Measurement (metrics = {'max' : 6 .0 , 'min' : - 2 .0 })
322325 )
323326 )
324327 pytrials .append (
325328 pyvizier .Trial ().complete (
326- pyvizier .Measurement (metrics = {'max' : 4.0 , 'min' : - 2 .0 })
329+ pyvizier .Measurement (metrics = {'max' : 4.0 , 'min' : - 4 .0 })
327330 )
328331 )
329332
330333 curve = generator .convert (pytrials )
331334 np .testing .assert_array_equal (curve .xs , [1 , 2 , 3 ])
332- np .testing .assert_array_almost_equal (
333- curve .ys , [[0.0 , 0.0 , 2.0 ]], decimal = 0.5
334- )
335+ # After the sign of the minimization metric is flipped, the three metric
336+ # points are (8, 0), (6, 2), (4, 4). After normalization, they become
337+ # (4, 0), (3, 1), (2, 2). After accounting for the reference point (3, 0),
338+ # they are (1, 0), (0, 1), (-1, 2). The sequence of hypervolume
339+ # is expected to be (0, 0.5, 0.5). However, we allow a large error
340+ # because the hypervolume computation is approximate.
341+ np .testing .assert_array_almost_equal (curve .ys , [[0.0 , 0.5 , 0.5 ]], decimal = 0 )
335342
336343 def test_convert_with_none_reference (self ):
337344 generator = convergence .HypervolumeCurveConverter ([
@@ -361,9 +368,7 @@ def test_convert_with_none_reference(self):
361368
362369 curve = generator .convert (pytrials )
363370 np .testing .assert_array_equal (curve .xs , [1 , 2 , 3 ])
364- np .testing .assert_array_almost_equal (
365- curve .ys , [[0.0 , 0.0 , 1.0 ]], decimal = 0.5
366- )
371+ np .testing .assert_array_almost_equal (curve .ys , [[0.0 , 0.0 , 1.0 ]], decimal = 0 )
367372
368373 def test_convert_with_inf_none_reference (self ):
369374 generator = convergence .HypervolumeCurveConverter ([
@@ -401,6 +406,7 @@ def test_convert_with_state(self):
401406 ),
402407 ],
403408 reference_value = np .array ([0.0 ]),
409+ disable_metric_normalization = True ,
404410 )
405411 pytrials = []
406412 pytrials .append (
@@ -415,15 +421,13 @@ def test_convert_with_state(self):
415421 )
416422 pytrials .append (
417423 pyvizier .Trial ().complete (
418- pyvizier .Measurement (metrics = {'max' : 4 .0 , 'min' : - 2.0 })
424+ pyvizier .Measurement (metrics = {'max' : 3 .0 , 'min' : - 2.0 })
419425 )
420426 )
421427
422428 curve = generator .convert (pytrials )
423429 np .testing .assert_array_equal (curve .xs , [1 , 2 , 3 ])
424- np .testing .assert_array_almost_equal (
425- curve .ys , [[0.0 , 5.0 , 9.0 ]], decimal = 0.5
426- )
430+ np .testing .assert_array_almost_equal (curve .ys , [[0.0 , 5.0 , 9.0 ]], decimal = 0 )
427431
428432 pytrials = []
429433 pytrials .append (
@@ -439,7 +443,7 @@ def test_convert_with_state(self):
439443
440444 curve = generator .convert (pytrials )
441445 np .testing .assert_array_equal (curve .xs , [4 , 5 ])
442- np .testing .assert_array_almost_equal (curve .ys , [[9.0 , 10.0 ]], decimal = 0.5 )
446+ np .testing .assert_array_almost_equal (curve .ys , [[9.0 , 10.0 ]], decimal = 0 )
443447
444448 def test_convert_factor_with_inf (self ):
445449 generator = convergence .HypervolumeCurveConverter (
@@ -534,7 +538,7 @@ def test_convert_multiobjective(self):
534538 pytrials = []
535539 pytrials .append (
536540 pyvizier .Trial ().complete (
537- pyvizier .Measurement (metrics = {'max' : 4 .0 , 'min' : - 1 .0 , 'safe' : 1.0 })
541+ pyvizier .Measurement (metrics = {'max' : 2 .0 , 'min' : 0 .0 , 'safe' : 1.0 })
538542 )
539543 )
540544 pytrials .append (
@@ -552,9 +556,7 @@ def test_convert_multiobjective(self):
552556
553557 curve = generator .convert (pytrials )
554558 np .testing .assert_array_equal (curve .xs , [1 , 2 , 3 ])
555- np .testing .assert_array_almost_equal (
556- curve .ys , [[4.0 , 4.0 , 8.0 ]], decimal = 0.5
557- )
559+ np .testing .assert_array_almost_equal (curve .ys , [[0.0 , 0.0 , 2.0 ]], decimal = 0 )
558560
559561
560562class RestartingCurveConverterTest (absltest .TestCase ):
@@ -570,6 +572,7 @@ def converter_factory():
570572 name = 'min' , goal = pyvizier .ObjectiveMetricGoal .MINIMIZE
571573 ),
572574 ],
575+ disable_metric_normalization = True ,
573576 )
574577
575578 restart_converter = convergence .RestartingCurveConverter (
0 commit comments