EDAspy.optimization package

Subpackages

Submodules

EDAspy.optimization.eda module

class EDAspy.optimization.eda.EDA(size_gen: int, max_iter: int, dead_iter: int, n_variables: int, alpha: float = 0.5, elite_factor: float = 0.4, disp: bool = True, parallelize: bool = False, init_data: array | None = None, w_noise: float = 0.5, *args, **kwargs)[source]

Bases: ABC

Abstract class which defines the general performance of the algorithms. The baseline of the EDA approach is defined in this object. The specific configurations is defined in the class of each specific algorithm.

export_settings() dict[source]

Export the configuration of the algorithm to an object to be loaded in other execution.

Returns:

configuration dictionary.

Return type:

dict

minimize(cost_function: callable, output_runtime: bool = True, ftol: float = 1e-08, *args, **kwargs) EdaResult[source]

Minimize function to execute the EDA optimization. By default, the optimizer is designed to minimize a cost function; if maximization is desired, just add a minus sign to your cost function.

Parameters:
  • cost_function – cost function to be optimized and accepts an array as argument.

  • output_runtime – true if information during runtime is desired.

  • ftol – termination tolerance

Returns:

EdaResult object with results and information.

Return type:

EdaResult

property pm: ProbabilisticModel

Returns the probabilistic model used in the EDA implementation.

Returns:

probabilistic model.

Return type:

ProbabilisticModel

property init: GenInit

Returns the initializer used in the EDA implementation.

Returns:

initializer.

Return type:

GenInit

EDAspy.optimization.eda_result module

class EDAspy.optimization.eda_result.EdaResult(best_ind: array, best_cost: float, n_fev: int, history: list, settings: dict, cpu_time: float)[source]

Bases: object

Object used to encapsulate the result and information of the EDA during the execution

EDAspy.optimization.tools module

EDAspy.optimization.tools.arcs2adj_mat(arcs: list, n_variables: int) array[source]

This function transforms the list of arcs in the BN structure to an adjacency matrix.

Parameters:
  • arcs (list) – list of arcs in the BN structure.

  • n_variables (int) – number of variables.

Returns:

adjacency matrix

Return type:

np.array

EDAspy.optimization.tools.plot_bn(arcs: list, var_names: list, pos: dict | None = None, curved_arcs: bool = True, curvature: float = -0.3, node_size: int = 500, node_color: str = 'red', edge_color: str = 'black', arrow_size: int = 15, node_transparency: float = 0.9, edge_transparency: float = 0.9, node_line_widths: float = 2, title: str | None = None, output_file: str | None = None)[source]

This function Plots a BN structure as a directed acyclic graph.

Parameters:
  • arcs (list(tuple)) – Arcs in the BN structure.

  • var_names (list) – List of variables.

  • pos (dict {name of variables: tuples with coordinates}) – Positions in the plot for each node.

  • curved_arcs (bool) – True if curved arcs are desired.

  • curvature (float) – Radians of curvature for edges. By default, -0.3.

  • node_size (int) – Size of the nodes in the graph. By default, 500.

  • node_color (str) – Color set to nodes. By default, ‘red’.

  • edge_color (str) – Color set to edges. By default, ‘black’.

  • arrow_size (int) – Size of arrows in edges. By default, 15.

  • node_transparency (float) – Alpha value [0, 1] that defines the transparency of the node. By default, 0.9.

  • edge_transparency (float) – Alpha value [0, 1] that defines the transparency of the edge. By default, 0.9.

  • node_line_widths (float) – Width of the nodes contour lines. By default, 2.0.

  • title (str) – Title for Figure. By default, None.

  • output_file (str) – Path to save the figure locally.

Returns:

Figure.

Module contents