jpata commited on
Commit
5d45649
·
1 Parent(s): f92296b

update model to 0612

Browse files
Files changed (2) hide show
  1. app.py +37 -16
  2. hf_space/models/model.ckpt +1 -1
app.py CHANGED
@@ -46,14 +46,13 @@ z_events = ak.from_parquet(os.path.join(base_path, "data/z_test_subset.parquet")
46
  qq_events = ak.from_parquet(os.path.join(base_path, "data/qq_test_subset.parquet"))
47
 
48
  def run_full_inference(events):
49
- from mltau.tools.io.ParT_dataloader import ParticleTransformerDataset
50
  from mltau.tools.io.scaling import apply_saved_input_scaling_from_cfg
51
 
52
  # Ensure output_dir is defined for scaler path resolution if needed
53
  if "output_dir" not in cfg:
54
  cfg.output_dir = base_path
55
 
56
- ds = ParticleTransformerDataset([], cfg, batch_size=256)
57
  all_preds = {}
58
  all_features = []
59
  all_masks = []
@@ -73,7 +72,7 @@ def run_full_inference(events):
73
  for i in range(0, len(events), 256):
74
  captured.clear()
75
  chunk = events[i:i+256]
76
- tensors = ds.build_tensors(chunk)
77
 
78
  # Apply scaling (it will check if enabled in cfg)
79
  tensors = apply_saved_input_scaling_from_cfg(tensors, cfg)
@@ -99,6 +98,11 @@ print("Pre-computing inference results...")
99
  z_results, z_feat, z_mask_feat, z_emb = run_full_inference(z_events)
100
  qq_results, qq_feat, qq_mask_feat, qq_emb = run_full_inference(qq_events)
101
 
 
 
 
 
 
102
  # Compute t-SNE for a subset of jets
103
  print("Computing t-SNE visualization...")
104
  n_z = min(1000, len(z_emb))
@@ -108,10 +112,8 @@ tsne_results = TSNE(n_components=2, random_state=42).fit_transform(tsne_emb)
108
  z_tsne = tsne_results[:n_z]
109
  qq_tsne = tsne_results[n_z:]
110
 
111
- # Capture decay modes for the signal subset
112
- z_dm_raw = ak.to_numpy(z_events.gen_jet_tau_decaymode[:n_z])
113
- z_dm_reduced = g.get_reduced_decaymodes(z_dm_raw)
114
- z_dm_idx = g.prepare_one_hot_encoding(z_dm_reduced)
115
 
116
  FEATURE_NAMES = [
117
  "Δη (relative to jet)", "Δφ (relative to jet)", "log(pT)", "log(energy)",
@@ -178,8 +180,7 @@ def update_scientific_plots(min_pt, max_pt, min_tot, max_tot, min_ch, max_ch, mi
178
  cm = confusion_matrix(true_dm_idx, pred_dm, labels=range(6), normalize='true')
179
 
180
  # Use descriptive labels for the 6 classes
181
- class_names = ["1p 0pi0", "1p 1pi0", "1p >=2pi0", "3p 0pi0", "3p >=1pi0", "Rare"]
182
- fig_cm = go.Figure(data=go.Heatmap(z=cm, x=class_names, y=class_names, colorscale='Viridis'))
183
  fig_cm.update_layout(
184
  title="Decay mode confusion matrix",
185
  template="plotly_white",
@@ -275,16 +276,37 @@ def plot_histogram(dataset_name, prop_key, min_val, max_val, title, xlabel):
275
  fig.update_layout(title=title, xaxis_title=xlabel, yaxis_title="Count", template="plotly_white", margin=dict(l=10, r=10, t=40, b=10), height=300, showlegend=False, yaxis2=dict(overlaying='y', visible=False, range=[0, 1]))
276
  return fig
277
 
 
 
278
  def filter_events_handler(*filters):
279
  z_mask = get_mask(z_props, *filters)
280
  qq_mask = get_mask(qq_props, *filters)
281
- z_indices = np.where(z_mask)[0].tolist()
282
- qq_indices = np.where(qq_mask)[0].tolist()
283
 
284
  status_text = f"**Event selection summary:**\n- Signal (Z): {len(z_indices)} / {len(z_events)}\n- Background (QQ): {len(qq_indices)} / {len(qq_events)}"
285
 
286
- z_update = gr.update(choices=z_indices, value=z_indices[0] if z_indices else None)
287
- qq_update = gr.update(choices=qq_indices, value=qq_indices[0] if qq_indices else None)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  return z_update, qq_update, status_text
289
 
290
  def plot_2d_jet(idx, dataset_name):
@@ -386,10 +408,9 @@ def plot_tsne():
386
  ))
387
 
388
  # Signal by decay mode
389
- class_names = ["1p 0pi0", "1p 1pi0", "1p >=2pi0", "3p 0pi0", "3p >=1pi0", "Rare"]
390
  symbols = ['circle', 'diamond', 'square', 'cross', 'x', 'triangle-up']
391
 
392
- for i, name in enumerate(class_names):
393
  mask = z_dm_idx == i
394
  if np.any(mask):
395
  fig.add_trace(go.Scatter(
@@ -403,7 +424,7 @@ def plot_tsne():
403
  xaxis_title="t-SNE dimension 1",
404
  yaxis_title="t-SNE dimension 2",
405
  template="plotly_white",
406
- height=600, width=800,
407
  legend=dict(yanchor="top", y=0.99, xanchor="right", x=0.99)
408
  )
409
  return fig
 
46
  qq_events = ak.from_parquet(os.path.join(base_path, "data/qq_test_subset.parquet"))
47
 
48
  def run_full_inference(events):
49
+ from mltau.tools.io.ParT_dataloader import build_tensors
50
  from mltau.tools.io.scaling import apply_saved_input_scaling_from_cfg
51
 
52
  # Ensure output_dir is defined for scaler path resolution if needed
53
  if "output_dir" not in cfg:
54
  cfg.output_dir = base_path
55
 
 
56
  all_preds = {}
57
  all_features = []
58
  all_masks = []
 
72
  for i in range(0, len(events), 256):
73
  captured.clear()
74
  chunk = events[i:i+256]
75
+ tensors = build_tensors(chunk, cfg)
76
 
77
  # Apply scaling (it will check if enabled in cfg)
78
  tensors = apply_saved_input_scaling_from_cfg(tensors, cfg)
 
98
  z_results, z_feat, z_mask_feat, z_emb = run_full_inference(z_events)
99
  qq_results, qq_feat, qq_mask_feat, qq_emb = run_full_inference(qq_events)
100
 
101
+ # Capture decay modes for the signal events
102
+ z_dm_raw_all = ak.to_numpy(z_events.gen_jet_tau_decaymode)
103
+ z_dm_reduced_all = g.get_reduced_decaymodes(z_dm_raw_all)
104
+ z_dm_idx_all = g.prepare_one_hot_encoding(z_dm_reduced_all)
105
+
106
  # Compute t-SNE for a subset of jets
107
  print("Computing t-SNE visualization...")
108
  n_z = min(1000, len(z_emb))
 
112
  z_tsne = tsne_results[:n_z]
113
  qq_tsne = tsne_results[n_z:]
114
 
115
+ # Use the pre-computed indices for t-SNE visualization mapping
116
+ z_dm_idx = z_dm_idx_all[:n_z]
 
 
117
 
118
  FEATURE_NAMES = [
119
  "Δη (relative to jet)", "Δφ (relative to jet)", "log(pT)", "log(energy)",
 
180
  cm = confusion_matrix(true_dm_idx, pred_dm, labels=range(6), normalize='true')
181
 
182
  # Use descriptive labels for the 6 classes
183
+ fig_cm = go.Figure(data=go.Heatmap(z=cm, x=CLASS_NAMES, y=CLASS_NAMES, colorscale='Viridis'))
 
184
  fig_cm.update_layout(
185
  title="Decay mode confusion matrix",
186
  template="plotly_white",
 
276
  fig.update_layout(title=title, xaxis_title=xlabel, yaxis_title="Count", template="plotly_white", margin=dict(l=10, r=10, t=40, b=10), height=300, showlegend=False, yaxis2=dict(overlaying='y', visible=False, range=[0, 1]))
277
  return fig
278
 
279
+ CLASS_NAMES = ["1p 0pi0", "1p 1pi0", "1p >=2pi0", "3p 0pi0", "3p >=1pi0", "Rare"]
280
+
281
  def filter_events_handler(*filters):
282
  z_mask = get_mask(z_props, *filters)
283
  qq_mask = get_mask(qq_props, *filters)
284
+ z_indices = np.where(z_mask)[0]
285
+ qq_indices = np.where(qq_mask)[0]
286
 
287
  status_text = f"**Event selection summary:**\n- Signal (Z): {len(z_indices)} / {len(z_events)}\n- Background (QQ): {len(qq_indices)} / {len(qq_events)}"
288
 
289
+ # Create descriptive labels and group signal by DM
290
+ z_choices = []
291
+ for idx in z_indices:
292
+ dm_name = CLASS_NAMES[z_dm_idx_all[idx]]
293
+ n_ch, n_nh, n_ph = z_props["n_ch"][idx], z_props["n_nh"][idx], z_props["n_photon"][idx]
294
+ label = f"[{dm_name}] {n_ch}ch, {n_nh}nh, {n_ph}ph | ID:{idx}"
295
+ z_choices.append((label, int(idx)))
296
+ # Sort by DM index, then constituent counts
297
+ z_choices.sort(key=lambda x: (z_dm_idx_all[x[1]], z_props["n_ch"][x[1]], z_props["n_photon"][x[1]]))
298
+
299
+ # Create descriptive labels and group background by constituent counts
300
+ qq_choices = []
301
+ for idx in qq_indices:
302
+ n_ch, n_nh, n_ph = qq_props["n_ch"][idx], qq_props["n_nh"][idx], qq_props["n_photon"][idx]
303
+ label = f"{n_ch}ch, {n_nh}nh, {n_ph}ph | ID:{idx}"
304
+ qq_choices.append((label, int(idx)))
305
+ # Sort by constituent counts
306
+ qq_choices.sort(key=lambda x: (qq_props["n_ch"][x[1]], qq_props["n_photon"][x[1]], qq_props["n_nh"][x[1]]))
307
+
308
+ z_update = gr.update(choices=z_choices, value=z_choices[0][1] if z_choices else None)
309
+ qq_update = gr.update(choices=qq_choices, value=qq_choices[0][1] if qq_choices else None)
310
  return z_update, qq_update, status_text
311
 
312
  def plot_2d_jet(idx, dataset_name):
 
408
  ))
409
 
410
  # Signal by decay mode
 
411
  symbols = ['circle', 'diamond', 'square', 'cross', 'x', 'triangle-up']
412
 
413
+ for i, name in enumerate(CLASS_NAMES):
414
  mask = z_dm_idx == i
415
  if np.any(mask):
416
  fig.add_trace(go.Scatter(
 
424
  xaxis_title="t-SNE dimension 1",
425
  yaxis_title="t-SNE dimension 2",
426
  template="plotly_white",
427
+ height=800, width=800,
428
  legend=dict(yanchor="top", y=0.99, xanchor="right", x=0.99)
429
  )
430
  return fig
hf_space/models/model.ckpt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:b025e95007b99e95ccca77d106f67172edb2c82444b5b6707810eb27f545cb35
3
  size 14485529
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:647985cd3ad9ca838ee3610218042f39a3de19c2488509d37184e4131a207f2a
3
  size 14485529