Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions bayes_opt/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
from contextlib import suppress
from pathlib import Path
from typing import Any

import numpy as np
from colorama import Fore, just_fix_windows_console
Expand Down Expand Up @@ -153,15 +154,16 @@ def _step(self, instance, colour=_colour_regular_message):
-------
A stringified, formatted version of the most recent optimization step.
"""
res = instance.res[-1]
cells: list[str | None] = [None] * 4
res: dict[str, Any] = instance.res[-1]
keys: list[str] = instance.space.keys
# iter, target, allowed [, *params]
cells: list[str | None] = [None] * (3 + len(keys))

cells[:2] = self._format_number(self._iterations + 1), self._format_number(res["target"])
if self._is_constrained:
cells[2] = self._format_bool(res["allowed"])

for key in instance.space.keys:
cells[3] = self._format_number(res["params"][key])
params = res.get("params", {})
cells[3:] = [self._format_number(params.get(key, float("nan"))) for key in keys]

return "| " + " | ".join(colour + x + self._colour_reset for x in cells if x is not None) + " |"

Expand All @@ -177,14 +179,14 @@ def _header(self, instance):
-------
A stringified, formatted version of the most header.
"""
cells: list[str | None] = [None] * 4
keys: list[str] = instance.space.keys
# iter, target, allowed [, *params]
cells: list[str | None] = [None] * (3 + len(keys))

cells[:2] = self._format_key("iter"), self._format_key("target")
if self._is_constrained:
cells[2] = self._format_key("allowed")

for key in instance.space.keys:
cells[3] = self._format_key(key)
cells[3:] = [self._format_key(key) for key in keys]

line = "| " + " | ".join(x for x in cells if x is not None) + " |"
self._header_length = len(line)
Expand Down