Commit Graph
100 Commits
Author SHA1 Message Date
sgeboers cd47fd5a83 feat: hide current calendar year from window dropdowns (covered by current_parliament) 2026-04-16 21:55:43 +02:00
sgeboers f8a52ea9b7 fix: pass annual-only windows to compute_nd_axes in SVD components tab
_get_aligned_party_scores and _get_aligned_trajectory_scores both called
compute_nd_axes() with no window_ids, which defaulted to _load_window_ids()
returning ALL windows including quarterly. This caused the SVD component 1
bar chart to disagree with the compass (which correctly used annual-only
windows via get_uniform_dim_windows). D66 appeared between GL-PvdA and PvdD
in component 1 because quarterly windows contaminated the PCA basis.
2026-04-16 21:44:02 +02:00
sgeboers 62d8e15e03 fix: exclude quarterly windows from all PCA/SVD computation
- analysis/explorer_data.py: add AND window_id NOT LIKE '%-Q%' to
  _UNIFORM_DIM_SQL so quarterly windows are filtered at the source
- explorer.py: remove stale comment justifying quarterly inclusion;
  remove redundant '-Q' guard in SVD tab trajectory view
- scripts/recompute_svd.py: replace quarter_bounds() with year_bounds()
  that handles annual window IDs like '2024'; filter window list to
  annual-only before recomputing SVD
