in parse.py [0:0]
def print_hp_table(df, aggregate=True):
hps = ["lr", "weight_decay", "epoch", "batch_size"]
hparams = df[[(hp, "mean") for hp in hps]].droplevel(1, axis=1)
hparams = hparams.apply(
{
"lr": np.log10,
"weight_decay": np.log10,
"epoch": lambda x: x,
"batch_size": lambda x: x,
}
)
if aggregate:
hparams = hparams.groupby(["dataset", "Groups", "method"]).agg(["mean", "std"])
metric = ("min_acc_te", "mean")
hparams[("min_acc_te", "min")] = (
df.groupby(["dataset", "Groups", "method"]).min()[metric] * 100
)
hparams[("min_acc_te", "max")] = (
df.groupby(["dataset", "Groups", "method"]).max()[metric] * 100
)
hparams[("min_acc_te_delta", "")] = (
hparams[("min_acc_te", "max")] - hparams[("min_acc_te", "min")]
)
else:
hparams = pd.concat([hparams, df[["min_acc_te"]]], axis=1)
hparams.columns = pd.MultiIndex.from_tuples(
[(hp, "") for hp in hps] + df[["min_acc_te"]].columns.tolist()
)
hparams = hparams.droplevel(["hparams_seed", "#HP"], axis=0)
hparams = hparams.reorder_levels(["dataset", "Groups", "method"])
# print(hparams)
hparams = hparams.sort_index()
print(convert_df_to_readable_format(hparams))
df = convert_df_to_readable_format(hparams, latex=True)
cmaps = {
"lr": "bone",
"weight_decay": "pink",
"epoch": "bone",
"batch_size": "pink",
}
groups = hparams.groupby(["dataset"])
for idx, row in hparams.iterrows():
for hp in ["lr", "weight_decay", "batch_size", "epoch"]:
cmap = cm.get_cmap(cmaps[hp])
hp_tup = (hp, "mean") if aggregate else hp
scale = {
"min": groups.get_group(idx[0])[hp_tup].min().item(),
"max": groups.get_group(idx[0])[hp_tup].max().item(),
}
max_level = {
"lr": 1 / 6,
"weight_decay": 1 / 6,
"batch_size": 1 / 6,
"epoch": 1 / 6,
}[hp]
if hp in ["weight_decay", "batch_size"]:
level = 1 - (
max_level
* (row[hp_tup].item() - scale["min"])
/ (scale["max"] - scale["min"])
)
else:
level = 1 + (
max_level
* (row[hp_tup].item() - scale["max"])
/ (scale["max"] - scale["min"])
)
color = ["{:.3f}".format(c) for c in cmap(level)[:3]]
df.loc[idx, hp] = (
"\cellcolor[rgb]{" + ",".join(color) + "}" + str(df.loc[idx, hp])
)
filename = "hp_table_mean" if aggregate else "hp_table"
df.to_latex(f"tables/{filename}.tex", multicolumn=True, multirow=True, escape=False)