opfunu.utils package

opfunu.utils.operator module

opfunu.utils.operator.ackley_func(x)[source]
opfunu.utils.operator.bent_cigar_func(x)[source]
opfunu.utils.operator.calculate_weight(x, delta=1.0)[source]
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.different_powers_func(x)[source]
opfunu.utils.operator.discus_func(x)[source]
opfunu.utils.operator.doubledip(x, c, s)[source]
opfunu.utils.operator.elliptic_func(x)[source]
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.f8f2_func(x)[source]
opfunu.utils.operator.fractal_1d_func(x)[source]
opfunu.utils.operator.generate_diagonal_matrix(size, alpha=10)[source]
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.griewank_func(x)[source]
opfunu.utils.operator.gz_func(x)[source]
opfunu.utils.operator.happy_cat_func(x, shift=0.0)[source]
opfunu.utils.operator.hgbat_func(x, shift=0.0)[source]
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.katsuura_func(x)[source]
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.levy_func(x, shift=0.0)[source]
opfunu.utils.operator.lunacek_bi_rastrigin_func(x, miu0=2.5, d=1, shift=0.0)[source]
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.operator.non_continuous_expanded_scaffer_func(x)[source]
opfunu.utils.operator.non_continuous_rastrigin_func(x)[source]
opfunu.utils.operator.rastrigin_func(x)[source]
opfunu.utils.operator.rosenbrock_func(x, shift=0.0)[source]
opfunu.utils.operator.rotated_expanded_scaffer_func(x)[source]
opfunu.utils.operator.rotated_expanded_schaffer_func(x)[source]
opfunu.utils.operator.rounder(x, condition)[source]
opfunu.utils.operator.scaffer_func(x)[source]
opfunu.utils.operator.schaffer_f7_func(x)[source]
opfunu.utils.operator.schwefel_12_func(x)[source]
opfunu.utils.operator.sphere_func(x)[source]
opfunu.utils.operator.sphere_noise_func(x)[source]
opfunu.utils.operator.tasy_func(x, beta=0.5)[source]
opfunu.utils.operator.tosz_func(x)[source]
opfunu.utils.operator.twist_func(x)[source]
opfunu.utils.operator.weierstrass_func(x, a=0.5, b=3.0, k_max=20)[source]
opfunu.utils.operator.weierstrass_norm_func(x, a=0.5, b=3.0, k_max=20)[source]

This function matches CEC2005 description of F11 except for addition of the bias and follows the C implementation

opfunu.utils.operator.zakharov_func(x)[source]

opfunu.utils.visualize module

opfunu.utils.visualize.custom_formatter(x, pos)[source]
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.