f3dasm.base package
Submodules
f3dasm.base.data module
- class f3dasm.base.data.Data(designspace: f3dasm.base.design.DesignSpace)
Bases:
objectClass that contains data
- Parameters
data (DataFrame) – data stored in a DataFrame
- add(data: pandas.core.frame.DataFrame, ignore_index: bool = False) None
Add data
- Parameters
data (pd.DataFrame) – data to append
- add_numpy_arrays(input: numpy.ndarray, output: numpy.ndarray) None
Append a numpy array to the dataframe
- Parameters
input (np.ndarray) – 2d numpy array added to input data
output (np.ndarray) – 2d numpy array added to output data
- add_output(output: numpy.ndarray, label: str) None
Add a numpy array to the output column of the dataframe
- Parameters
output (np.ndarray) – Output data
label (str) – label of the output column to add to
- data: pandas.core.frame.DataFrame
- designspace: f3dasm.base.design.DesignSpace
- get_input_data() pandas.core.frame.DataFrame
Get the input data
- Returns
DataFrame containing only the input data
- Return type
pd.DataFrame
- get_n_best_input_parameters_numpy(nosamples: int) numpy.ndarray
Returns the input vectors in numpy array format of the n best samples
- Parameters
nosamples (int) – number of samples
- Returns
numpy array containing the n best input parameters
- Return type
np.ndarray
- get_n_best_output_samples(nosamples: int) pandas.core.frame.DataFrame
Returns the n lowest rows of the dataframe. Values are compared to the output columns
- Parameters
nosamples (int) – number of samples
- Returns
DataFrame containing the n best samples
- Return type
pd.DataFrame
- get_number_of_datapoints() int
Get the total number of datapoints
- Returns
total number of datapoints
- Return type
int
- get_output_data() pandas.core.frame.DataFrame
Get the output data
- Returns
DataFrame containing only the output data
- Return type
pd.DataFrame
- plot(input_par1: str, input_par2: Optional[str] = None) None
Plot the data of two parameters in a figure
- Parameters
input_par1 (str) – name of first parameter (x-axis)
input_par2 (str) – name of second parameter (x-axis)
- plot_pairs()
Plot a matrix of 2D plots that visualize the spread of the samples for each dimension. Requires seaborn to be installed.
- reset_data() None
Reset the dataframe to an empty dataframe with the appropriate input and output columns
- show() None
Print the data to the console
f3dasm.base.design module
- class f3dasm.base.design.DesignSpace(input_space: List[f3dasm.base.space.ParameterInterface] = <factory>, output_space: List[f3dasm.base.space.ParameterInterface] = <factory>)
Bases:
objectMain clas for the design of experiments
- Parameters
input_space (List[SpaceInterface]) – list of parameters
output_space (List[SpaceInterface]) – list of parameters
- add_input_space(space: f3dasm.base.space.ParameterInterface) None
Add a new parameter to the searchspace
- Parameters
space (SpaceInterface) – search space parameter to be added
- add_output_space(space: f3dasm.base.space.ParameterInterface) None
Add a new parameter to the searchspace
- Parameters
space (SpaceInterface) – search space parameter to be added
- get_categorical_input_names() List[str]
Receive the names of the categorical input parameters
- Returns
list of names of categorical input parameters
- Return type
List[str]
- get_categorical_input_parameters() List[f3dasm.base.space.CategoricalParameter]
Obtain all the categorical input parameters
- Returns
space of categorical input parameters
- Return type
List[CategoricalSpace]
- get_continuous_input_names() List[str]
Receive the continuous parameter names of the input space”
- Returns
list of names of the continuous input parameters
- Return type
List[str]
- get_continuous_input_parameters() List[f3dasm.base.space.ContinuousParameter]
Obtain all the continuous parameters
- Returns
space of continuous parameters
- Return type
List[ContinuousSpace]
- get_discrete_input_names() List[str]
Receive the names of all the discrete parameters
- Returns
list of names
- Return type
List[str]
- get_discrete_input_parameters() List[f3dasm.base.space.DiscreteParameter]
Obtain all the discrete parameters
- Returns
space of discrete parameters
- Return type
List[DiscreteSpace]
- get_empty_dataframe() pandas.core.frame.DataFrame
Create an empty DataFrame with the information of the input and output space
- Returns
DataFrame containing “input” and “output” columns
- Return type
pd.DataFrame
- get_input_names() List[str]
Get the names of the input parameters
- Returns
List of the names of the input parameters
- Return type
List[str]
- get_input_space() List[f3dasm.base.space.ParameterInterface]
Get the input space
- Returns
List of input parameters
- Return type
List[ParameterInterface]
- get_number_of_input_parameters() int
Obtain the number of input parameters
- Returns
number of input parameters
- Return type
int
- get_number_of_output_parameters() int
Obtain the number of input parameters
- Returns
number of output parameters
- Return type
int
- get_output_names() List[str]
Get the names of the output parameters
- Returns
List of the names of the output parameters
- Return type
List[str]
- get_output_space() List[f3dasm.base.space.ParameterInterface]
Get the output space
- Returns
List of output parameters
- Return type
List[ParameterInterface]
- input_space: List[f3dasm.base.space.ParameterInterface]
- is_single_objective_continuous() bool
Check if the output is single objective and continuous
- Returns
boolean value if the above described condition is true
- Return type
bool
- output_space: List[f3dasm.base.space.ParameterInterface]
f3dasm.base.function module
- class f3dasm.base.function.Function(noise: bool = False, seed: Optional[Any] = None, dimensionality: int = 2, scale_bounds: numpy.ndarray = array([[0.0, 1.0], [0.0, 1.0]]), input_domain: numpy.ndarray = array([[0.0, 1.0], [0.0, 1.0]]))
Bases:
abc.ABCInterface of a continuous benchmark function
- Parameters
noise (bool) – inflict Gaussian noise on the output.
seed (Any|int) – value to seed the random generator (Default = None).
dimensionality (int) – input dimension
scale_bounds (Any|List[float]) – array containing the lower and upper bound of the scaling factor of the input data (Default = [0.0, 1.0])
input_domain (np.ndarray) – array containing the lower and upper bound of the input domain of the original function (Default = [0.0, 1.0])
- check_if_within_bounds(x: numpy.ndarray) bool
Check if the input vector is between the given scaling bounds
- Parameters
x (np.ndarray) – input vector
- Returns
whether the vector is within the boundaries
- Return type
bool
- dfdx(x: numpy.ndarray) numpy.ndarray
Compute the gradient at a particular point in space. Gradient is computed by numdifftools.
- Parameters
x (np.ndarray) – input vector
- Returns
gradient
- Return type
np.ndarray
- dimensionality: int = 2
- f(x) numpy.ndarray
Analytical function of the objective function. Needs to be implemented by inhereted class
- input_domain: numpy.ndarray = array([[0., 1.], [0., 1.]])
- noise: bool = False
- plot(orientation: str = '3D', px: int = 300, domain: numpy.ndarray = array([[0.0, 1.0], [0.0, 1.0]]), show: bool = True)
Generate a surface plot, either 2D or 3D, of the function
- Parameters
orientation (str, optional) – Either “2D” or “3D” orientation. Defaults to “3D”.
px (int, optional) – Number of points per dimension. Defaults to 300.
domain (List, optional) – Domain that needs to be plotted . Defaults to [0, 1].
- Returns
Figure and axis
- Return type
fig, ax
- plot_data(data: f3dasm.base.data.Data, px: int = 300, domain: numpy.ndarray = array([[0.0, 1.0], [0.0, 1.0]]))
Create a 2D contour plot with the datapoints as scatter
- Parameters
data (Data) – Data object containing samples
px (int, optional) – Number of pixels on each axis. Defaults to 300.
domain (np.ndarray, optional) – Domain that needs to be plotted. Defaults to np.tile([0.0, 1.0], (2, 1)).
- Returns
_description_
- Return type
_type_
- scale_bounds: numpy.ndarray = array([[0., 1.], [0., 1.]])
- seed: Any = None
- static set_seed(seed) None
Set the numpy seed of the random generator
f3dasm.base.optimization module
- class f3dasm.base.optimization.Optimizer(data: f3dasm.base.data.Data, hyperparameters: Optional[Mapping[str, Any]] = <factory>, seed: int = 81320, defaults: Optional[Mapping[str, Any]] = <factory>)
Bases:
objectMainclass to inherit from to implement optimization algorithms
- Parameters
data (Data) – Data-object
hyperparamaters (dict) – Dictionary with hyperparamaters (default is None)
seed (int) – seed to set the optimizer
defaults (dict) – Default hyperparameter arguments
- algorithm: Any
- data: f3dasm.base.data.Data
- defaults: Optional[Mapping[str, Any]]
- extract_data() f3dasm.base.data.Data
Returns a copy of the data
- hyperparameters: Optional[Mapping[str, Any]]
- init_parameters() None
Set the initialization parameters. This could be dynamic or static hyperparameters.
- iterate(iterations: int, function: f3dasm.base.function.Function) None
Calls the update_step function multiple times.
- Parameters
iterations (int) – number of iterations
function (Function) – Objective function to evaluate
- seed: int = 81320
- set_algorithm() None
If necessary, the algorithm needs to be set
- set_data(data: f3dasm.base.data.Data) None
- static set_seed(seed: int) None
Set the seed of the optimizer. Needs to be inherited.
- update_step(function: f3dasm.base.function.Function) None
One iteration of the algorithm. Adds the new input vector and resulting output immediately to the data attribute
- Parameters
function (Function) – Objective function to evaluate
f3dasm.base.samplingmethod module
- class f3dasm.base.samplingmethod.SamplingInterface(doe: f3dasm.base.design.DesignSpace, seed: Optional[Any] = None)
Bases:
abc.ABCInterface for sampling method
- Parameters
doe (DoE) – design of experiments object
seed (Any) – Optional: seed for sampling (default is None)
- get_samples(numsamples: int) f3dasm.base.data.Data
Receive samples of the search space
- Parameters
numsamples (int) – number of samples
- Returns
Data objects with the samples
- Return type
- sample_continuous(numsamples: int) numpy.ndarray
Create N samples within the search space
- Parameters
numsamples (int) – number of samples
dimensions (int) – number of dimensions
- Returns
samples
- Return type
np.array
- seed: Any = None
- set_seed(seed: int) None
f3dasm.base.space module
- class f3dasm.base.space.CategoricalParameter(name: str, categories: List[str])
Bases:
f3dasm.base.space.ParameterInterfaceCreates a search space parameter that is categorical
- Parameters
categories (list) – list of strings that represent available categories
- categories: List[str]
- type: str = 'category'
- class f3dasm.base.space.ConstraintInterface
Bases:
objectInterface for constraints
- class f3dasm.base.space.ContinuousParameter(name: str, lower_bound: float = - inf, upper_bound: float = inf)
Bases:
f3dasm.base.space.ParameterInterfaceCreates a search space parameter that is continuous
- Parameters
lower_bound (float) – lower bound of continuous search space
upper_bound (float) – upper bound of continuous search space (exclusive)
- lower_bound: float = -inf
- type: str = 'float'
- upper_bound: float = inf
- class f3dasm.base.space.DiscreteParameter(name: str, lower_bound: int = 0, upper_bound: int = 1)
Bases:
f3dasm.base.space.ParameterInterfaceCreates a search space parameter that is discrete
- Parameters
lower_bound (int) – lower bound of discrete search space
upper_bound (int) – upper bound of discrete search space (exclusive)
- lower_bound: int = 0
- type: str = 'int'
- upper_bound: int = 1
f3dasm.base.utils module
- f3dasm.base.utils.make_nd_continuous_design(bounds: numpy.ndarray, dimensions: int)