@@ -82,25 +82,36 @@ def __str__(self):
82
82
83
83
@staticmethod
84
84
def convert_parameter (p ):
85
+ distribution = (
86
+ p .feasible_space .distribution
87
+ if p .feasible_space .distribution != ""
88
+ and p .feasible_space .distribution is not None
89
+ and p .feasible_space .distribution != api .DISTRIBUTION_UNSPECIFIED
90
+ else None
91
+ )
92
+
85
93
if p .parameter_type == api .INT :
86
94
# Default value for INT parameter step is 1
87
- step = 1
88
- if p .feasible_space .step is not None and p .feasible_space .step != "" :
89
- step = p .feasible_space .step
95
+ step = p .feasible_space .step if p .feasible_space .step else 1
90
96
return HyperParameter .int (
91
- p .name , p .feasible_space .min , p .feasible_space .max , step
97
+ p .name , p .feasible_space .min , p .feasible_space .max , step , distribution
92
98
)
99
+
93
100
elif p .parameter_type == api .DOUBLE :
94
101
return HyperParameter .double (
95
102
p .name ,
96
103
p .feasible_space .min ,
97
104
p .feasible_space .max ,
98
105
p .feasible_space .step ,
106
+ distribution ,
99
107
)
108
+
100
109
elif p .parameter_type == api .CATEGORICAL :
101
110
return HyperParameter .categorical (p .name , p .feasible_space .list )
111
+
102
112
elif p .parameter_type == api .DISCRETE :
103
113
return HyperParameter .discrete (p .name , p .feasible_space .list )
114
+
104
115
else :
105
116
logger .error (
106
117
"Cannot get the type for the parameter: %s (%s)" ,
@@ -110,33 +121,35 @@ def convert_parameter(p):
110
121
111
122
112
123
class HyperParameter (object ):
113
- def __init__ (self , name , type_ , min_ , max_ , list_ , step ):
124
+ def __init__ (self , name , type_ , min_ , max_ , list_ , step , distribution = None ):
114
125
self .name = name
115
126
self .type = type_
116
127
self .min = min_
117
128
self .max = max_
118
129
self .list = list_
119
130
self .step = step
131
+ self .distribution = distribution
120
132
121
133
def __str__ (self ):
122
- if self .type == constant .INTEGER or self . type == constant .DOUBLE :
134
+ if self .type in [ constant .INTEGER , constant .DOUBLE ] :
123
135
return (
124
- "HyperParameter(name: {}, type: {}, min: {}, max: {}, step: {})" .format (
125
- self .name , self .type , self .min , self .max , self .step
126
- )
136
+ f"HyperParameter(name: { self .name } , type: { self .type } , min: { self .min } , "
137
+ f"max: { self .max } , step: { self .step } , distribution: { self .distribution } )"
127
138
)
128
139
else :
129
140
return "HyperParameter(name: {}, type: {}, list: {})" .format (
130
141
self .name , self .type , ", " .join (self .list )
131
142
)
132
143
133
144
@staticmethod
134
- def int (name , min_ , max_ , step ):
135
- return HyperParameter (name , constant .INTEGER , min_ , max_ , [], step )
145
+ def int (name , min_ , max_ , step , distribution = None ):
146
+ return HyperParameter (
147
+ name , constant .INTEGER , min_ , max_ , [], step , distribution
148
+ )
136
149
137
150
@staticmethod
138
- def double (name , min_ , max_ , step ):
139
- return HyperParameter (name , constant .DOUBLE , min_ , max_ , [], step )
151
+ def double (name , min_ , max_ , step , distribution = None ):
152
+ return HyperParameter (name , constant .DOUBLE , min_ , max_ , [], step , distribution )
140
153
141
154
@staticmethod
142
155
def categorical (name , lst ):
0 commit comments