feat: agent-native refactor, SVD consistency fixes, UX cleanup, mobile support

- Refactor agent_tools to atomic primitives (24 tools, delete workflows)
- Fix SVD component score inconsistency between single-window and trajectory views
  (same PCA basis, same flip handling, same active-MP filter for current_parliament)
- Fix Dutch spelling: Huidig parliament -> Huidig parlement
- Remove all decorative emojis from UI (app.py, explorer.py, analysis tabs)
- Add dark theme matching sgeboers.nl (mint accent on dark background)
- Remove browser tab favicon and Streamlit chrome (deploy button, running status)
- Remove trajectories debug UI and EMA settings (hardcoded smooth_alpha=0.35)
- Switch layout to centered for mobile readability
- Add responsive CSS for mobile (touch targets, font sizing, overflow prevention)
- Update AGENTS.md and SYSTEM_PROMPT.md with active tool instructions
- Add compound docs for SVD consistency bug
- Update tests: 214 passed, 3 skipped
This commit is contained in:
2026-05-04 21:56:40 +02:00
parent efb3a8fbd2
commit 272d839a42
33 changed files with 854 additions and 1108 deletions
@@ -0,0 +1,108 @@
---
title: "SVD time trajectory shows different scores than single-window view for same component and window"
date: 2026-05-04
module: analysis
problem_type: ui_bug
component: analysis
symptoms:
- "Party position numbers in Tijdtraject view differ from Enkel venster view for the exact same component and window"
- "Same party has opposite sign in trajectory vs single-window when theme flip is active"
- "Inconsistent numerical values break user trust in the SVD Components tab"
root_cause: logic_error
resolution_type: code_fix
severity: high
tags:
- svd
- pca
- time-trajectory
- parliamentary-explorer
- alignment
- flip
---
# SVD Time Trajectory Shows Different Scores Than Single-Window View
## Problem
In the parliamentary explorer's "SVD Components" tab, party position numbers differed between the "Enkel venster" (single window) view and the "Tijdtraject" (time trajectory) view for the SAME component and SAME window. Users comparing a specific year across the two views saw inconsistent numerical scores.
## Symptoms
- Selecting component 2, window "2023-2024" in single-window shows PVV at +0.42, but the trajectory view at the same point shows PVV at -0.15
- Signs invert for certain components when `theme["flip"]` is `True`
- The mismatch occurs even though both views claim to show the same underlying SVD component
## What Didn't Work
Initial suspicion that the difference came from Procrustes alignment or data caching issues. Checking whether `load_party_scores_all_windows_aligned()` vs `load_party_scores_all_windows()` was the culprit. However, both views were already using the same alignment path.
The real cause was subtler: the trajectory view was computing PCA over a different set of windows than the single-window view, and then ignoring the flip flag entirely.
## Solution
### Fix 1: Align trajectory PCA computation with single-window computation
In `analysis/explorer_data.py`, function `_get_aligned_trajectory_scores()`:
```python
def _get_aligned_trajectory_scores(
db_path: str, windows: List[str], n_components: int = 10
) -> Dict[str, Dict[str, List[float]]]:
from analysis.political_axis import compute_nd_axes
all_uniform_windows = get_uniform_dim_windows(db_path)
scores_by_window, _ = compute_nd_axes(
db_path, window_ids=all_uniform_windows, n_components=n_components
)
# ... rest filters to requested windows
```
**Change:** Compute PCA on **all** uniform-dim windows (matching `get_aligned_party_scores`), then filter to the requested windows. Previously, `_get_aligned_trajectory_scores()` passed only a subset of windows (excluding `_current_year`) to `compute_nd_axes()`, which produced different principal components, global mean, and flip signs.
### Fix 2: Apply theme flip in trajectory rendering
In `analysis/tabs/_rendering.py`, function `_render_svd_time_trajectory()`:
```python
idx = comp_sel - 1
flip = theme.get("flip", False)
# ...
for window in sorted_windows:
scores_by_party = party_scores_by_window.get(window, {})
for party in selected_parties:
scores = scores_by_party.get(party, [])
if scores and len(scores) > idx:
try:
score = float(scores[idx])
if flip:
score = -score
party_trajectories.setdefault(party, []).append((window, score))
except (ValueError, TypeError):
continue
```
**Change:** Added flip application to negate scores when `theme.get("flip", False)` is `True`. `_render_party_axis_chart_1d()` already did this, but `_render_svd_time_trajectory()` completely ignored the flip flag.
## Why This Works
1. **Same PCA basis**: `compute_nd_axes()` computes global PCA across all provided windows. When the single-window view used all uniform-dim windows and the trajectory view used a subset, the resulting components, mean centering, and variance explained were different. Passing the same `window_ids` to `compute_nd_axes()` guarantees identical PCA bases.
2. **Same flip handling**: The single-window view negates scores when `flip=True`. The trajectory view now does the same, ensuring both views display numerically identical values for the same (window, component, party) tuple.
## Prevention
- When multiple views display the same underlying SVD/PCA data, ensure they all call `compute_nd_axes()` with the **identical** set of window IDs
- Never apply visual transformations (like `theme["flip"]`) in one view but omit them in another — keep rendering logic symmetric
- Add a regression test that asserts `get_aligned_party_scores(window, comp)` equals `_get_aligned_trajectory_scores([window], comp)[window]` for sampled windows and components
- Document that `compute_nd_axes()` is a global operation over its input windows; any subset produces a different coordinate frame
## Related Files
- `analysis/explorer_data.py``_get_aligned_trajectory_scores()` fix (all uniform windows)
- `analysis/tabs/_rendering.py``_render_svd_time_trajectory()` fix (flip application)
- `analysis/political_axis.py``compute_nd_axes()` global PCA logic
## Related Issues
- Builds on `docs/solutions/ui-bugs/svd-compass-components-position-inconsistency.md` (consistent alignment for components 1-2)
- Builds on `docs/solutions/ui-bugs/svd-axis-pole-labels-incorrect-after-flip.md` (runtime flip mechanism)