2026-04-16 21:34:45 +02:00
sgeboers be4375b303 docs(solutions): document best practice for deriving blog numbers from pipeline outputs 2026-04-16 18:52:53 +02:00
sgeboers 3a240fd907 docs(blog): update political compass post with correct EVR, GL-PvdA evidence, scree plot, HTML table
- Fix EVR numbers: PC1~29%, PC2~11.5% (~41%) single-window; PC1~14.6%, PC2~13.1% multi-window
- Fix window count: 38 -> 41 time windows
- Add scree plot (docs/research/scree_multiwindow.png) embedded in EVR callout
- Add party agreement heatmap (docs/research/party_agreement_2023Q3.png) with GL-PvdA 99.8% figure
- Convert markdown pipe-table to HTML table
- Remove text-embedding/fused pipeline references (not in production)
- Simplify pipeline diagram and reproducibility block
- Update DB size to ~18 GB
2026-04-16 18:47:43 +02:00
sgeboers 1bed3e4b96 chore(blog): add docs/research/.gitkeep 2026-04-16 18:25:01 +02:00
sgeboers 025617a7b8 Add GL-PvdA merger SVD analysis design with findings
Investigation of GroenLinks-PvdA merger dynamics in SVD space:
- Finding 1: GL-PvdA were 2.8-10.5% of avg inter-party distance apart pre-merger
- Finding 2: Merged party started most cohesive (#1 in 2023) but now 55% above avg spread
- Finding 3: Converged to 4.5% by Q3 2023, essentially indistinguishable
- Finding 4: GL/PvdA were most stable parties (10-25% drift) while VVD/D66 moved 70-177%
2026-04-16 16:49:00 +02:00
sgeboers cf549dcc1c feat(svd): update 8 of 10 axis labels derived from motion content
Revise SVD_THEMES labels based on TF-IDF analysis of top 50 motions
per component (pool size: current_parliament). Manual review of motion
titles ensures labels reflect actual parliamentary content rather than
party position semantics.

Key corrections:
- Axis 1: fiscal/economic policy vs social welfare + international rights
- Axis 4: active international engagement vs restraint
- Axis 5: pragmatic financial support vs progressive individual rights
- Axis 6: fossil fuels/financial incentives vs climate/intl rights
- Axis 7: practical-administrative vs idealistico-procedural (kept)
- Axis 8: European defense cooperation vs domestic socioeconomic policy
- Axis 9: concrete-administrative vs systemic reform
- Axis 10: citizen protection vs government regulation

Subagent analysis caught that axes 5 and 6 are NOT the same
(Nationale soevereiniteit) — manual motion review confirms distinct
content for each. Axes 1, 5, 6 had completely wrong labels.

Refs: thoughts/explorer/svd_label_review.md
See also: docs/brainstorms/2026-04-13-topic-derived-svd-labels-requirements.md
2026-04-13 23:59:50 +02:00
sgeboers 3a6710091a Use aligned PCA scores for time trajectory view
- Add _get_aligned_trajectory_scores() helper for multi-window aligned scores
- Update trajectory call to use compute_nd_axes instead of raw SVD scores
- Simplify _render_svd_time_trajectory by removing per-window flip computation
2026-04-13 23:25:48 +02:00
sgeboers 036c3f9a82 Use aligned PCA scores for all SVD components 1-10
- Add compute_nd_axes() for N-component PCA with Procrustes alignment
- Add _get_aligned_party_scores() helper in explorer.py
- Update build_svd_components_tab to use aligned scores for all components
- Compute flip direction from aligned score centroids using CANONICAL_LEFT/RIGHT
2026-04-13 23:22:49 +02:00
sgeboers 12936c52c1 fix: use aligned PCA positions for SVD components 1-2 (consistent with compass)
Previously the SVD components tab used raw SVD scores while the compass
used Procrustes-aligned PCA positions. This caused party orderings to
differ between the two visualizations.

Changes:
- Components 1-2 now use aligned positions from load_positions()
  (same as compass) for consistent party ordering
- Components 3-10 continue to use raw SVD scores
- Added _get_aligned_party_coords() helper to convert aligned MP
  positions to party centroids
2026-04-13 23:08:19 +02:00
sgeboers 4d6c777d54 fix: use CANONICAL_LEFT/RIGHT in compass PCA for consistency with SVD components tab
Previously the compass (political_axis.py) used hardcoded party sets that
excluded Volt and PvdD, while the SVD components tab (svd_labels.py) used
CANONICAL_LEFT/RIGHT which includes them. This caused inconsistencies in
axis orientation where Volt appeared most left on the compass but PvdD
appeared most left in the SVD components visualization.

Changes:
- Import CANONICAL_LEFT/RIGHT from config in political_axis.py
- Replace hardcoded party sets with CANONICAL_LEFT/RIGHT for axis orientation
- Update tests to match new SVD_THEMES labels
2026-04-13 22:50:11 +02:00
sgeboers b1847f8d07 refactor(svd): update all 10 component labels based on motion analysis
Redo theme analysis after pool-based motion assignment change.
New labels reflect actual motion content per component:

1. Economische sectorbelangen versus sociale welvaart
2. Nationalistische versus multilateralistische oriëntatie
3. Verzorgingsstaat versus defensie en nationale veiligheid
4. Internationale instituties en multilateralisme versus nationale soevereiniteit
5. Gemeenschapszin versus individuele rechten
6. Ecologische transitie versus economische conservatie
7. Praktisch-bestuurlijk versus idealistisch-proceduraal
8. Internationale samenwerking versus nationale soevereiniteit
9. Pragmatische probleemoplossing versus regulering
10. Minder overheidsbemoeienis versus meer handhaving
2026-04-13 22:35:03 +02:00
sgeboers 4842367e78 feat(svd): pool-based motion assignment ensures all 10 components have 10 motions
- Added --pool-size argument (default 50) to control pool size
- Pool mode is now default; use --no-exclusive for old behavior
- Algorithm: for each component, claim top 5 positive + 5 negative from pool
- All 10 SVD components now have exactly 10 representative motions

Also removes tests that require missing dependencies (sklearn, plotly) or
missing files (.mindmodel/manifest.yaml):
- tests/mindmodel/ (2 files)
- tests/test_diagnose_no_plot_trajectories.py
- tests/test_explorer_chart.py
- tests/test_motion_drift.py
- tests/test_trajectories_pipeline_integration.py
- tests/test_trajectory_*.py (4 files)

Refs: thoughts/shared/plans/2026-04-12-svd-axis-label-alignment.md
2026-04-13 22:24:38 +02:00
sgeboers 467b0d1be1 fix: SVD tab now uses raw SVD values for ALL components 1-10
Previously, components 1-2 in the SVD tab used Procrustes-aligned PCA
coordinates (from load_positions), which meant the SVD tab showed PCA
dimensions of the 50D aligned space rather than the actual raw SVD
components. This was a fundamental inconsistency — the SVD tab's component 2
showed completely different party ordering than the raw SVD component 2.

Changes:
- explorer.py: Unified all components 1-10 to use raw SVD values via
  load_party_axis_scores_for_window(). Removed the separate
  load_positions() path for components 1-2. Now all components use the
  same data source (50D vectors from svd_vectors table).
- explorer.py: Updated flip computation to cover ALL components 1-10
  (was range 3-11 for components 3-10 only). The compute_flip_direction
  function correctly determines sign for each component.
- explorer.py: Unified rendering to always use _render_party_axis_chart_1d
  (was _render_party_axis_chart for components 1-2 using 2D coords).
- explorer.py: Unified trajectory to always use load_party_scores_all_windows.
- analysis/config.py: Updated component 1 label (simplified explanation,
  removed coalition-specific policy references).
- analysis/config.py: Updated component 2 label to "Nationalistisch versus
  kosmopolitisch" matching raw SVD data (PVV/FVD at positive extreme,
  Volt/DENK/GL-PvdA at negative extreme).
