Parameters#

pyhopper.float(lb=None, ub=None, fmt=None, init=None, log=None, precision=None, shape=None, mutation_fn=None, seeding_fn=None)#

Creates a new floating point parameter

Examples:

>>> pyhopper.float(1) # uniform distribution in range [0,1]
>>> pyhopper.float(-1,1) # uniform distribution in range [-1,1]
>>> pyhopper.float(1e-5,1e-2, log=True) # loguniform distrubution
>>> pyhopper.float(0,0.5, "0.1f") # uniform distribution, quantized to 0.1 increments (1 decimal digit)
>>> pyhopper.float(1e-5,1e-2, "0.1g") # loguniform distribution, logquantized to to 1 signficiant digit
>>> pyhopper.float(-1,1, shape=(3,3)) # multidimensional parameter
Parameters
  • lb (Optional[Union[int, float, ndarray]]) – Lower bound of the parameter. If both lb and ub are None, this parameter will be unbounded (usually not recommended).

  • ub (Optional[Union[int, float, ndarray]]) – Upper bound of the parameter. If None, the lb argument will be used as upper bound with a lower bound of 0.

  • init (Optional[Union[int, float, ndarray]]) – Initial value of the parameter. If None it will be randomly sampled

  • fmt (Optional[str]) – Format string as syntactic sugar for setting both log and precision. fmt=”0.2f” refers to parameter with linear search space and 2 decimal digts precision. fmt=”0.1g” refers to a parameter with logarithmic search space and 1 significant digit precision

  • shape (Optional[Union[int, Tuple]]) – For NumPy array type parameters, this argument must be set to a tuple containing the shape of the np.ndarray

  • log (Optional[bool]) – Whether to use logarithmic or linearly scaling of the parameter. Defaults to False which searches the space linearly. If True, a logarithmic scaling is applied to the search space of this variable

  • precision (Optional[int]) – Rounds the values to the specified significant digits. Defaults to None meaning that no rounding is applied

  • mutation_fn (Optional[function]) – Setting this argument to a callable overwrites the default local sampling strategy. The callback gets called with the value of the the current best solution as argument and returns a mutated value

  • seeding_fn (Optional[function]) – Setting this argument to a callable overwrites the default random seeding strategy

Return type

FloatParameter

import pyhopper

pyhopper.float(0,1) #  Bounded by 0 and 1
pyhopper.float(1)   #  Implicitly bounded by 0 and 1
pyhopper.float()    #  Unbounded
pyhopper.int(lb=None, ub=None, init=None, multiple_of=None, power_of=None, shape=None, seeding_fn=None, mutation_fn=None)#

Creates a new integer parameter (both lower and upper bounds are inclusive)

Examples:

>>> pyhopper.int(10) # uniform distribution [0,10] (including 0 and 10 as valid values)
>>> pyhopper.int(-10, 10) # uniform distribution [-10,10]
>>> pyhopper.int(100,500, multiple_of=100) # quantized to 100 increments (100,200,300,400,500)
>>> pyhopper.int(8,64, power_of=2) # quantized to powers of 2 (8,16,32,64)
>>> pyhopper.int(0,100, shape=5) # multidimensional parameter (5 dimensions)
Parameters
  • lb (Optional[Union[int, float, ndarray]]) – Inclusive lower bound of the parameter (used as upper bound if no upper bound is provided)

  • ub (Optional[Union[int, float, ndarray]]) – Inclusive upper bound of the parameter. If None, the lb argument will be used as upper bound with a lower bound of 0.

  • init (Optional[Union[int, float, ndarray]]) – Initial value of the parameter. If None it will be randomly sampled

  • multiple_of (Optional[int]) – Setting this value to a positive integer enforces the sampled values of this parameter to be a mulitple of multiple_of.

  • shape (Optional[Union[int, Tuple]]) – For NumPy array type parameters, this argument must be set to a tuple containing the shape of the np.ndarray

  • mutation_fn (Optional[callable]) – Setting this argument to a callable overwrites the default local sampling strategy. The callback gets called with the value of the the current best solution as argument and returns a mutated value

  • seeding_fn (Optional[callable]) – Setting this argument to a callable overwrites the default random seeding strategy

  • power_of (Optional[int]) –

Returns

Return type

IntParameter

pyhopper.choice(*args, init_index=None, is_ordinal=False, mutation_fn=None, seeding_fn=None)#

Creates a new choice parameter

Examples:

>>> pyhopper.choice("adam","rmsprop","sgd") # unnamed arguments as valid options
>>> pyhopper.choice(["adam","rmsprop","sgd"]) # equivalent syntax
>>> pyhopper.choice("low","medium","high",is_ordinal=True) # ordinal (ordered) options

The possible options can contain nested parameter spaces, for instance

Examples:

>>> pyhopper.choice("const", pyhopper.int(0, 10), ["nested2", pyhopper.int(-10, 0)])
>>> # Generates the samples
>>> # 'const'
>>> # 8
>>> # 2
>>> # ['nested2', 0]
>>> # ['nested2', -8]
>>> # 4
Parameters
  • init_index (Optional[Any]) – Initial guess of the parameter represented by its index

  • *args

    Possible values of this parameter. If only a single list is provided, the items inside the list will be used as admissible values.

  • init – Initial value of the parameter. If None it will be randomly sampled.

  • is_ordinal (bool) – Flag indicating whether two neighboring list items ordered or not. If True, in the local sampling stage list items neighboring the current best value will be preferred. For sets with a natural ordering it is recommended to set this flag to True.

  • mutation_fn (Optional[function]) – Setting this argument to a callable overwrites the default local sampling strategy. The callback gets called with the value of the the current best solution as argument and returns a mutated value

  • seeding_fn (Optional[function]) – Setting this argument to a callable overwrites the default random seeding strategy

Returns

Return type

ChoiceParameter

pyhopper.custom(seeding_fn=None, mutation_fn=None, init=None)#
Parameters
  • seeding_fn (Optional[callable]) –

  • mutation_fn (Optional[callable]) –

  • init (Optional[Any]) –

Return type

CustomParameter

class pyhopper.Parameter(init=None)[source]#