DataList¶

class DataList¶

Bases: object

A class to handle input-output pairs of a black-box function.

Methods

__init__

Initialize the data list class.

append

Append an input-output pair.

copy

Deepcopy an instantce of the class.

is_unique

save

Save the data if the filepath is set either in the DataList.__init__ or with the DataList.set_output_path method.

set_output_path

Set a output file path.

to_df

Convert and return the data to pandas.DataFrame.

to_solution_dict

Convert to the solution dict.

to_structured_solution

Convert the i-th data (input) to StructuredSolution.

to_structured_solution_list

Convert the data (all input vectors) to a list of StructuredSolution.

Attributes

abs_y_max

The absolute maximum value in the output values in the current dataset.

values

Return input vectors and output values.

variable_names

Names of the variables.

x

The list of the input vectors.

y

The list of the output values.

__getitem__(i: int) tuple[list[bool | int | float], int | float]¶

Return a tuple of the input vector and output value.

Parameters:

i (int) – Index.

Returns:

A tuple of the input vector and output value.

Return type:

tuple[list[bool | int | float], int | float]

__init__(
x: list[list[bool | int | float]] | None = None,
y: list[int | float] | None = None,
variable_names: list[str] | None = None,
filepath: str | None = None,
) None¶

Initialize the data list class.

Parameters:
  • x (list[list[bool | int | float]] | None, optional) – A list of the input vectors. Defaults to None.

  • y (list[int | float] | None, optional) – A list of the output values. Defaults to None.

  • variable_names (list[str] | None, optional) – A list of the variable names. Defaults to None.

  • filepath (str | None, optional) – A filepath to save the data with save() method. Defaults to None.

Raises:
  • ValueError – If only one of (x, y) is specified.

  • ValueError – If x and y do not have the same length.

  • ValueError – If at least one of the data (x, y) or variable_names is not specified.

__iter__() Iterator[tuple]¶

A tuple of the input vector and output value.

Yields:

tuple[list[bool | int | float], int | float] – A tuple of the input vector and output value.

__len__() int¶

Length of the data list.

Returns:

The length.

Return type:

int

append(value: tuple[list[bool | int | float], int | float]) None¶

Append an input-output pair.

Parameters:

value (tuple[list[bool | int | float], int | float]) – A tuple of input and output.

copy() DataList¶

Deepcopy an instantce of the class.

Returns:

The copied data.

Return type:

DataList

is_unique(solution_dict: FlatSolutionDict) bool¶
save() None¶

Save the data if the filepath is set either in the DataList.__init__ or with the DataList.set_output_path method.

set_output_path(filepath: str | None) None¶

Set a output file path.

Parameters:

filepath (str | None) – A file path.

to_df() DataFrame¶

Convert and return the data to pandas.DataFrame.

Returns:

The converted data.

Return type:

pandas.DataFrame

to_solution_dict(i: int) FlatSolutionDict¶

Convert to the solution dict. This can be used for multi-objective optimization where there is no one specific Variables assigned for the multiple objectives.

Parameters:

i (int) – Index of the sample.

Returns:

The resulting solution dict.

Return type:

FlatSolutionDict

to_structured_solution(variables: Variables, i: int) StructuredSolution¶

Convert the i-th data (input) to StructuredSolution.

Parameters:
  • variables (Variables) – A Variables instance that is relevant to the black-box objective function class that this DataList is for.

  • i (int) – Index of the sample.

Returns:

A converted input vector.

Return type:

StructuredSolution

to_structured_solution_list(variables: Variables) list[StructuredSolution]¶

Convert the data (all input vectors) to a list of StructuredSolution.

Parameters:

variables (Variables) – A Variables instance that is relevant to the black-box objective function class that this DataList is for.

Returns:

A list of converted input vectors.

Return type:

list[StructuredSolution]

__dict__ = mappingproxy({'__module__': 'amplify_bbopt.data_list', '__doc__': 'A class to handle input-output pairs of a black-box function.', '__init__': <function DataList.__init__>, 'variable_names': <property object>, 'append': <function DataList.append>, '__len__': <function DataList.__len__>, '__getitem__': <function DataList.__getitem__>, '__iter__': <function DataList.__iter__>, 'to_df': <function DataList.to_df>, 'to_solution_dict': <function DataList.to_solution_dict>, 'to_structured_solution': <function DataList.to_structured_solution>, 'to_structured_solution_list': <function DataList.to_structured_solution_list>, 'save': <function DataList.save>, 'set_output_path': <function DataList.set_output_path>, 'is_unique': <function DataList.is_unique>, 'values': <property object>, 'abs_y_max': <property object>, 'x': <property object>, 'y': <property object>, 'copy': <function DataList.copy>, '__dict__': <attribute '__dict__' of 'DataList' objects>, '__weakref__': <attribute '__weakref__' of 'DataList' objects>, '__annotations__': {'_x': 'list[list[bool | int | float]]', '_y': 'list[int | float]'}})¶
__weakref__¶

list of weak references to the object (if defined)

property abs_y_max: float¶

The absolute maximum value in the output values in the current dataset.

property values: tuple[list[list[bool | int | float]], list[int | float]]¶

Return input vectors and output values.

Returns:

A tuple of the lists of the input vectors and the corresponding output values.

Return type:

tuple[list[list[bool | int | float]], list[int | float]]

property variable_names: list[str] | None¶

Names of the variables.

property x: list[list[bool | int | float]]¶

The list of the input vectors.

property y: list[int | float]¶

The list of the output values. None elements are replaced with 0.5 * sys.float_info.max.