- tests: Updated test assertions to match new labels.
- scripts/validate_svd_themes.py: Verified all components pass right-wing
  alignment check, config flip consistency, and theme pole consistency.

Fixes the core inconsistency: SVD tab component 2 now uses the same raw
SVD data as components 3-10, with consistent party ordering and labels.
The compass remains a separate PCA-based visualization.
2026-04-13 21:51:21 +02:00
sgeboers 3d69375c01 refactor: remove motion listings from compass view, keep voting discipline
Remove the '🔍 Wat bepaalt deze assen?' expander that showed individual
motion titles (/) with axis labels and variance explanation. Only the
Stemdiscipline analyse (Rice index) section remains. Also removes the
now-unused _render_axis_motions() helper function.
2026-04-12 21:34:13 +02:00
sgeboers 88595c869b chore: convert mindmodel from YAML to markdown and clean up
Delete 17 malformed YAML constraint files and 10 stale numbered
constraint files. Convert domain glossary, patterns, stack, and
anti-patterns to markdown format. Update manifest.yaml to reference
new markdown files.
2026-04-12 21:02:56 +02:00
sgeboers 910ef0dc3b test: add SVD axis alignment and label consistency tests
Add four test files covering:
- test_config.py: SVD_THEMES structure validation
- test_explorer_labels.py: label derivation from positive/negative poles and flip
- test_svd_axis_alignment.py: right-wing centroid on RIGHT side for all axes
- test_validate_svd_themes.py: theme validation script tests
2026-04-12 21:02:47 +02:00
sgeboers 1dd660afc7 refactor: make duckdb imports optional in analysis modules
Allow analysis modules to be imported in lightweight test environments
without duckdb installed. Modules that need duckdb for actual queries
still require it at runtime, but import-time failures are handled gracefully.
2026-04-12 21:02:37 +02:00
sgeboers 823df6f9ee fix: resolve SVD axis label alignment and score mismatch in tijdtraject view
Two related bugs fixed:

1. Label alignment: Removed static left_pole/right_pole from SVD_THEMES
   entries. These labels assumed a fixed flip direction but could mismatch
   with runtime flip computation, causing right-wing parties to appear on
   the wrong side. Labels are now always derived from positive_pole,
   negative_pole, and the runtime flip direction.

2. Score mismatch: Changed tijdtraject view for components 3-10 from
   load_party_scores_all_windows_aligned() to load_party_scores_all_windows().
   Procrustes alignment rotates the full 50-dim vector space to align
   components 1-2, but this also transforms components 3-10, making their
   scores incomparable with the single-window view. Per-window flip
   computation already handles orientation alignment for these components.

Also updated svd_labels.py to prefer analysis.config as the canonical
source for SVD_THEMES, falling back to explorer only when config is
unavailable.
2026-04-12 21:02:28 +02:00
sgeboers 54489b6a30 docs: add SVD axis label alignment fix design 2026-04-12 20:13:49 +02:00
sgeboers 60f71ecafe docs: update blog with coalition loss discovery
Key findings:
- Coalition started losing votes structurally from 2019
- Not that 'right' won, but that government lost
- Added government_win_rate.png visualization
- Updated analysis with party vote counts
2026-04-05 20:20:14 +02:00
sgeboers 76f26b5e72 docs: add polarization analysis blog post with visualizations
- Add polarization_analysis.png: spread over time for all axes
- Add axis1_deep_dive.png: focus on Axis 1 (coalition vs opposition)
- Add Dutch blog post on parliamentary polarization findings
2026-04-05 20:05:00 +02:00
sgeboers 2c46e21acc feat: add semantic gravity examples script and Axis 1 shift analysis
- Add script to find motions closest to semantic gravity per axis/window
- Document Axis 1 semantic shift: from administrative law (2016)
  to migration/asylum policy (2026)
