Skip to content

Commit

Permalink
Add plot_optima to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
kiudee committed Feb 6, 2022
1 parent 1d239a2 commit ec0e0f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tune/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ def local( # noqa: C901
plot_results(
optimizer=opt,
result_object=result_object,
iterations=np.array(performance)[:, 0],
optima=np.array(optima),
plot_path=settings.get("plot_path", plot_path),
parameter_names=list(param_ranges.keys()),
confidence=settings.get("confidence", confidence),
Expand Down
21 changes: 20 additions & 1 deletion tune/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from skopt.space import Categorical, Dimension, Integer, Real, Space
from skopt.utils import normalize_dimensions

from tune.plots import plot_objective, plot_objective_1d
from tune.plots import plot_objective, plot_objective_1d, plot_optima
from tune.summary import confidence_intervals
from tune.utils import TimeControl, confidence_to_mult, expected_ucb

Expand Down Expand Up @@ -518,6 +518,8 @@ def print_results(
def plot_results(
optimizer: Optimizer,
result_object: OptimizeResult,
iterations: np.ndarray,
optima: np.ndarray,
plot_path: str,
parameter_names: Sequence[str],
confidence: float = 0.9,
Expand All @@ -530,6 +532,10 @@ def plot_results(
Fitted Optimizer object.
result_object : scipy.optimize.OptimizeResult
Result object containing the data and the last fitted model.
iterations : np.ndarray
Array containing the iterations at which optima were collected.
optima : np.ndarray
Array containing the predicted optimal parameters.
plot_path : str
Path to the directory to which the plots should be saved.
parameter_names : Sequence of str
Expand All @@ -541,6 +547,8 @@ def plot_results(
logger.debug("Starting to compute the next plot.")
timestr = time.strftime("%Y%m%d-%H%M%S")
dark_gray = "#36393f"

# First save the landscape:
save_params = dict()
if optimizer.space.n_dims == 1:
fig, ax = plot_objective_1d(
Expand Down Expand Up @@ -569,6 +577,17 @@ def plot_results(
logger.info(f"Saving a plot to {full_plotpath}.")
plt.close(fig)

# Now plot the history of optima:
fig, ax = plot_optima(
iterations=iterations,
optima=optima,
space=optimizer.space,
parameter_names=parameter_names,
)
full_plotpath = plotpath / f"optima-{timestr}-{len(optimizer.Xi)}.png"
fig.savefig(full_plotpath, dpi=150, facecolor=dark_gray)
plt.close(fig)


def run_match(
rounds=10,
Expand Down

0 comments on commit ec0e0f1

Please sign in to comment.