| 124 | study.trials_dataframe().to_csv(runsummary) |
| 125 | |
| 126 | def compile_summaries(dataset): |
| 127 | tune_results_dir_this_datset = os.path.join(TUNE_RESULTS_DIR, dataset) |
| 128 | runsdir = os.path.join(TUNE_RESULTS_DIR, f"{dataset}/runs") |
| 129 | |
| 130 | csvs = [csv for csv in os.listdir(runsdir) if csv.endswith("csv") and csv != "summary.csv"] |
| 131 | |
| 132 | summary = [] |
| 133 | hparams = {} |
| 134 | for csv in csvs: |
| 135 | df = pd.read_csv(os.path.join(runsdir, csv)) |
| 136 | best_run = df.sort_values(by="value").iloc[0] |
| 137 | value = best_run.value |
| 138 | params = {k.replace("params_", ""): v for k, v in best_run.to_dict().items() if "params" in k} |
| 139 | pe, nn = csv.replace(".csv", "").split("-") |
| 140 | hparams[f"{pe}-{nn}"] = params |
| 141 | |
| 142 | sum = { |
| 143 | "pe":pe, |
| 144 | "nn":nn, |
| 145 | "value":value |
| 146 | } |
| 147 | sum.update(params) |
| 148 | |
| 149 | summary.append(sum) |
| 150 | |
| 151 | summary = pd.DataFrame(summary).sort_values("value").set_index(["pe","nn"]) |
| 152 | summary.to_csv(os.path.join(tune_results_dir_this_datset, "summary.csv")) |
| 153 | |
| 154 | print("writing " + os.path.join(tune_results_dir_this_datset, "hparams.yaml")) |
| 155 | with open(os.path.join(tune_results_dir_this_datset, "hparams.yaml"), 'w') as f: |
| 156 | yaml.dump(hparams, f) |
| 157 | |
| 158 | value_matrix = pd.pivot_table(summary.value.reset_index(), index="pe", columns="nn", values=["value"])["value"] |
| 159 | print("writing " + os.path.join(tune_results_dir_this_datset, "values.csv")) |
| 160 | value_matrix.to_csv(os.path.join(tune_results_dir_this_datset, "values.csv")) |
| 161 | |
| 162 | import matplotlib.pyplot as plt |
| 163 | fig, ax = plt.subplots() |
| 164 | ax.imshow(value_matrix) |
| 165 | ax.set_xticks(range(len(value_matrix.columns))) |
| 166 | ax.set_xticklabels(value_matrix.columns) |
| 167 | ax.set_xlabel(value_matrix.columns.name) |
| 168 | |
| 169 | ax.set_yticks(range(len(value_matrix.index))) |
| 170 | ax.set_yticklabels(value_matrix.index) |
| 171 | ax.set_ylabel(value_matrix.index.name) |
| 172 | |
| 173 | plt.tight_layout() |
| 174 | |
| 175 | print("writing "+os.path.join(tune_results_dir_this_datset, "values.png")) |
| 176 | fig.savefig(os.path.join(tune_results_dir_this_datset, "values.png"), transparent=True, bbox_inches="tight", pad_inches=0) |
| 177 | |
| 178 | if __name__ == '__main__': |
| 179 | #positional_encoders = ["theory", "direct", "cartesian3d", "grid"] # "sphericalharmonics", |