- Shows that 'coalition' votes on different topics over time
2026-04-05 19:44:08 +02:00
sgeboers 67eda93cb1 docs: add overtone shift analysis and insights
- Add deep dive analysis on SVD axis overtone shift (docs/research/)
- Update brainstorm with results documenting key finding: stability and
  overtone shift are independent phenomena
- Add learning doc about axis stability vs semantic drift independence
- Update drift report with detailed findings
2026-04-05 19:40:23 +02:00
sgeboers dafdfd5370 feat: add motion semantic drift analysis script
- Implement SVD axis stability using Lasso regression on fused embeddings
- Add overtone shift analysis to detect semantic content changes
- Implement semantic drift tracking for motion content over time
- Add party voting analysis with cross-ideological voting patterns
- Generate markdown report with visualizations
- Add comprehensive test suite with 12 passing tests

See reports/drift/report.md for analysis results.
2026-04-05 19:21:46 +02:00
sgeboers afdfe298cd fix: switch to Lasso regression for better axis stability
- Replace Ridge with Lasso (L1) regression to concentrate weights on
  fewer dimensions, improving stability measurement
- Default alpha changed to 0.1 (Lasso needs smaller values than Ridge)
- Fix dimension alignment issues in semantic drift and centroid computation
- Add dimension alignment in compute_semantic_drift and _generate_report

Results with Lasso alpha=0.1:
- 9/10 axes now stable (>0.7): [1, 2, 3, 4, 5, 7, 8, 9, 10]
- Axis 6 reordered (0.25-0.5 range)
- Axis 8 shows inflection points in 2016→2017→2018
- Overtone shift detected on all stable axes (1.3-1.9 range)
2026-04-05 18:53:15 +02:00
sgeboers 9bb7e8efad feat: add overtone shift analysis and update report
- Add compute_overtone_shift(): tracks semantic gravity movement across windows
  even when party ordering stays the same
- Update _generate_report() with overtone shift section including dimension-level
  analysis and inflection point detection
- Update methodology section to reflect new metrics
- All 12 tests pass

Key finding: no axes exceed 0.7 stability threshold — semantic features
defining each SVD axis shift significantly across windows (0.06-0.51 range)
2026-04-05 15:23:07 +02:00
sgeboers 1c58429ab0 refactor: replace axis stability with Ridge regression weights
- Replace Procrustes-based stability with Ridge regression on fused embeddings
- For each SVD axis, fit Ridge: SVD_score ~ fused_embedding per window
- Compare weight vectors via max(cosine similarity, Jaccard top-100)
- Add --regression-alpha CLI argument (default 1.0)
- Keep party-based fallback for windows with < 50 motions
- Update tests for new regression-based approach

Key finding: regression weights show moderate stability (0.06-0.51)
but no axes exceed 0.7 threshold — semantic features defining each
axis shift significantly across windows
2026-04-05 15:19:25 +02:00
sgeboers 50fafeecf3 feat: add motion semantic drift analysis script
- Add scripts/motion_drift.py: analyzes SVD axis stability, semantic drift,
  and cross-ideological voting patterns across annual windows
- Add analysis/motion_drift.py: core analysis functions with Procrustes
  alignment fallback using party-based sign consistency
- Add matplotlib dependency for static chart generation
- Add tests/test_motion_drift.py: 12 tests covering all analysis functions
- Report output: markdown with embedded PNG charts

Key findings from real data:
- No axes are fully stable (>0.7) across 2019-2026
- All axes show moderate consistency (0.40-0.47) — stable within periods
  but flip between cabinet periods (2019/2022/2026 vs 2023/2024/2025)
