GPyOpt.core.task package

Submodules

GPyOpt.core.task.cost module

class GPyOpt.core.task.cost.CostModel(cost_withGradients)

Bases: object

Class to handle the cost of evaluating the function.

param cost_withGradients: function that returns the cost of evaluating the function and its gradient. By default no cost is used. Options are:

  • cost_withGradients is some pre-defined cost function. Should return numpy array as outputs.
  • cost_withGradients = ‘evaluation_time’.

Note

if cost_withGradients = ‘evaluation time’ the evaluation time of the function is used to model a GP whose

mean is used as cost.

update_cost_model(x, cost_x)

Updates the GP used to handle the cost.

param x: input of the GP for the cost model. param x_cost: values of the time cost at the input locations.

GPyOpt.core.task.cost.constant_cost_withGradients(x)

Constant cost function used by default: cost=1, d_cost =0.

GPyOpt.core.task.objective module

class GPyOpt.core.task.objective.Objective

Bases: object

General class to handle the objective function internally.

evaluate(x)
class GPyOpt.core.task.objective.SingleObjective(func, num_cores=1, objective_name='no_name', batch_type='synchronous', space=None)

Bases: GPyOpt.core.task.objective.Objective

Class to handle problems with one single objective function.

param func: objective function. param batch_size: size of the batches (default, 1) param num_cores: number of cores to use in the process of evaluating the objective (default, 1). param objective_name: name of the objective function. param batch_type: Type of batch used. Only ‘synchronous’ evaluations are possible at the moment. param space: Not in use.

Note

the objective function should take 2-dimensional numpy arrays as input and outputs. Each row should

contain a location (in the case of the inputs) or a function evaluation (in the case of the outputs).

evaluate(x)

Performs the evaluation of the objective at x.

GPyOpt.core.task.space module

class GPyOpt.core.task.space.Design_space(space, constraints=None, store_noncontinuous=False)

Bases: object

Class to handle the input domain of the function. The format of a input domain, possibly with restrictions: The domain is defined as a list of dictionaries contains a list of attributes, e.g.:

  • Arm bandit
space =[{‘name’: ‘var_1’, ‘type’: ‘bandit’, ‘domain’: [(-1,1),(1,0),(0,1)]},
{‘name’: ‘var_2’, ‘type’: ‘bandit’, ‘domain’: [(-1,4),(0,0),(1,2)]}]
  • Continuous domain
space =[ {‘name’: ‘var_1’, ‘type’: ‘continuous’, ‘domain’:(-1,1), ‘dimensionality’:1},
{‘name’: ‘var_2’, ‘type’: ‘continuous’, ‘domain’:(-3,1), ‘dimensionality’:2}, {‘name’: ‘var_3’, ‘type’: ‘bandit’, ‘domain’: [(-1,1),(1,0),(0,1)], ‘dimensionality’:2}, {‘name’: ‘var_4’, ‘type’: ‘bandit’, ‘domain’: [(-1,4),(0,0),(1,2)]}, {‘name’: ‘var_5’, ‘type’: ‘discrete’, ‘domain’: (0,1,2,3)}]
  • Discrete domain
space =[ {‘name’: ‘var_3’, ‘type’: ‘discrete’, ‘domain’: (0,1,2,3)}]
{‘name’: ‘var_3’, ‘type’: ‘discrete’, ‘domain’: (-10,10)}]
  • Mixed domain
space =[{‘name’: ‘var_1’, ‘type’: ‘continuous’, ‘domain’:(-1,1), ‘dimensionality’ :1},
{‘name’: ‘var_4’, ‘type’: ‘continuous’, ‘domain’:(-3,1), ‘dimensionality’ :2}, {‘name’: ‘var_3’, ‘type’: ‘discrete’, ‘domain’: (0,1,2,3)}]

Restrictions can be added to the problem. Each restriction is of the form c(x) <= 0 where c(x) is a function of the input variables previously defined in the space. Restrictions should be written as a list of dictionaries. For instance, this is an example of an space coupled with a constraint

space =[ {‘name’: ‘var_1’, ‘type’: ‘continuous’, ‘domain’:(-1,1), ‘dimensionality’ :2}] constraints = [ {‘name’: ‘const_1’, ‘constraint’: ‘x[:,0]**2 + x[:,1]**2 - 1’}]

If no constraints are provided the hypercube determined by the bounds constraints are used.

Note about the internal representation of the vatiables: for variables in which the dimaensionality has been specified in the domain, a subindex is internally asigned. For instance if the variables is called ‘var1’ and has dimensionality 3, the first three positions in the internal representation of the domain will be occupied by variables ‘var1_1’, ‘var1_2’ and ‘var1_3’. If no dimensionality is added, the internal naming remains the same. For instance, in the example above ‘var3’ should be fixed its original name.

param space: list of dictionaries as indicated above. param constraints: list of dictionaries as indicated above (default, none)

find_variable(variable_name)
static fromConfig(constraints)
get_bandit()

Extracts the arms of the bandit if any.

get_bounds()

Extracts the bounds of all the inputs of the domain of the model

get_continuous_bounds()

Extracts the bounds of the continuous variables.

get_continuous_dims()

Returns the dimension of the continuous components of the domain.

get_continuous_space()

Extracts the list of dictionaries with continuous components

get_discrete_dims()

Returns the dimension of the discrete components of the domain.

get_discrete_grid()

