Plotting Metrics Across Histories¶
This page demonstrates the use of plot_metric_history which allows for the plotting the evolution of metrics over each population within a History object.
In [1]:
Copied!
import paretobench as pb
from paretobench.plotting import plot_metric_history, population_obj_scatter
from paretobench.metrics import Hypervolume
import paretobench as pb
from paretobench.plotting import plot_metric_history, population_obj_scatter
from paretobench.metrics import Hypervolume
In [2]:
Copied!
# Load an experiment and get the history object from it
exp = pb.Experiment.load("../data/NSGAII.h5")
hist = exp.runs[0]
# Load an experiment and get the history object from it
exp = pb.Experiment.load("../data/NSGAII.h5")
hist = exp.runs[0]
In [3]:
Copied!
# Show the last generation
population_obj_scatter(hist.reports[-1])
# Show the last generation
population_obj_scatter(hist.reports[-1])
Out[3]:
(<Figure size 640x480 with 1 Axes>, <Axes: xlabel='$f_1$', ylabel='$f_2$'>)
In [4]:
Copied!
# Plot hypervolume vs function evaluations
plot_metric_history(exp.runs[0], Hypervolume(ref_point=[3, 3]))
# Plot hypervolume vs function evaluations
plot_metric_history(exp.runs[0], Hypervolume(ref_point=[3, 3]))
Out[4]:
(<Figure size 640x480 with 1 Axes>, <Axes: xlabel='Function Evaluations', ylabel='Hypervolume'>)
In [5]:
Copied!
# Plot hypervolume vs generation
plot_metric_history(exp.runs[0], Hypervolume(ref_point=[3, 3]), x_axis="generation")
# Plot hypervolume vs generation
plot_metric_history(exp.runs[0], Hypervolume(ref_point=[3, 3]), x_axis="generation")
Out[5]:
(<Figure size 640x480 with 1 Axes>, <Axes: xlabel='Generation', ylabel='Hypervolume'>)