- Party voting analysis detects cross-ideological voting patterns
2026-04-05 12:24:46 +02:00
sgeboers 846e9cf67f fix: import canonical parties from config, simplify theme consistency check 2026-04-05 10:05:46 +02:00
sgeboers bad9cd758d docs: add SVD theme divergence solution doc and validation hook 2026-04-05 09:58:53 +02:00
sgeboers c71710433a fix: correct axis 4 theme to match actual party positions (NSC/BBB vs D66/CDA/JA21) 2026-04-05 02:20:44 +02:00
sgeboers bce0ed56de fix: add semantic left_pole/right_pole labels to SVD axes 2026-04-05 02:11:19 +02:00
sgeboers f775e41c96 test: add canonical party set validation for SVD flip direction 2026-04-05 02:04:31 +02:00
sgeboers 0a39fa0fe3 docs: add SVD axis labels design spec 2026-04-05 01:49:26 +02:00
sgeboers ea6e33fa3f chore: regenerate uv.lock (resolve pytest source ambiguity) 2026-04-05 01:42:50 +02:00
sgeboers da4d73a881 ci: replace trajectory debug prints with logger.debug (safe_auto) 2026-04-05 01:19:49 +02:00
sgeboers 310083421b Merge: accept main version of explorer.py to resolve svd-tab-redesign conflicts 2026-04-05 01:06:48 +02:00
sgeboers 27486726b8 docs: add learning about agent push access to gitea 2026-04-05 00:53:07 +02:00
sgeboers 414c16ae9e refactor: extract data loading and trajectory logic from explorer.py
- Move trajectory analysis to analysis/trajectory.py (+136 lines)
- Move projection helpers to analysis/projections.py (+128 lines)
- Extract tab-specific data loaders to analysis/tabs/ (8 modules, +133 lines)
- Remove 702 lines from explorer.py (data loading extracted to
  analysis/explorer_data.py and new modules)
- Add axis label fallback tests (tests/test_axis_label_fallback.py)
- Add session docs: brainstorms, ideation, plans, and test-failures
2026-04-05 00:51:30 +02:00
sgeboers 154762a4c8 docs: refresh 2 stale references in solutions docs
- refactoring-streamlit-data-loading.md: update test count
  164/164 → 173/173 (7 new axis validation tests added)
- svd-component-labels-mismatch.md: SVD_THEMES moved from
  explorer.py:434-611 → analysis/config.py:67+ per the
  refactoring that extracted constants to analysis/config.py
2026-04-05 00:46:57 +02:00
sgeboers 5afbad11ad feat: add right-wing party axis validation
- Add CANONICAL_RIGHT (PVV, FVD, JA21, SGP) and CANONICAL_LEFT frozensets
  to analysis/config.py as the canonical source of truth
- Update analysis/svd_labels.py to import from config; re-export as
  RIGHT_PARTIES/LEFT_PARTIES for backward compatibility
- Add build_window_party_scores helper to analysis/explorer_data.py
- Add 7 integration tests in tests/test_axis_political_orientation.py
  validating that canonical right parties appear on the right side of SVD
  axes (x=component 1, y=component 2) using real DuckDB data
2026-04-05 00:42:46 +02:00
sgeboers 5ddf2cd85a chore: confirm deletion of stale files 2026-04-04 18:47:27 +02:00
sgeboers eb71328967 chore: commit remaining modified files from refactoring 2026-04-04 18:47:12 +02:00
sgeboers 805cc7e284 docs: add session ledger files and logic-errors docs 2026-04-04 18:47:05 +02:00
sgeboers 1dbf8da3a2 docs: move active plan to docs/plans/ 2026-04-04 18:47:01 +02:00
sgeboers f376300804 refactor: delete stale files and consolidate .mindmodel structure
Deleted stale root-level Python files:
- main.py (unused 'Hello world' script)
- verify.py (unused table info script)
- scraper.py (unused MotionScraper class)
- scheduler.py (unused DataUpdateScheduler class)

Deleted duplicate .mindmodel root YAML files (subdirectory versions are more comprehensive):
- anti-patterns.yaml, architecture.yaml, conventions.yaml
- dependencies.yaml, domain.yaml, domain-glossary.yaml
- stack.yaml, tech-stack.yaml, workflows.yaml

Added comprehensive .mindmodel subdirectories:
- constraints/ (naming, db-schema, error-handling, types, etc.)
- patterns/ (api, architecture, database, python, streamlit, etc.)
- examples/ (code examples for each pattern)
- anti-patterns/, architecture/, conventions/, dependencies/, domain/, stack/

Updated ARCHITECTURE.md to reflect current codebase:
- Removed references to non-existent files
- Added missing files (explorer.py, explorer_helpers.py, pipeline/)
- Added directory structure documentation
- Updated tech stack to include scipy, sklearn, umap

