opfunu.utils package¶
opfunu.utils.operator module¶
- opfunu.utils.operator.chebyshev_func(x)[source]¶
The following was converted from the cec2019 C code Storn’s Tchebychev - a 2nd ICEO function - generalized version
- opfunu.utils.operator.expanded_griewank_rosenbrock_func(x)¶
This is based on the CEC version which unrolls the griewank and rosenbrock functions for better performance
- opfunu.utils.operator.expanded_scaffer_f6_func(x)¶
- opfunu.utils.operator.expanded_schaffer_f6_func(x)[source]¶
This is a direct conversion of the CEC2021 C-Code for the Expanded Schaffer F6 Function
- opfunu.utils.operator.grie_rosen_cec_func(x)[source]¶
This is based on the CEC version which unrolls the griewank and rosenbrock functions for better performance
- opfunu.utils.operator.inverse_hilbert_func(x)[source]¶
This is a direct conversion of the cec2019 C code for python optimized to use numpy
- opfunu.utils.operator.lennard_jones_func(x)[source]¶
This version is a direct python conversion from the C-Code of CEC2019 implementation. Find the atomic configuration with minimum energy (Lennard-Jones potential) Valid for any dimension, D = 3 * k, k = 2, 3, 4, …, 25. k is the number of atoms in 3-D space.
- opfunu.utils.operator.modified_schwefel_func(x)[source]¶
This is a direct conversion of the CEC2021 C-Code for the Modified Schwefel F11 Function
opfunu.utils.visualize module¶
- opfunu.utils.visualize.draw_2d(func, lb=None, ub=None, selected_dims=None, n_points=1000, ct_cmap='viridis', ct_levels=30, ct_alpha=0.7, fixed_strategy='mean', fixed_values=None, title='Contour map of the function', x_label=None, y_label=None, figsize=(10, 8), filename=None, exts=('.png', '.pdf'), verbose=True)[source]¶
Draw 2D contour of the function.
- Parameters
func (callable) – The callable function that is used to calculate the value
lb (list, tuple, np.ndarray) – The lower bound of the variables, should be a list, tuple, or numpy array.
ub (list, tuple, np.ndarray) – The upper bound of the variables, should be a list, tuple, or numpy array.
selected_dims (list, tuple, np.ndarray) – The selected dimensions you want to draw. If your function has only 2 dimensions, it will select (1, 2) automatically.
n_points (int) – The number of points that will be used to draw the contour
ct_cmap (str) – The cmap of matplotlib.pyplot.contourf function (https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contourf.html)
ct_levels (int) – The levels parameter of contourf function
ct_alpha (float) – The alpha parameter of contourf function
fixed_strategy (str) –
The selected strategy to set values for other dimensions. When your function has > 2 dimensions, you need to set a fixed value for other dimensions to be able to calculate value. List of available strategy: [“min”, “max”, “mean’, “values”, “zero”]
min: Set the other dimensions by its lower bound
max: Set the other dimensions by its upper bound
mean: Set the other dimensions by it average value (lower bound + upper bound) / 2
zero: Set the other dimensions by 0
values: Set the other dimensions by your passed values through the parameter: fixed_values.
fixed_values (list, tuple, np.ndarray) – Fixed values for all dimensions (length should be the same as lower bound), the selected dimensions will be replaced in the drawing process.
title (str) – Title for the figure
x_label (str) – Set the x label
y_label (str) – Set the y label
figsize (tuple, default=(10, 8)) – The figure size with format of tuple (width, height)
filename (str, default = None) – Set the file name, If None, the file will not be saved
exts (list, tuple, np.ndarray) – The list of extensions to save file, for example: (“.png”, “.pdf”, “.jpg”)
verbose (bool) – Show the figure or not. It will not show on linux system.
- opfunu.utils.visualize.draw_3d(func, lb=None, ub=None, selected_dims=None, n_points=1000, ct_cmap='viridis', ct_levels=30, ct_alpha=0.7, fixed_strategy='mean', fixed_values=None, title='3D visualization of the function', x_label=None, y_label=None, figsize=(10, 8), filename=None, exts=('.png', '.pdf'), verbose=True)[source]¶
Draw 3D of the function.
- Parameters
func (callable) – The callable function that is used to calculate the value
lb (list, tuple, np.ndarray) – The lower bound of the variables, should be a list, tuple, or numpy array.
ub (list, tuple, np.ndarray) – The upper bound of the variables, should be a list, tuple, or numpy array.
selected_dims (list, tuple, np.ndarray) – The selected dimensions you want to draw. If your function has only 2 dimensions, it will select (1, 2) automatically.
n_points (int) – The number of points that will be used to draw the contour
ct_cmap (str) – The cmap of matplotlib.pyplot.contourf function (https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contourf.html)
ct_levels (int) – The levels parameter of contourf function
ct_alpha (float) – The alpha parameter of contourf function
fixed_strategy (str) –
The selected strategy to set values for other dimensions. When your function has > 2 dimensions, you need to set a fixed value for other dimensions to be able to calculate value. List of available strategy: [“min”, “max”, “mean’, “values”, “zero”]
min: Set the other dimensions by its lower bound
max: Set the other dimensions by its upper bound
mean: Set the other dimensions by it average value (lower bound + upper bound) / 2
zero: Set the other dimensions by 0
values: Set the other dimensions by your passed values through the parameter: fixed_values.
fixed_values (list, tuple, np.ndarray) – Fixed values for all dimensions (length should be the same as lower bound), the selected dimensions will be replaced in the drawing process.
title (str) – Title for the figure
x_label (str) – Set the x label
y_label (str) – Set the y label
figsize (tuple, default=(10, 8)) – The figure size with format of tuple (width, height)
filename (str, default = None) – Set the file name, If None, the file will not be saved
exts (list, tuple, np.ndarray) – The list of extensions to save file, for example: (“.png”, “.pdf”, “.jpg”)
verbose (bool) – Show the figure or not. It will not show on linux system.
- opfunu.utils.visualize.draw_latex(latex, title='Latex equation', figsize=(8, 3), dpi=500, filename=None, exts=('.png', '.pdf'), verbose=True)[source]¶
Draw latex equation.
- Parameters
latex (equation) – Your latex equation, you can test on the website: https://latex.codecogs.com/
title (str) – Title for the figure
figsize (tuple, default=(10, 8)) – The figure size with format of tuple (width, height)
dpi (int, default=500) – The dot per inches (DPI) - indicate the number of dots per inch.
filename (str, default = None) – Set the file name, If None, the file will not be saved
exts (list, tuple, np.ndarray) – The list of extensions to save file, for example: (“.png”, “.pdf”, “.jpg”)
verbose (bool) – Show the figure or not. It will not show on linux system.