performance_history module¶
Class that generates performance measures out of data generated by an algorithm.
Iterative algorithms that solve, for example, optimization problems or equations produce histories of data such as the value of the objective to minimize, or the size of the equation residual, at each iteration. The best value obtained up until each iteration can be generated out of this data. Here we call “performance history” the history of the best values obtained up until each iteration.
Infeasible data can be discarded based upon histories of infeasibility measures or boolean feasibility statuses.
Performance histories can be used to generate target values for a problem, or to generate the data profile of an algorithm.
- class gemseo_benchmark.results.performance_history.PerformanceHistory(objective_values=None, infeasibility_measures=None, feasibility_statuses=None, n_unsatisfied_constraints=None, problem_name=None, objective_name=None, constraints_names=None, doe_size=None, total_time=None, algorithm_configuration=None, number_of_variables=None)[source]¶
Bases:
Sequence
A history of performance measures generated by an algorithm.
A
PerformanceHistory
is a sequence ofHistoryItem
s.- Parameters:
objective_values (Sequence[float] | None) – The history of the quantity to be minimized. If
None
, will be considered empty.infeasibility_measures (Sequence[float] | None) – The history of infeasibility measures. An infeasibility measure is a non-negative real number representing the gap between the design and the feasible space, a zero value meaning feasibility. If
None
and feasibility_statuses is not None then the infeasibility measures are set to zero in case of feasibility, and set to infinity otherwise. IfNone
and feasibility_statuses is None then every infeasibility measure is set to zero.feasibility_statuses (Sequence[bool] | None) – The history of the (boolean) feasibility statuses. If infeasibility_measures is not None then feasibility_statuses is disregarded. If
None
and ‘infeasibility_measures’ is None then every infeasibility measure is set to zero.n_unsatisfied_constraints (Sequence[int] | None) – The history of the number of unsatisfied constraints. If
None
, the entries will be set to 0 for feasible entries and None for infeasible entries.problem_name (str | None) – The name of the problem. If
None
, it will not be set.objective_name (str | None) – The name of the objective function. If
None
, it will not be set.constraints_names (Sequence[str] | None) – The names the scalar constraints. Each name must correspond to a scalar value. If
None
, it will not be set.doe_size (int | None) – The size of the initial design of experiments. If
None
, it will not be set.total_time (float | None) – The total time of the optimization, in seconds. If
None
, it will not be set.algorithm_configuration (AlgorithmConfiguration | None) – The name of the algorithm which generated the history. If
None
, it will not be set.number_of_variables (int | None) – The number of optimization variables. If
None
, it will not be set.
- Raises:
ValueError – If the lengths of the histories do not match.
- apply_infeasibility_tolerance(infeasibility_tolerance)[source]¶
Apply a tolerance on the infeasibility measures of the history items.
Mark the history items with an infeasibility measure below the tolerance as feasible.
- Parameters:
infeasibility_tolerance (float) – the tolerance on the infeasibility measure.
- Return type:
None
- compute_cumulated_minimum()[source]¶
Return the history of the cumulated minimum.
- Returns:
The history of the cumulated minimum.
- Return type:
- static compute_maximum_history(histories)[source]¶
Return the maximum of several performance histories.
- Parameters:
histories (Iterable[PerformanceHistory]) – The performance histories
- Returns:
The maximum history.
- Return type:
- static compute_median_history(histories)[source]¶
Return the median of several performance histories.
- Parameters:
histories (Iterable[PerformanceHistory]) – The performance histories
- Returns:
The median history.
- Return type:
- static compute_minimum_history(histories)[source]¶
Return the minimum of several performance histories.
- Parameters:
histories (Iterable[PerformanceHistory]) – The performance histories
- Returns:
The minimum history.
- Return type:
- count(value) integer -- return number of occurrences of value ¶
- extend(size)[source]¶
Extend the performance history by repeating its last item.
If the history is longer than the expected size then it will not be altered.
- Parameters:
size (int) – The expected size of the extended performance history.
- Returns:
The extended performance history.
- Raises:
ValueError – If the expected size is smaller than the history size.
- Return type:
- classmethod from_file(path)[source]¶
Create a new performance history from a file.
- Parameters:
path (str | Path) – The path to the file.
- Returns:
The performance history.
- Return type:
- classmethod from_problem(problem, problem_name=None)[source]¶
Create a performance history from a solved optimization problem.
- Parameters:
problem (OptimizationProblem) – The optimization problem.
problem_name (str | None) – The name of the problem. If
None
, the name of the problem is not set.
- Returns:
The performance history.
- Return type:
- get_plot_data(feasible=False, minimum_history=False)[source]¶
Return the data to plot the performance history.
- Parameters:
- Returns:
The abscissas and the ordinates of the plot.
- Return type:
tuple[list[int], list[HistoryItem]]
- index(value[, start[, stop]]) integer -- return first index of value. ¶
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- remove_leading_infeasible()[source]¶
Return the history starting from the first feasible item.
- Returns:
The truncated performance history.
- Return type:
- shorten(size)[source]¶
Shorten the performance history to a given size.
If the history is shorter than the expected size then it will not be altered.
- Parameters:
size (int) – The expected size of the shortened performance history.
- Returns:
The shortened performance history.
- Return type:
- to_file(path)[source]¶
Save the performance history in a file.
- Parameters:
path (str | Path) – The path where to write the file.
- Return type:
None
- property items: list[HistoryItem]¶
The history items.
- Raises:
TypeError – If an item is set with a type different from HistoryItem.