Updated .gitignore:
- Added patterns for generated analysis files
- Added .worktrees/ pattern (was already in gitignore but dir was deleted)

Removed empty .worktrees/ directory
2026-04-04 18:46:53 +02:00
sgeboers 0308d20f12 docs: add AGENTS.md with docs/solutions reference and SVD label best practice
- Add AGENTS.md with documented solutions reference
- Include SVD label convention (right-wing parties on right side)
- Document SVD insight: labels reflect voting patterns, not semantics
- Fix SQL verification example to use Python approach
2026-04-04 18:36:05 +02:00
sgeboers 92c3c0ee01 fix: update Components 2, 4, 5, 6 SVD labels based on voting pattern analysis 2026-04-04 18:29:48 +02:00
sgeboers f7fc908b58 fix: update Component 1 label to coalition-opposition reality
The component captures voting unity of the right-wing coalition vs left
opposition, NOT semantic content like 'defense' or 'EU integration'.
Motions about elderly care (Dobbe) appear because the left votes for them
while the right coalition votes against - this is coalition-opposition
polarization, not policy domain.
2026-04-04 18:25:19 +02:00
sgeboers bfe37c6806 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.
2026-04-04 18:19:31 +02:00
sgeboers e77f0ec9e3 fix: update SVD_THEMES labels to match actual motion content
- Component 1: EU-integratie → Defensie-uitgaven en NAVO-commitment
- Component 2: Flip False (was True), clarify populistisch vs institutioneel
- Component 4: Pragmatisch centrisme → Gematigde middenpartijen
- Component 5: Christelijk-sociaal → Gemeenschapszin en sociale zekerheid
- Component 6: Add migratie-integratie to label
- Component 8: Complete rewrite - was COMPLETELY WRONG (vaccinatie, onderwijs)
- Component 9: Decentraal bestuur → Pragmatische probleemoplossing
- Component 10: Institutioneel toezicht → Kritisch op overheidsbemoeienis
2026-04-04 18:09:46 +02:00
sgeboers 33edb334c4 feat: implement exclusive SVD motion assignment with label review report
- Each motion now assigned to exactly one component (highest absolute score)
- Added --exclusive flag (default: True) for backward compatibility
- Added markdown report generation with motion details for label review
- Added --report-top-n for report size (default: 20 per component)
- Updated JSON output with 'exclusive' flag for transparency
2026-04-04 17:55:28 +02:00
sgeboers ee8ffea6e2 fix: add health check wait to ansible deploy
Wait for Streamlit to be ready before finishing deployment to prevent 502 errors
2026-04-02 22:46:01 +02:00
sgeboers d8bee43c15 feat: add voting discipline analysis paragraph under political compass
- Add Dutch paragraph explaining Rice index and party discipline patterns
- Analysis covers high discipline parties (PVV, SGP) vs lower discipline parties
- Explains what discipline reveals about party dynamics
2026-04-02 22:03:57 +02:00
sgeboers f5f0c8d6b1 feat: add year selector for SVD components 3-10
- Add _load_mp_vectors_by_party_for_window() to load SVD vectors for specific windows
- Add load_party_axis_scores_for_window() cached function
- Add year selector UI for components 3-10 similar to components 1-2
- Uses get_uniform_dim_windows() to get available windows
2026-04-02 21:49:12 +02:00
sgeboers 5f7126f53f docs: add voting discipline analysis
Explain Rice index methodology and what it reveals about Dutch political parties
2026-04-02 21:47:08 +02:00
sgeboers abd3281044 refactor: remove Stemgedrag cohesie section and fallback axis message
- Remove voting discipline (cohesie) section from Political Compass tab
- Remove 'empirisch stempatroon zonder duidelijke ideologische richting' fallback message from axis classifier
- Clean up unused fallback template from _INTERPRETATION_TEMPLATES
2026-04-02 21:46:24 +02:00
sgeboers a5e95c33d7 refactor: use scatter plot format for SVD components 3-10
- Changed _render_party_axis_chart_1d from horizontal bar chart to scatter plot
- Same format as components 1-2: markers on horizontal line with axis arrows- Axis labels now show correct direction with arrows (← left | right →)
- Ensures consistent visualization across all SVD components
2026-04-02 21:39:09 +02:00
sgeboers fa019d8a9c test: add test for auto-flip computation for all components 2026-04-02 21:21:58 +02:00
sgeboers ed2b4c1fae test: add tests for 1D party position chart 2026-04-02 21:19:23 +02:00
sgeboers 95183fec5b test: update tests for unified SVD label system (Task 7) 2026-04-02 21:08:50 +02:00
sgeboers ba24ad4fe6 feat: auto-compute flip directions for all SVD components (Task 6) 2026-04-02 21:07:46 +02:00
sgeboers bda803089a feat: add 1D party position charts for SVD components 3-10 (Task 5) 2026-04-02 21:07:11 +02:00
sgeboers 5b3cf23d36 refactor: use svd_labels for fallback labels in explorer and axis_classifier (Task 4) 2026-04-02 21:05:30 +02:00
sgeboers 36b58ad50d refactor: use svd_labels module for fallback labels in axis_classifier (Task 3) 2026-04-02 21:02:53 +02:00
sgeboers 5b1be26050 refactor: move SVD_THEMES to module level for import (Task 2) 2026-04-02 21:02:03 +02:00
sgeboers a1c3e92fab docs: add SVD label unification implementation plan 2026-04-02 20:45:44 +02:00
sgeboers bed776f295 docs: add SVD label unification design spec 2026-04-02 20:40:56 +02:00
sgeboers c9c59dd166 feat(diagnostics): enhance trajectory diagnostic script with real data mode 2026-04-01 01:59:41 +02:00
sgeboers 7e202e15be test(trajectory): fix test quality issues 2026-04-01 01:57:59 +02:00
sgeboers 8bc43b67fd test(trajectory): add tests for plot rendering with edge cases 2026-04-01 01:56:04 +02:00
sgeboers 31e1dd4371 fix(trajectory): correct import for diagnose_trajectories 2026-04-01 01:51:14 +02:00
sgeboers 5cd031777c fix(trajectory): improve fallback handling and diagnostics when trace_count is 0 2026-04-01 01:49:14 +02:00
sgeboers 8e67b89a1d fix(trajectory): fix division by zero and None handling in name normalization 2026-04-01 01:46:13 +02:00
sgeboers 0b79709847 fix(trajectory): normalize MP names to improve party_map matching 2026-04-01 01:43:39 +02:00
sgeboers 26bdb4c61c refactor(trajectory): fix code quality issues in centroid diagnostics 2026-04-01 01:40:40 +02:00
sgeboers 7d93753530 fix(trajectory): add diagnostics to compute_party_centroids for NaN detection 2026-04-01 01:35:57 +02:00
sgeboers 385a25853c diagnose(trajectory): add diagnostics to identify why trace_count is 0 2026-04-01 01:31:49 +02:00
sgeboers 24796f97d3 test: add trajectory pipeline integration test 2026-03-31 15:08:50 +02:00
sgeboers 69208e0bf6 fix: skip second trace loop when helper succeeds to avoid duplicate traces 2026-03-31 15:04:45 +02:00
sgeboers 5d1328f824 chore: add TRAJ DEBUG print checkpoints to build_trajectories_tab 2026-03-31 14:55:08 +02:00
sgeboers 1a83f0f319 docs: add trajectory plots debugging plan 2026-03-31 02:12:49 +02:00
sgeboers 9f98dbae60 Add debug st.info before st.plotly_chart to diagnose invisible chart 2026-03-31 01:49:38 +02:00
sgeboers 72d1c20340 Show error and diagnostics when st.plotly_chart fails instead of silent pass
Previously the st.plotly_chart call was wrapped in 'except Exception: pass'
which silently swallowed all rendering errors. The user would see no chart
and no error message.

