@@ -205,22 +205,6 @@ def mask(self):
205
205
206
206
return mask
207
207
208
- @property
209
- def mask (self ):
210
- '''Returns a boolean array of the points that satisfy the constraint and boundary conditions'''
211
- mask = np .ones_like (self .target , dtype = bool )
212
-
213
- # mask points that don't satisfy the constraint
214
- if self ._constraint is not None :
215
- mask &= self ._constraint .allowed (self ._constraint_values )
216
-
217
- # mask points that are outside the bounds
218
- if self ._bounds is not None :
219
- within_bounds = np .all ((self ._bounds [:, 0 ] <= self ._params ) &
220
- (self ._params <= self ._bounds [:, 1 ]), axis = 1 )
221
- mask &= within_bounds
222
-
223
- return mask
224
208
225
209
def params_to_array (self , params ):
226
210
"""Convert a dict representation of parameters into an array version.
@@ -235,13 +219,11 @@ def params_to_array(self, params):
235
219
np.ndarray
236
220
Representation of the parameters as dictionary.
237
221
"""
238
- try :
239
- assert set (params ) == set (self .keys )
240
- except AssertionError as e :
222
+ if not set (params ) == set (self .keys ):
241
223
raise ValueError (
242
224
f"Parameters' keys ({ sorted (params )} ) do " +
243
225
f"not match the expected set of keys ({ self .keys } )."
244
- ) from e
226
+ )
245
227
return np .asarray ([params [key ] for key in self .keys ])
246
228
247
229
def array_to_params (self , x ):
@@ -257,13 +239,11 @@ def array_to_params(self, x):
257
239
dict
258
240
Representation of the parameters as dictionary.
259
241
"""
260
- try :
261
- assert len (x ) == len (self .keys )
262
- except AssertionError as e :
242
+ if not len (x ) == len (self .keys ):
263
243
raise ValueError (
264
244
f"Size of array ({ len (x )} ) is different than the " +
265
245
f"expected number of parameters ({ len (self .keys )} )."
266
- ) from e
246
+ )
267
247
return dict (zip (self .keys , x ))
268
248
269
249
def _as_array (self , x ):
@@ -273,13 +253,11 @@ def _as_array(self, x):
273
253
x = self .params_to_array (x )
274
254
275
255
x = x .ravel ()
276
- try :
277
- assert x .size == self .dim
278
- except AssertionError as e :
256
+ if not x .size == self .dim :
279
257
raise ValueError (
280
258
f"Size of array ({ len (x )} ) is different than the " +
281
259
f"expected number of parameters ({ len (self .keys )} )."
282
- ) from e
260
+ )
283
261
return x
284
262
285
263
def register (self , params , target , constraint_value = None ):
@@ -485,7 +463,6 @@ def res(self):
485
463
Does not report if points are within the bounds of the parameter space.
486
464
487
465
"""
488
-
489
466
if self ._constraint is None :
490
467
params = [dict (zip (self .keys , p )) for p in self .params ]
491
468
0 commit comments