Normalize flow centers to unit direction vectors

#2
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -93,12 +93,19 @@ def process_json(json_file, background=None):
93
  if labels is None:
94
  return None, {"error":"Insufficient data for clustering."}
95
 
 
 
 
 
 
96
  img_path = draw_flow_overlay(vectors, labels, centers, background)
 
97
  stats = {
98
  "num_vectors": int(len(vectors)),
99
  "dominant_flows": int(len(centers)),
100
  "flow_centers": centers.tolist()
101
  }
 
102
  return img_path, stats
103
 
104
 
 
93
  if labels is None:
94
  return None, {"error":"Insufficient data for clustering."}
95
 
96
+ # --- Normalize flow centers to unit direction vectors ---
97
+ centers = np.array(centers)
98
+ norms = np.linalg.norm(centers, axis=1, keepdims=True) + 1e-6
99
+ centers = centers / norms
100
+
101
  img_path = draw_flow_overlay(vectors, labels, centers, background)
102
+
103
  stats = {
104
  "num_vectors": int(len(vectors)),
105
  "dominant_flows": int(len(centers)),
106
  "flow_centers": centers.tolist()
107
  }
108
+
109
  return img_path, stats
110
 
111