--- file_format: mystnb --- # Larger Examples While not strictly necessary for low-lever error computation, for metrics that consider whole tracks or average over tracks, it is good to test larger example graphs. Here we provide one such example. ```{code-cell} ipython3 :tags: [remove-input] import sys sys.path.append("../../../tests") import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import ListedColormap from matplotlib.patches import Patch import examples.larger_examples as ex_graphs from traccuracy import TrackingGraph ``` ```{code-cell} ipython3 :tags: [remove-input] def get_loc(graph, node): return graph.graph.nodes[node]["t"], graph.graph.nodes[node]["y"] def plot_graph(ax, graph: TrackingGraph, color="black"): if graph.graph.number_of_nodes() == 0: return [0, 0], [0, 0] ids = list(graph.graph.nodes) x = [graph.graph.nodes[node]["t"] for node in ids] y = [graph.graph.nodes[node]["y"] for node in ids] ax.scatter(x, y, color=color) for _x, _y, _id in zip(x, y, ids): ax.text(_x + 0.05, _y + 0.05, str(_id)) for u, v in graph.graph.edges(): xs = [graph.graph.nodes[u]["t"], graph.graph.nodes[v]["t"]] ys = [graph.graph.nodes[u]["y"], graph.graph.nodes[v]["y"]] ax.plot(xs, ys, color=color) return [max(x), min(x)], [max(y), min(y)] def plot_matching(ax, matched, color="grey"): for u, v in matched.mapping: xs = [ matched.gt_graph.graph.nodes[u]["t"], matched.pred_graph.graph.nodes[v]["t"], ] ys = [ matched.gt_graph.graph.nodes[u]["y"], matched.pred_graph.graph.nodes[v]["y"], ] ax.plot(xs, ys, color=color, linestyle="dashed") def plot_matched(examples, title): gt_color = "black" pred_color = "blue" mapping_color = "grey" fig, ax = plt.subplots(1, len(examples) + 1, figsize=(5 * len(examples) + 1, 8)) for i, matched in enumerate(examples): axis = ax[i] xbounds, ybounds = plot_graph(axis, matched.gt_graph, color=gt_color) bounds = plot_graph(axis, matched.pred_graph, color=pred_color) xbounds.extend(bounds[0]) ybounds.extend(bounds[1]) plot_matching(axis, matched, color=mapping_color) axis.set_ybound(min(ybounds) - 0.5, max(ybounds) + 0.5) axis.set_xbound(min(xbounds) - 0.5, max(xbounds) + 0.5) axis.set_ylabel("Y Value") axis.set_xlabel("Time") handles = [ Patch(color=gt_color), Patch(color=pred_color), Patch(color=mapping_color), ] labels = ["Ground Truth", "Prediction", "Mapping"] ax[-1].legend(handles=handles, labels=labels, loc="center") ax[-1].set_axis_off() plt.tight_layout() fig.suptitle(title, y=1.05) ``` ```{code-cell} ipython3 plot_matched([ex_graphs.larger_example_1()], "Larger Example 1") ``` ```{code-cell} ipython3 ```