@@ -483,18 +483,21 @@ def augment_study(self, study: vz.ProblemAndTrials, /) -> vz.ProblemAndTrials:
483
483
return self .augment (study )
484
484
485
485
486
+ @attrs .define (kw_only = True )
486
487
class StandardizeSearchSpace (VizierIdempotentAugmenter [vz .ProblemAndTrials ]):
487
488
"""Standardizes the search space and corresponding trials.
488
489
489
490
DOUBLE, INTEGER, and DISCRETE parameters are scaled to [0,1] range, and
490
491
corresponding ParameterConfigs are all DOUBLE.
491
492
492
- CATEGORICAL parameters use standard ["0", "1", "2", ...] feasible values .
493
+ CATEGORICAL params use ["0", "1", "2", ...] or ["a", "b", "c", ...] .
493
494
494
495
This is useful mainly for serializations for string-based regressors, where we
495
496
don't care about reversibility back into original space.
496
497
"""
497
498
499
+ alpha_categorical : bool = attrs .field (default = False )
500
+
498
501
def augment (self , study : vz .ProblemAndTrials , / ) -> vz .ProblemAndTrials :
499
502
# Create a forward converter to map to normalized feature space.
500
503
old_search_space = study .problem .search_space
@@ -508,10 +511,11 @@ def augment(self, study: vz.ProblemAndTrials, /) -> vz.ProblemAndTrials:
508
511
new_search_space = vz .SearchSpace ()
509
512
for i , pc in enumerate (old_search_space .parameters ):
510
513
if pc .type == vz .ParameterType .CATEGORICAL :
511
- new_pc = vz .ParameterConfig .factory (
512
- f'x{ i } ' ,
513
- feasible_values = [str (j ) for j in range (len (pc .feasible_values ))],
514
- )
514
+ if self .alpha_categorical :
515
+ feasibles = [chr (j + 97 ) for j in range (len (pc .feasible_values ))]
516
+ else :
517
+ feasibles = [str (j ) for j in range (len (pc .feasible_values ))]
518
+ new_pc = vz .ParameterConfig .factory (f'x{ i } ' , feasible_values = feasibles )
515
519
else :
516
520
new_pc = vz .ParameterConfig .factory (f'x{ i } ' , bounds = (0.0 , 1.0 ))
517
521
new_search_space .add (new_pc )
0 commit comments