From bfe37c68062b4a5b2fff763e61695cb812431903 Mon Sep 17 00:00:00 2001 From: Sven Geboers Date: Sat, 4 Apr 2026 18:19:31 +0200 Subject: [PATCH] fix: align report generation with JSON output for positive/negative separation Bug: report_per_component used scored[:args.report_top_n] which took top N by score (all positive for components with only positive scores). JSON correctly separated positive and negative poles. Fix: Use same positive/negative separation logic for report as JSON. --- scripts/generate_svd_json.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/generate_svd_json.py b/scripts/generate_svd_json.py index 3f0a293..0c55c9a 100644 --- a/scripts/generate_svd_json.py +++ b/scripts/generate_svd_json.py @@ -336,12 +336,26 @@ def main(argv: Optional[List[str]] = None) -> int: report_motion_ids.extend(report_all_ids[comp_idx]) # Build per_component for report (with more motions) + # Report needs the same positive/negative separation as JSON output report_per_component: List[List[Tuple[int, float]]] = [] for comp_idx in range(args.components): scored = comp_scores[comp_idx] scored.sort(key=lambda x: x[1], reverse=True) - report_top = scored[: args.report_top_n] - report_per_component.append(report_top) + + # Separate positive and negative + positive = [(mid, score) for mid, score in scored if score >= 0] + negative = [(mid, score) for mid, score in scored if score < 0] + + # Get top N per pole for report (same logic as JSON but more motions) + report_n_pos = args.report_top_n // 2 + report_n_neg = args.report_top_n - report_n_pos + + report_pos = positive[:report_n_pos] + report_neg = negative[:report_n_neg] + + # Combine: positive first, then negative (reversed so most negative at end) + report_combined = report_pos + list(reversed(report_neg)) + report_per_component.append(report_combined) else: # NON-EXCLUSIVE: each component selects its own top motions (original behavior)