best_dendro_corrs.append(max(dendro_corrs)) """ Plotting best & final validation losses """ if len(validation_losses) > 0: dendro_best_loss.append(min(validation_losses[1:])) simple_best_loss.append(min(simple_validation_losses[1:])) dendro_final_loss.append(validation_losses[-1]) simple_final_loss.append(simple_validation_losses[-1]) if len(dendro_best_loss) > 0: names = ['dendro_best', 'dendro_final', 'simple_best', 'simple_final'] loss_outputs = [ dendro_best_loss, dendro_final_loss, simple_best_loss, simple_final_loss ] log_aucs(os.path.join(base_output_dir, 'loss_log.txt'), loss_outputs, names) print('Done disentanglement analysis') disentanglement_metrics = { 'simple_errors': best_simple_errors, 'dendro_errors': best_dendro_errors, 'simple_correlations': best_simple_corrs, 'dendro_correlations': best_dendro_corrs, # 'simple_final_weights': simple_final_weights, # 'dendro_final_weights': dendro_final_weights } dump_dict(disentanglement_metrics, base_output_dir, name='disentanglement_metrics.csv')
roc_metrics[ls]['targets'].extend(targets) roc_metrics[ls]['dendro_preds'].extend(dendro_predictions.numpy()[:, 1]) roc_metrics[ls]['simple_preds'].extend(simple_predictions.numpy()[:, 1]) if args.baselines: _, parsimony_predictions, one_hot_predictions = baseline_experiment.retrieve_predictions() roc_metrics[ls]['parsimony_preds'].extend(np.squeeze(parsimony_predictions.numpy())[:, 1]) roc_metrics[ls]['one_hot_preds'].extend(one_hot_predictions.numpy()[:, 1]) auc_list = list() log_auc_names = list() for ls in DIVERSE_TROPHIC_LEVELS: for name in basenames: auc_list.append(aucs[ls][name]) log_auc_names.append(str(ls + '_' + name)) if len(auc_list[0]) > 0: log_aucs(os.path.join(base_output_dir, 'auc_log.txt'), auc_list, log_auc_names) print('done') if PLOT_ROC: for ls in DIVERSE_TROPHIC_LEVELS: pd_name = ls +'_roc_metrics.csv' pd.DataFrame.from_dict(roc_metrics[ls]).to_csv(pd_name) targets = roc_metrics[ls]['targets'] dendro_predictions = roc_metrics[ls]['dendro_preds'] simple_predictions = roc_metrics[ls]['simple_preds'] bin_targets = [t[1] for t in targets] dendro_fpr, dendro_tpr, _ = roc_curve(bin_targets, dendro_predictions) simple_fpr, simple_tpr, _ = roc_curve(bin_targets, simple_predictions) dendro_auc = auc(dendro_fpr, dendro_tpr)