MCPcopy
hub / github.com/hyperopt/hyperopt / main_plot_vars

Function main_plot_vars

hyperopt/plotting.py:89–173  ·  view source on GitHub ↗
(
    trials,
    do_show=True,
    fontsize=10,
    colorize_best=None,
    columns=5,
    arrange_by_loss=False,
)

Source from the content-addressed store, hash-verified

87
88
89def main_plot_vars(
90 trials,
91 do_show=True,
92 fontsize=10,
93 colorize_best=None,
94 columns=5,
95 arrange_by_loss=False,
96):
97 # -- import here because file-level import is too early
98 import matplotlib.pyplot as plt
99
100 idxs, vals = miscs_to_idxs_vals(trials.miscs)
101 losses = trials.losses()
102 finite_losses = [y for y in losses if y not in (None, float("inf"))]
103 asrt = np.argsort(finite_losses)
104 if colorize_best is not None:
105 colorize_thresh = finite_losses[asrt[colorize_best + 1]]
106 else:
107 # -- set to lower than best (disabled)
108 colorize_thresh = finite_losses[asrt[0]] - 1
109
110 loss_min = min(finite_losses)
111 loss_max = max(finite_losses)
112 print("finite loss range", loss_min, loss_max, colorize_thresh)
113
114 loss_by_tid = dict(zip(trials.tids, losses))
115
116 def color_fn(lossval):
117 if lossval is None:
118 return 1, 1, 1
119 else:
120 t = 4 * (lossval - loss_min) / (loss_max - loss_min + 0.0001)
121 if t < 1:
122 return t, 0, 0
123 if t < 2:
124 return 2 - t, t - 1, 0
125 if t < 3:
126 return 0, 3 - t, t - 2
127 return 0, 0, 4 - t
128
129 def color_fn_bw(lossval):
130 if lossval in (None, float("inf")):
131 return 1, 1, 1
132 else:
133 t = (lossval - loss_min) / (loss_max - loss_min + 0.0001)
134 if lossval < colorize_thresh:
135 return 0.0, 1.0 - t, 0.0 # -- red best black worst
136 else:
137 return t, t, t # -- white=worst, black=best
138
139 all_labels = list(idxs.keys())
140 titles = all_labels
141 order = np.argsort(titles)
142
143 C = min(columns, len(all_labels))
144 R = int(np.ceil(len(all_labels) / float(C)))
145
146 for plotnum, varnum in enumerate(order):

Callers

nothing calls this directly

Calls 3

miscs_to_idxs_valsFunction · 0.85
lossesMethod · 0.80
keysMethod · 0.80

Tested by

no test coverage detected