fix: SVD tab component 1/2 now uses compass-identical Procrustes-aligned positions; remove redundant y-axis annotations and interpretation caption

main
Sven Geboers 2 weeks ago
parent cd47fd5a83
commit fafb53cb3d
  1. 29
      explorer.py

@ -1585,22 +1585,14 @@ def build_compass_tab(db_path: str, window_size: str) -> None:
xaxis={"range": [-1, 1]}, xaxis={"range": [-1, 1]},
yaxis={"range": [-0.6, 0.6]}, yaxis={"range": [-0.6, 0.6]},
) )
_add_y_direction_annotations(fig)
with col1: with col1:
st.plotly_chart(fig, use_container_width=True) st.plotly_chart(fig, use_container_width=True)
_x_interp = axis_def.get("x_interpretation", {}).get(window_idx, "") _x_interp = axis_def.get("x_interpretation", {}).get(window_idx, "")
_y_interp = axis_def.get("y_interpretation", {}).get(window_idx, "")
if ( if (
_x_interp _x_interp
and axis_def.get("x_quality", {}).get(window_idx, 1.0) < _THRESHOLD and axis_def.get("x_quality", {}).get(window_idx, 1.0) < _THRESHOLD
): ):
st.caption(_x_interp) st.caption(_x_interp)
if (
_y_interp
and axis_def.get("y_quality", {}).get(window_idx, 1.0) < _THRESHOLD
):
st.caption(_y_interp)
# Voting discipline analysis # Voting discipline analysis
st.markdown("---") st.markdown("---")
@ -2678,13 +2670,22 @@ def build_svd_components_tab(db_path: str) -> None:
if score_list if score_list
} }
# Extract 1D scores for this component using aligned PCA scores # Extract 1D scores for this component.
# Components 1 and 2 are literally the x and y axes of the compass (Procrustes-aligned
# PCA via compute_2d_axes). Use _get_aligned_party_coords so the numbers are identical
# to what the compass shows. Components 3-10 fall back to compute_nd_axes scores.
party_1d_coords: dict = {} party_1d_coords: dict = {}
aligned_all_scores = _get_aligned_party_scores(svd_window) if comp_sel in (1, 2):
for party, all_scores in aligned_all_scores.items(): coord_idx = 0 if comp_sel == 1 else 1
idx = comp_sel - 1 # 0-indexed aligned_2d = _get_aligned_party_coords(svd_window)
if idx < len(all_scores): for party, xy in aligned_2d.items():
party_1d_coords[party] = (float(all_scores[idx]),) party_1d_coords[party] = (float(xy[coord_idx]),)
else:
aligned_all_scores = _get_aligned_party_scores(svd_window)
for party, all_scores in aligned_all_scores.items():
idx = comp_sel - 1 # 0-indexed
if idx < len(all_scores):
party_1d_coords[party] = (float(all_scores[idx]),)
# Auto-compute flip directions for ALL components 1-10 based on aligned party centroids. # Auto-compute flip directions for ALL components 1-10 based on aligned party centroids.
# Since we now use aligned PCA scores for all components, compute flip directly from # Since we now use aligned PCA scores for all components, compute flip directly from

Loading…
Cancel
Save