Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dashboard.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@
"plt.show()\n",
"\n",
"dashboard = ExperimentDashboard(\n",
" selected_experiment_path, \n",
" confusion_matrices, \n",
" experiment.partitions,\n",
" experiment.training_engine.graph,\n",
Expand Down
11 changes: 10 additions & 1 deletion dnotebooks/plots/confusion_matrix_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from networkx.algorithms import descendants_at_distance

from dengine.analysis import ExperimentConfusionMatrix
from dnotebooks.widgets import ExperimentGroup


def reduce_n_hop_normalized_confusion_matrices(
Expand All @@ -26,7 +27,15 @@ def reduce_n_hop_normalized_confusion_matrices(
try:
cfs = [confusion_matrices.device_view(X).confusion_matrix(normalize=True) for X in k_hop_neighbors]
except Exception:
logging.warning(f"No confusion found for {device}")
logging.warning(
f"No metric found at index {device}. "
f"This warning may be caused by aggregated experiment seeds. When loading multiple experiments via "
f"{ExperimentGroup.__name__}, node metrics for each experiment are initially aggregated by mean. "
"Different seeds are then stored internally as separate nodes in a fictitious graph. "
"If multiple experiment seeds are loaded, this warning can safely be ignored. "
"Future versions will handle this use case automatically."
)
continue
mean_cfs = reduction_fun(np.stack(cfs))
devices_n_hops_neighbors_mean_cf.append(mean_cfs)
return ExperimentConfusionMatrix(
Expand Down
1 change: 0 additions & 1 deletion dnotebooks/widgets/confusion_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
class ExperimentDashboard:
def __init__(
self,
experiment_root_path: Path,
confusion_matrices: Optional[ExperimentConfusionMatrix],
partitions: ExperimentPartitions,
graph: Graph,
Expand Down
24 changes: 18 additions & 6 deletions dnotebooks/widgets/latent_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def __init__(
D: SupervisedDataset,
activations,
labels: dict[int, str] | None = None,
labels_color: dict[int, str] | None = None,
title: str = "",
highlight_labels: set[int] | None = None,
output_directory: Path = Path('res/'),
Expand All @@ -160,16 +161,25 @@ def __init__(
self._exception_output = Output()

self._label_names = labels or {}
self._label_colors = labels_color or {}
self._data = _get_data(D)
self._labels = _get_labels(D)
self._unique_labels = np.unique(self._labels)
self._fig.canvas.mpl_connect('button_press_event', self._onclick_print_execpt)

def _label_text(self, label):
def _label_text(self, label) -> str:
if label in self._label_names:
return f"{self._label_names[label]} ({label})"
return f"{label} ({self._label_names[label]})"
return f"{label}"

def _label_color(self, label) -> Optional[str]:
is_highlighted = not self._highlight_labels or label in self._highlight_labels
if not is_highlighted:
return "gray"
if label in self._label_colors:
return self._label_colors[label]
return None

def draw(self, highlight_idx=None, img=None):
self._ax.cla()

Expand All @@ -183,11 +193,11 @@ def draw(self, highlight_idx=None, img=None):
label=self._label_text(label),
alpha=0.3 if is_highlighted else 0.08,
edgecolors="red" if (label < 0) else "none",
color="gray" if not is_highlighted else None,
color=self._label_color(label),
s=32
)

if highlight_idx is not None:
if highlight_idx is not None: # Handles onclick over a sample
self._ax.scatter(
self._embedding[highlight_idx, 0],
self._embedding[highlight_idx, 1],
Expand Down Expand Up @@ -265,7 +275,7 @@ def dump(self, *args, **kwargs):
filename = f"{self._title}.png"

self._ax.set_title(self._title)
self._fig.savefig(filename, bbox_inches="tight", pad_inches=0, transparent=True, dpi=300)
self._fig.savefig(self._output_dir / filename, bbox_inches="tight", pad_inches=0, transparent=True, dpi=300)


class UmapWidget:
Expand All @@ -274,6 +284,7 @@ def __init__(
D: SupervisedDataset,
activations,
labels: dict[int, str] | None = None,
labels_colors: dict[int, str] | None = None,
title: str = "",
highlight_labels: set[int] | None = None,
):
Expand All @@ -284,7 +295,8 @@ def __init__(
labels=labels,
title=title,
highlight_labels=highlight_labels,
output_directory=self._output_dir
output_directory=self._output_dir,
labels_color=labels_colors
)
self._dump_button = Button(description='Save all figures')
self._dump_button.on_click(self.dump)
Expand Down
6 changes: 5 additions & 1 deletion dnotebooks/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def aggregate_mean(self) -> ExperimentMetric:
devices_confusion_matrices=m0.data,
description=m0.description
)
stacked_means = np.stack([m.mean() for m in self.metrics])

metrics_mean = [m.mean() for m in self.metrics]
metrix_epoch = min([x.shape[0] for x in metrics_mean])
metrics_truncated_mean = [x[:metrix_epoch] for x in metrics_mean]
stacked_means = np.stack(metrics_truncated_mean)
return ExperimentConfusionMatrix(
devices_confusion_matrices=stacked_means,
description=m0.description,
Expand Down
Loading