evox.workflows.eval_monitor¶
Module Contents¶
Classes¶
Evaluation monitor. Used for both single-objective and multi-objective workflow. Hooked around the evaluation process, can monitor the offspring, their corresponding fitness and keep track of the evaluation count. Moreover, it can also record the best solution or the pareto front on-the-fly. |
API¶
- class evox.workflows.eval_monitor.EvalMonitor(multi_obj: bool = False, full_fit_history: bool = True, full_sol_history: bool = False, full_pop_history: bool = False, topk: int = 1, device: torch.device | None = None, history_device: torch.device | None = None)[source]¶
Bases:
evox.core.MonitorEvaluation monitor. Used for both single-objective and multi-objective workflow. Hooked around the evaluation process, can monitor the offspring, their corresponding fitness and keep track of the evaluation count. Moreover, it can also record the best solution or the pareto front on-the-fly.
Initialization
Initialize the monitor.
- Parameters:
multi_obj – Whether the optimization is multi-objective. Defaults to False.
full_fit_history – Whether to record the full history of fitness value. Default to True. Setting it to False may reduce memory usage.
full_sol_history – Whether to record the full history of solutions. Default to False. Setting it to True may increase memory usage.
topk – Only affect Single-objective optimization. The number of elite solutions to record. Default to 1, which will record the best individual.
device – The device of the monitor. Defaults to None.
history_device – The device to record the history. Defaults to None. If None, it will use cpu.
Tip
Setting the
history_deviceto the same device as the monitor will save the data transfer time, but may increase the memory usage on the device.Note
When
opt_direction="max"is used, fitness values are internally multiplied by -1 to ensure that optimization logic always treats the best fitness as the minimum value. As a result, raw fitness values (e.g.,monitor.topk_fitness,monitor.fitness_history, etc.) will appear negated. However, access methods such asmonitor.get_best_fitness()andmonitor.get_pf_fitness()automatically reverse this negation and return the original, unmodified values.- property fitness_history: List[torch.Tensor]¶
- property fit_history: List[torch.Tensor]¶
- property solution_history: List[torch.Tensor]¶
- property sol_history: List[torch.Tensor]¶
- property aux_history: Dict[str, List[torch.Tensor]]¶
- property auxiliary_history: Dict[str, List[torch.Tensor]]¶
- get_pf_fitness(deduplicate=True) torch.Tensor[source]¶
Get the approximate pareto front fitness values of all the solutions evaluated so far. Requires enabling
full_fit_history.
- get_pf_solutions(deduplicate=True) torch.Tensor[source]¶
Get the approximate pareto front solutions of all the solutions evaluated so far. Requires enabling both
full_sol_historyandfull_sol_history. Ifdeduplicateis set to True, the duplicated solutions will be removed.
- get_pf(deduplicate=True) Tuple[torch.Tensor, torch.Tensor][source]¶
Get the approximate pareto front solutions and fitness values of all the solutions evaluated so far. Requires enabling both
full_sol_historyandfull_sol_history. Ifdeduplicateis set to True, the duplicated solutions will be removed.
- plot(problem_pf=None, source='eval', **kwargs)[source]¶
Plot the fitness history. If the problem’s Pareto front is provided, it will be plotted as well.
- Parameters:
problem_pf – The Pareto front of the problem. Default to None.
source – The source of the data, either “eval” or “pop”, default to “eval”. When “eval”, the fitness from the problem evaluation side will be plotted, representing what the problem sees. When “pop”, the fitness from the population inside the algorithm will be plotted, representing what the algorithm sees.
kwargs – Additional arguments for the plot.