MCPcopy Index your code
hub / github.com/hyperopt/hyperopt / main_plot_1D_attachment

Function main_plot_1D_attachment

hyperopt/plotting.py:176–257  ·  view source on GitHub ↗

Plots trail attachments, which are 1D-Data. A legend is only added if the number of plotted elements is < 10. :param trials: The trials object to gather the attachments from. :param attachment_name: Thename of the attachment to gather. :param do_show: If the plot should be sho

(
    trials,
    attachment_name,
    do_show=True,
    colorize_by_loss=True,
    max_darkness=0.5,
    num_trails=None,
    preprocessing_fn=lambda x: x,
    line_width=0.1,
)

Source from the content-addressed store, hash-verified

174
175
176def main_plot_1D_attachment(
177 trials,
178 attachment_name,
179 do_show=True,
180 colorize_by_loss=True,
181 max_darkness=0.5,
182 num_trails=None,
183 preprocessing_fn=lambda x: x,
184 line_width=0.1,
185):
186 """
187 Plots trail attachments, which are 1D-Data.
188
189 A legend is only added if the number of plotted elements is < 10.
190
191 :param trials: The trials object to gather the attachments from.
192 :param attachment_name: Thename of the attachment to gather.
193 :param do_show: If the plot should be shown after creating it.
194 :param colorize_by_loss: If the lines represening the trial data should be shaded by loss.
195 :param max_darkness: The maximumg shading darkness (between 0 and 1). Implies colorize_by_loss=True
196 :param num_trails: The number of trials to plot the attachment for. If none, all trials with a corresponding
197 attachment are taken. If set to any integer value, the trials are sorted by loss and trials are selected in regular
198 intervals for plotting. This ensures, that all possible outcomes are equally represented.
199 :param preprocessing_fn: A preprocessing function to be appleid to the attachment before plotting.
200 :param line_width: The width of the lines to be plotted.
201 :return: None
202 """
203 # -- import here because file-level import is too early
204 import matplotlib.pyplot as plt
205
206 plt.title(attachment_name)
207
208 lst = [l for l in trials.losses() if l is not None]
209 min_loss = min(lst)
210 max_loss = max(lst)
211
212 if num_trails is None:
213 plotted_trials = trials
214 else:
215 trials_by_loss = sorted(
216 filter(lambda t: "loss" in t["result"], trials),
217 key=lambda t: t["result"]["loss"],
218 )
219 plotted_trials = [
220 trials_by_loss[i]
221 for i in np.linspace(
222 0, len(trials_by_loss), num_trails, endpoint=False, dtype=int
223 )
224 ]
225
226 for trial in plotted_trials:
227 t_attachments = trials.trial_attachments(trial)
228 if attachment_name in t_attachments:
229 attachment_data = np.squeeze(
230 np.asanyarray(pickle.loads(t_attachments[attachment_name]))
231 )
232 if len(attachment_data.shape) == 1:
233 attachment_data = preprocessing_fn(attachment_data)

Callers

nothing calls this directly

Calls 2

lossesMethod · 0.80
trial_attachmentsMethod · 0.45

Tested by

no test coverage detected