22import tensorflow as tf
33
44from tensorflow .keras .losses import BinaryCrossentropy
5+ import scipy .stats as sps
56
67from ..engine import Ledger , minimize_multi_start , is_duplicate
78from ..types import DenseConfigurationSpace , DenseConfiguration
@@ -19,7 +20,7 @@ def __init__(self, config_space, eta=3, min_budget=0.01, max_budget=1,
1920 num_restarts = 10 , batch_size = 64 , num_steps_per_iter = 1000 ,
2021 optimizer = "adam" , num_layers = 2 , num_units = 32 ,
2122 activation = "relu" , normalize = True , method = "L-BFGS-B" ,
22- max_iter = 100 , ftol = 1e-2 , seed = None , ** kwargs ):
23+ max_iter = 100 , ftol = 1e-2 , distortion = 1e-3 , seed = None , ** kwargs ):
2324
2425 if gamma is None :
2526 gamma = 1 / eta
@@ -31,7 +32,7 @@ def __init__(self, config_space, eta=3, min_budget=0.01, max_budget=1,
3132 optimizer = optimizer , num_layers = num_layers ,
3233 num_units = num_units , activation = activation ,
3334 normalize = normalize , method = method ,
34- max_iter = max_iter , ftol = ftol , seed = seed )
35+ max_iter = max_iter , ftol = ftol , distortion = distortion , seed = seed )
3536 # (LT): Note this is using the *grandparent* class initializer to
3637 # replace the config_generator!
3738 super (HyperBand , self ).__init__ (config_generator = cg , ** kwargs )
@@ -70,8 +71,8 @@ def __init__(self, config_space, gamma=1/3, num_random_init=10,
7071 random_rate = 0.25 , num_restarts = 3 , batch_size = 64 ,
7172 num_steps_per_iter = 1000 , optimizer = "adam" , num_layers = 2 ,
7273 num_units = 32 , activation = "relu" , normalize = True ,
73- method = "L-BFGS-B" , max_iter = 100 , ftol = 1e-2 , seed = None ,
74- ** kwargs ):
74+ method = "L-BFGS-B" , max_iter = 100 , ftol = 1e-2 , distortion = 1e-3 ,
75+ seed = None , ** kwargs ):
7576
7677 super (RatioEstimator , self ).__init__ (** kwargs )
7778
@@ -100,6 +101,7 @@ def __init__(self, config_space, gamma=1/3, num_random_init=10,
100101 self .method = method
101102 self .ftol = ftol
102103 self .max_iter = max_iter
104+ self .distortion = distortion
103105
104106 self .batch_size = batch_size
105107 self .num_steps_per_iter = num_steps_per_iter
@@ -230,7 +232,20 @@ def get_config(self, budget):
230232
231233 self .logger .info (f"[Glob. maximum: value={ - opt .fun :.3f} , x={ opt .x } " )
232234
233- config_opt_arr = opt .x
235+ loc = opt .x
236+
237+ if self .distortion is None :
238+
239+ config_opt_arr = loc
240+ else :
241+
242+ # dist = multivariate_normal(mean=opt.x, cov=opt.hess_inv.todense())
243+ a = (self .bounds .lb - loc ) / self .distortion
244+ b = (self .bounds .ub - loc ) / self .distortion
245+ dist = sps .truncnorm (a = a , b = b , loc = loc , scale = self .distortion )
246+
247+ config_opt_arr = dist .rvs (random_state = self .random_state )
248+
234249 config_opt_dict = self ._dict_from_array (config_opt_arr )
235250
236251 return (config_opt_dict , {})
0 commit comments