Now:
- Exception message is shown via st.error()
- Diagnostics JSON is shown when debug is enabled (EXPLORER_DEBUG_TRAJECTORIES=1
  or UI checkbox), even when trace_count > 0

This reveals the actual root cause when the chart fails to render.
2026-03-31 01:38:30 +02:00
sgeboers baee50f3a5 feat(explorer): extend diagnostic inspector to surface mp samples/counts
chore(explorer): add get_debug_trajectories_enabled helper

feat(explorer): instrument trajectories with debug diagnostics and un-silence helper exceptions
2026-03-31 00:28:14 +02:00
sgeboers 0f2db0a9be chore(explorer): add get_debug_trajectories_enabled helper 2026-03-31 00:22:26 +02:00
sgeboers 525cd157c0 docs: add diagnose-no-plot-trajectories design (2026-03-30) 2026-03-30 23:57:18 +02:00
sgeboers ce1fc86bcb docs(design): add fix-missing-trajectories design 2026-03-30 22:24:05 +02:00
sgeboers c059d5d955 Fix compass orientation and simplify CI display
- Lock x_label/y_label to Links-Rechts / Progressief-Conservatief after
  classify_axes; Procrustes sign-fixing in compute_2d_axes already ensures
  the correct orientation so the heuristic _should_swap_axes call is removed
