metaheuristic_designer.history_tracker module#

Module for recording per-generation metrics and exporting them as pandas DataFrames.

class HistoryTracker[source]#

Bases: ABC

Methods

get_state()

Return a dictionary containing the recorded history.

restart()

Clear all recorded data.

to_pandas()

Return a DataFrame with per-generation summary metrics.

to_pandas_full_objective()

Return a wide-format DataFrame of all individual objective values.

update(algorithm)

Record metrics for the current generation.

abstract restart()[source]#

Clear all recorded data.

Call this when an algorithm is reset to start a fresh run.

abstract update(algorithm)[source]#

Record metrics for the current generation.

Parameters:
algorithmAlgorithm

The running algorithm from which the current population, fitness, objective, and parameters are extracted.

Parameters:

algorithm (Algorithm)

abstract to_pandas()[source]#

Return a DataFrame with per-generation summary metrics.

Return type:

DataFrame

Returns:
pandas.DataFrame
to_pandas_full_objective()[source]#

Return a wide-format DataFrame of all individual objective values.

Each column Individual_0, Individual_1, … holds the objective of one member of the population across generations. This is useful for boxplots or distribution plots of fitness.

Return type:

DataFrame

Returns:
pandas.DataFrame

Empty by default.

abstract get_state()[source]#

Return a dictionary containing the recorded history.

Return type:

dict

Returns:
dict
class ConfigurableHistoryTracker(track_best=True, track_median=False, track_worst=False, track_full_objective=False, track_full_population=False, track_parameters=False, track_diversity=False)[source]#

Bases: HistoryTracker

Record per-generation metrics and export them as pandas DataFrames.

The tracker is called once per generation (via step()) and stores the requested statistics. After the run the data can be retrieved with to_pandas() (a summary of best, median, worst, diversity, and scheduled parameters) or to_pandas_full_objective() (the full objective vector of every individual at each generation).

Parameters:
track_bestbool, optional

Record the best objective and solution (default True).

track_medianbool, optional

Record the median objective (default False).

track_worstbool, optional

Record the worst objective (default False).

track_full_objectivebool, optional

Store the complete objective vector of the population at every generation. Enables to_pandas_full_objective().

track_full_populationbool, optional

Store the entire population (genotypes) at every generation. This can consume a lot of memory.

track_parametersbool, optional

Record the current value of all scheduled parameters (e.g., mutation strength, branch probability).

track_diversitybool, optional

Compute and store a simple diversity metric (average Euclidean distance from the centroid).

Parameters:
  • track_best (bool)

  • track_median (bool)

  • track_worst (bool)

  • track_full_objective (bool)

  • track_full_population (bool)

  • track_parameters (bool)

  • track_diversity (bool)

Methods

get_state()

Return a dictionary containing the recorded history.

restart()

Clear all recorded data.

to_pandas()

Return a DataFrame with per-generation summary metrics.

to_pandas_full_objective()

Return a wide-format DataFrame of all individual objective values.

update(algorithm)

Record metrics for the current generation.

restart()[source]#

Clear all recorded data.

Call this when an algorithm is reset to start a fresh run.

update(algorithm)[source]#

Record metrics for the current generation.

Parameters:
algorithmAlgorithm

The running algorithm from which the current population, fitness, objective, and parameters are extracted.

Parameters:

algorithm (Algorithm)

to_pandas()[source]#

Return a DataFrame with per-generation summary metrics.

Columns include iteration, best_objective, median_objective, worst_objective, diversity, and one column per scheduled parameter. The DataFrame is intended for easy plotting with seaborn or matplotlib.

Return type:

DataFrame

Returns:
pandas.DataFrame
to_pandas_full_objective()[source]#

Return a wide-format DataFrame of all individual objective values.

Each column Individual_0, Individual_1, … holds the objective of one member of the population across generations. This is useful for boxplots or distribution plots of fitness.

Return type:

DataFrame

Returns:
pandas.DataFrame

Empty DataFrame if track_full_objective was not enabled.

get_state()[source]#

Return a dictionary containing the recorded history.

Return type:

dict

Returns:
dict

Keys include best_objective, best_solutions, etc. Only metrics that were enabled are present.