Skip to content

Commit 72723f6

Browse files
author
Isaac Peterson
committed
updates to analysis
1 parent bff50f3 commit 72723f6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

matsimAI/scripts/analysis.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def create_html_plot(dataset, link_flows, hour_count, title, output_html_path="s
143143
u, v = dataset.target_graph.edge_index[0][i].item(), dataset.target_graph.edge_index[1][i].item()
144144

145145
if i in sensor_idxs:
146-
edge_attrs = {"Absolute Difference": [], "Predicted Flow": [], "Target Flow": []}
146+
edge_attrs = {"Link id":[], "Absolute Difference": [], "Predicted Flow": [], "Target Flow": []}
147+
link_id = dataset.edge_mapping.inv[i]
147148

148149
for hour_idx in range(hour_count):
149150
if isinstance(link_flows, torch.Tensor):
@@ -159,6 +160,7 @@ def create_html_plot(dataset, link_flows, hour_count, title, output_html_path="s
159160

160161
abs_diff = abs(target_flow - pred_flow)
161162

163+
edge_attrs["Link id"].append(link_id)
162164
edge_attrs["Absolute Difference"].append(abs_diff)
163165
edge_attrs["Predicted Flow"].append(pred_flow)
164166
edge_attrs["Target Flow"].append(target_flow)
@@ -178,7 +180,7 @@ def create_html_plot(dataset, link_flows, hour_count, title, output_html_path="s
178180
# Build plot data
179181
sensor_edges = []
180182
normal_edges = []
181-
weight_all_hours, pred_all_hours, target_all_hours = [], [], []
183+
weight_all_hours, pred_all_hours, target_all_hours, link_id_all_hours = [], [], [], []
182184

183185
for (u, v, data) in tqdm(G_sensor.edges(data=True), desc="Processing Sensor Edges"):
184186
if "Absolute Difference" in data:
@@ -201,16 +203,19 @@ def create_html_plot(dataset, link_flows, hour_count, title, output_html_path="s
201203
weight_all_hours.append(data["Absolute Difference"])
202204
pred_all_hours.append(data["Predicted Flow"])
203205
target_all_hours.append(data["Target Flow"])
206+
link_id_all_hours.append(data["Link id"])
204207

205208
sensors_edge_source = ColumnDataSource(data=dict(
206209
x0=s_x0s, y0=s_y0s, x1=s_x1s, y1=s_y1s,
207210
mid_x=mid_x, mid_y=mid_y,
208211
weight=[w[0] for w in weight_all_hours],
209212
predicted=[p[0] for p in pred_all_hours],
210213
target=[t[0] for t in target_all_hours],
214+
link_id=[l[0] for l in link_id_all_hours],
211215
weight_all_hours=weight_all_hours,
212216
predicted_all_hours=pred_all_hours,
213217
target_all_hours=target_all_hours,
218+
link_id_all_hours=link_id_all_hours,
214219
))
215220

216221
# Normal edges (black)
@@ -250,7 +255,7 @@ def create_html_plot(dataset, link_flows, hour_count, title, output_html_path="s
250255
plot.scatter(node_x, node_y, size=.01, color="black", alpha=0.1)
251256

252257
# Hover tool
253-
tooltips = [("Abs Diff", "@weight"), ("Predicted", "@predicted"), ("Target", "@target")]
258+
tooltips = [("Link ID", "@link_id"),("Abs Diff", "@weight"), ("Predicted", "@predicted"), ("Target", "@target")]
254259
hover = HoverTool(tooltips=tooltips)
255260
plot.add_tools(hover)
256261

@@ -297,6 +302,7 @@ def create_html_plot(dataset, link_flows, hour_count, title, output_html_path="s
297302
const weights_all = source.data['weight_all_hours'];
298303
const preds_all = source.data['predicted_all_hours'];
299304
const targets_all = source.data['target_all_hours'];
305+
const link_ids_all = source.data['link_id_all_hours'];
300306
301307
const weights = [];
302308
for (let i = 0; i < mids_x.length; i++) {
@@ -306,6 +312,7 @@ def create_html_plot(dataset, link_flows, hour_count, title, output_html_path="s
306312
source.data['weight'][i] = weights_all[i][hour];
307313
source.data['predicted'][i] = preds_all[i][hour];
308314
source.data['target'][i] = targets_all[i][hour];
315+
source.data['link_id'][i] = link_ids_all[i][hour];
309316
}
310317
311318
const bin_count = 20;

0 commit comments

Comments
 (0)