BPt.p.Choice#

class BPt.p.Choice(*args, **kwargs)[source]#

BPt parameter wrapper around nevergrad.p.Choice.

Examples

Constructing a Choice parameter:

In [1]: import BPt as bp

In [2]: class_weight_choice = bp.p.Choice(['balanced', None])

In [3]: class_weight_choice
Out[3]: Choice(['balanced', None])

This parameter can then be set when setting Pipeline Pieces. In the example below we will set it to be the params when constructing a logistic ridge model.

In [4]: params = {'class_weight': class_weight_choice}

In [5]: model = bp.Model('ridge', params=params)

In [6]: model
Out[6]: Model(obj='ridge', params={'class_weight': Choice(['balanced', None])})

Attributes

args

Value of the positional arguments.

choices

The different options, as a Tuple Parameter

descriptors

Stores the descriptor information for this parameter.

dimension

Dimension of the standardized space for this parameter i.e size of the vector returned by get_standardized_data(reference=...)

generation

Generation of the parameter (children are current generation + 1)

index

Index of the chosen option

indices

Array of indices of the chosen option

kwargs

Value of the keyword arguments.

losses

Possibly multiobjective losses which were told to the optimizer along this parameter.

name

Name of the parameter This is used to keep track of how this Parameter is configured (included through internal/model parameters), mostly for reproducibility A default version is always provided, but can be overriden directly through the attribute, or through the set_name method (which allows chaining).

random_state

Random state the instrumentation and the optimizers pull from.

Methods

add_layer(other)

Adds a layer which will modify the object behavior

copy()

Creates a full copy of the parameter (with new unique uid).

freeze()

Prevents the parameter from changing value again (through value, mutate etc...)

get_standardized_data(*, reference)

Get the standardized data representing the value of the instance as an array in the optimization space.

get_value_hash()

Hashable object representing the current value of the instance

mutate()

Mutate parameters of the instance, and then its value

recombine(*others)

Update value and parameters of this instance by combining it with other instances.

register_cheap_constraint(func[, as_layer])

Registers a new constraint on the parameter values.

sample()

Sample a new instance of the parameter.

satisfies_constraints()

Whether the instance satisfies the constraints added through the register_cheap_constraint method

set_name(name)

Sets a name and return the current instrumentation (for chaining)

set_standardized_data(data, *[, reference])

Updates the value of the provided reference (or self) using the standardized data.

spawn_child([new_value])

Creates a new instance which shares the same random generator than its parent, is sampled from the same data, and mutates independently from the parentp.

to_grid()

This method will attempt to convert from the current BPt / nevergrad style parameter to a sklearn-grid search compatible one.