metaheuristic_designer.history_tracker module#
Module for recording per-generation metrics and exporting them as pandas DataFrames.
- class HistoryTracker[source]#
Bases:
ABCMethods
Return a dictionary containing the recorded history.
restart()Clear all recorded data.
Return a DataFrame with per-generation summary metrics.
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.
- 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:
HistoryTrackerRecord 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 withto_pandas()(a summary of best, median, worst, diversity, and scheduled parameters) orto_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
Return a dictionary containing the recorded history.
restart()Clear all recorded data.
Return a DataFrame with per-generation summary metrics.
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.