Computes a Numpy array with the grid of points that results after crossing the possible outputs of the discrete variables

get_discrete_space()

Extracts the list of dictionaries with continuous components

get_subspace(dims)

Extracts subspace from the reference of a list of variables in the inputs of the model.

has_constraints()

Checks if the problem has constraints. Note that the coordinates of the constraints are defined in terms of the model inputs and not in terms of the objective inputs. This means that if bandit or discre varaibles are in place, the restrictions should reflect this fact (TODO: implement the mapping of constraints defined on the objective to constraints defined on the model).

has_continuous()

Returns true if the space contains at least one continuous variable, and false otherwise

indicator_constraints(x)

Returns array of ones and zeros indicating if x is within the constraints

input_dim()

Extracts the input dimension of the domain.

model_to_objective(x_model)

This function serves as interface between model input vectors and objective input vectors

objective_to_model(x_objective)

This function serves as interface between objective input vectors and model input vectors

round_optimum(x)

Rounds some value x to a feasible value in the design space. x is expected to be a vector or an array with a single row

supported_types = ['continuous', 'discrete', 'bandit', 'categorical']
unzip_inputs(X)
zip_inputs(X)
GPyOpt.core.task.space.bounds_to_space(bounds)

Takes as input a list of tuples with bounds, and create a dictionary to be processed by the class Design_space. This function us used to keep the compatibility with previous versions of GPyOpt in which only bounded continuous optimization was possible (and the optimization domain passed as a list of tuples).

GPyOpt.core.task.variables module

class GPyOpt.core.task.variables.BanditVariable(name, domain, dimensionality=None)

Bases: GPyOpt.core.task.variables.Variable

expand()

Builds a list of single dimensional variables representing current variable.

Examples: For single dimensional variable, it is returned as is discrete of (0,2,4) -> discrete of (0,2,4) For multi dimensional variable, a list of variables is returned, each representing a single dimension continuous {0<=x<=1, 2<=y<=3} -> continuous {0<=x<=1}, continuous {2<=y<=3}

get_bounds()

Returns a list of tuples representing bounds of the variable

get_possible_values()

Returns a list of possible variable values

is_bandit()
model_to_objective(x_model)

Translates model input to objective input with respect to current variable

objective_to_model(x_objective)

Translates objective input to model input with respect to current variable

round(value_array)

Rounds a bandit variable by selecting the closest point in the domain Closest here is defined by euclidian distance Assumes an 1d array of the same length as the single variable value

class GPyOpt.core.task.variables.CategoricalVariable(name, domain, dimensionality=1)

Bases: GPyOpt.core.task.variables.Variable

expand()

Builds a list of single dimensional variables representing current variable.

Examples: For single dimensional variable, it is returned as is discrete of (0,2,4) -> discrete of (0,2,4) For multi dimensional variable, a list of variables is returned, each representing a single dimension continuous {0<=x<=1, 2<=y<=3} -> continuous {0<=x<=1}, continuous {2<=y<=3}

get_bounds()

Returns a list of tuples representing bounds of the variable

get_possible_values()

Returns a list of possible variable values

is_bandit()
model_to_objective(x_model, index_in_model)

Translates model input to objective input with respect to current variable

objective_to_model(x_objective)

Translates objective input to model input with respect to current variable

round(value_array)

Rounds a categorical variable by setting to one the max of the given vector and to zero the rest of the entries. Assumes an 1x[number of categories] array (due to one-hot encoding) as an input

class GPyOpt.core.task.variables.ContinuousVariable(name, domain, dimensionality=1)

Bases: GPyOpt.core.task.variables.Variable

get_bounds()

Returns a list of tuples representing bounds of the variable

get_possible_values()

Returns a list of possible variable values

is_bandit()
is_continuous()
round(value_array)

If value falls within bounds, just return it otherwise return min or max, whichever is closer to the value Assumes an 1d array with a single element as an input.

class GPyOpt.core.task.variables.DiscreteVariable(name, domain, dimensionality=1)

Bases: GPyOpt.core.task.variables.Variable

get_bounds()

Returns a list of tuples representing bounds of the variable

get_possible_values()

Returns a list of possible variable values

is_bandit()
round(value_array)

Rounds a discrete variable by selecting the closest point in the domain Assumes an 1d array with a single element as an input.

class GPyOpt.core.task.variables.Variable(name, var_type, domain, dimensionality)

Bases: object

expand()

Builds a list of single dimensional variables representing current variable.

Examples: For single dimensional variable, it is returned as is discrete of (0,2,4) -> discrete of (0,2,4) For multi dimensional variable, a list of variables is returned, each representing a single dimension continuous {0<=x<=1, 2<=y<=3} -> continuous {0<=x<=1}, continuous {2<=y<=3}

get_bounds()

Returns a list of tuples representing bounds of the variable

get_possible_values()

Returns a list of possible variable values

is_continuous()
model_to_objective(x_model, index_in_model)

Translates model input to objective input with respect to current variable

objective_to_model(x_objective)

Translates objective input to model input with respect to current variable

round(value_array)

Rounds the given value to the variable’s domain. Value is assumed to be in a 1x[variable dimentionality] numpy array

set_index_in_model(index)

Allows to set the index of this variable in the model space

set_index_in_objective(index)

Allows to set the index of this variable in the objective space

GPyOpt.core.task.variables.create_variable(descriptor)

Creates a variable from a dictionary descriptor

Module contents