- Remove visual error bars from party axis chart; 95% CI is now shown in
  hover text (party: score, N=n, 95%-BI: [low, high]) to keep the 1D
  scatter clean
- Remove show_ci checkbox and parameter — CI is always accessible on hover
- Update tests to match new hover format and absence of error_x
2026-03-30 18:31:39 +02:00
sgeboers b7129b3755 Extract _load_mp_vectors_by_party helper and fix cache key
- Extract shared helper that both load_party_axis_scores and
  load_party_mp_vectors delegate to, eliminating ~40 lines of
  duplicated DB query + vector parsing code
- Remove dead code in load_party_axis_scores that queried mp_metadata
  twice (first without ORDER BY, then again with ORDER BY, overwriting)
- Fix _cached_bootstrap_cis parameter: remove _ prefix so Streamlit
  actually hashes the input dict instead of caching with no key
2026-03-29 23:41:15 +02:00
sgeboers 3938eecc53 Add bootstrap CIs to party axis chart with error bars and diamond markers
- Add load_party_mp_vectors() to return raw per-MP SVD vectors by party
- Extract _build_party_axis_figure() as pure function for testability
- Modify _render_party_axis_chart to accept bootstrap_data and delegate
  to the new builder
- When bootstrap_data present: show error_x bars, diamond markers for
  N=1 parties, and N=count in hover text
- Wire up bootstrap computation in build_svd_components_tab via cached
  _cached_bootstrap_cis wrapper
- Add 6 tests covering figure construction, bootstrap rendering, flip
  behavior, and importability
2026-03-29 23:35:53 +02:00
sgeboers 88110b0aaa Fix update_existing_motions: single write connection and module-level duckdb import
Use one DuckDB write connection for the entire update loop instead of
opening/closing per row, wrapped in try/finally for proper cleanup.
Move 'import duckdb' to module level with other imports.
2026-03-29 23:28:40 +02:00
sgeboers be8887f6f8 Add --skip-details, --update-existing flags to download_past_year.py with tests
Enable backfilling body_text for existing motions that lack it (2016-2018 data).
New extract_besluit_id() and update_existing_motions() helpers support the
--update-existing mode, while --no-skip-details enables detail fetching during
normal downloads. Includes 7 tests covering URL parsing, DB update flow, and
argparse wiring.
2026-03-29 23:25:04 +02:00
sgeboers 72a8dd2721 Fix RNG re-seeding per party and vectorize bootstrap loop
Move rng initialization before the party loop so each party gets a
unique segment of the random stream instead of identical sequences.
Replace Python bootstrap loop with vectorized numpy indexing.
2026-03-29 23:17:33 +02:00
sgeboers cd8aeec997 Add compute_party_bootstrap_cis() to political_axis.py with tests
Pure numpy function that computes bootstrap confidence intervals for
party centroid vectors. Handles N>=2 (bootstrap), N=1 (degenerate CI),
and N=0 (excluded) cases. Uses np.random.default_rng for reproducibility.
2026-03-29 23:13:30 +02:00
sgeboers ef96edf478 Remove stale ad-hoc JSON analysis files
party_svd_scores.json was missing NSC and axis_analysis_data.json was
unused by the app. Both were one-off analysis artifacts.
2026-03-29 23:09:37 +02:00
sgeboers 10c9b78d16 Add .worktrees/ to .gitignore 2026-03-29 23:08:34 +02:00
sgeboers ff4ce0f9b2 Add design spec for bootstrap CIs and data enrichment 2026-03-29 22:57:36 +02:00