Red Dwarf: A Pol.is-like library

   ⚫⋆✦⋆⭑⋆⋆⋆⋆⋆          PyPI - Version Run Tests Deploy Docs


A DIMensional REDuction library for reproducing and experimenting with Polis-like data pipelines.

Red dwarf stars are dim red stars. They are hard to see, but are the most common type -- the quiet 70% majority. They burn slow, using fuel efficiently, making them the longest-living stars in the universe. They'll be around until the last light, even supporting habitable planets for billions of years. If there's persistant life out there, it's likely in a long slow dance with a red dwarf.

Features

  • Loads Polis conversation data from APIs, CSV exports, or saved JSON.
  • Two pipeline implementations:
  • Polis-compatible pipeline = Legacy compatibility baseline: PCA, KMeans, and heuristic statement selection, tested against saved Polis API results within the limits below.
  • Agora enhanced pipeline = Targeted improvements to statement selection and consensus scoring, using Benjamini-Hochberg selection, effective agreement group-aware consensus, and Simes' p-value combination.
  • Alternative algorithms, aspiring for sensible defaults:
  • dimensional reduction: PaCMAP & LocalMAP
  • clustering: HDBSCAN*
  • Helpful visualizations via matplotlib
  • Planned: Plotly

Polis-compatible vs Agora enhanced

These names refer to Red-Dwarf analysis pipelines, not the Polis or Agora platforms (see the glossary). Existing Python imports remain reddwarf.implementations.polis and reddwarf.implementations.agora.

Both pipelines share the same core (PCA + KMeans by default), but differ in statement selection and consensus scoring. The Polis-compatible pipeline preserves legacy behavior for comparison; the Agora enhanced pipeline addresses the edge cases below rather than reproducing every upstream heuristic.

Feature Polis-compatible Agora enhanced
Statement selection Heuristics and fallbacks; pick_max=5 by default Benjamini-Hochberg selection; no fixed number per group
Evidence z-score thresholds and best-agree heuristic Simes combination of probability and representativeness p-values
Group-aware consensus (agree) Legacy default: prod(pa) (raw product) Top-level score: prod(pa*(1-pd))^(1/n), discounting disagreement
Output Selected statements only Ranked candidates with selected flags; moderated-out statements excluded

Here, pa and pd are smoothed agreement/disagreement probabilities per group, and n is the number of groups. The Agora enhanced pipeline's top-level group_aware_consensus is recomputed from group statistics; its smoothing differs from the default standard-mode consensus columns in statements_df, so these outputs should not be assumed interchangeable.

Selection edge cases

The Polis-compatible selector tests characterize inherited quirks. The paired pipeline tests run both public pipelines on identical synthetic votes, seed two groups, and verify matching memberships:

Case Polis-compatible behavior Agora enhanced behavior in these tests
0 agree / 20 disagree Can receive best-agree=True despite a disagreement label Selected as disagreement, with explicit agree/disagree counts and no best-agree flag
Unanimous agreement shared by both groups Equal representativeness scores can format best-agree as disagreement Labeled agreement
Pass-only or unvoted within a group Fallback can return a statement without directional votes Retained as a candidate, but selected=False; excluded from the representative-selection BH hypothesis count

Both pipelines also retain strong disagreement without an agreement headline. Red-Dwarf port bugs that dropped such results or misreported n-agree have been fixed in the Polis-compatible pipeline too; inherited quirks remain for compatibility. Consumers of the Agora enhanced pipeline's rankings must respect selected, not treat every candidate as a recommendation.

These tests show targeted improvements, not overall statistical superiority or end-to-end FDR calibration. Simes/BH guarantees depend on their assumptions; Simes combines evidence, rather than requiring both a majority and between-group distinctiveness. See also the ranker and consensus unit tests.

How Polis compatibility is tested

The small-conversation parity test recomputes results from saved votes and statement metadata, comparing against raw Polis /api/v3/math/pca2 responses saved as math-pca2.json. The two fixtures have 23 and 27 participants. Checks cover PCA, projections, group memberships, extremity, priorities, representative statements, consensus, and group-aware consensus, with numerical tolerances where appropriate.

This is a controlled comparison: PCA signs are aligned, group count and initial centers come from the API, and retained participant IDs are supplied explicitly. It does not establish automatic group-count/history parity or rerun the Clojure implementation. Live-loader tests check fetching and data compatibility, not full-pipeline parity on arbitrary live conversations.

Base clusters and eventual display buckets

The Polis platform first compresses participant projections into up to 100 base clusters by default, then discovers opinion groups from their weighted centers. This is a scaling approximation, not just a way to draw fewer dots.

Red-Dwarf currently discovers opinion groups directly from participant projections. It does not need this intermediate compression to run analysis, and keeping participants separate avoids losing that detail before group discovery. The tradeoffs are potentially more computation and no claim of matching Polis's larger-conversation results; those parity tests remain skipped.

The eventual plan is optional display buckets, created after opinion-group discovery and before export/rendering. They would reduce the number of points drawn without changing group memberships or analysis statistics. This is not implemented yet, and would not reproduce Polis's computational base clustering.

Agora enhanced roadmap: cleaner input/output APIs, improved default algorithms, reduced DataFrame complexity, and richer outputs.

Goals

Code that aspires to embody and support democratic values should be...

  • Legible. It should be explorable and auditable not just to researchers, but to as many curious citizens as possible.
  • Re-usable. It should be easily used in contexts in which its original creators did not anticipate, nor perhaps even desire.
  • Collectively stewarded. It should grow and govern itself democratically and in a plural fashion.

Roadmap

For now, see this related issue

Sponsors

Agora Citizen Network

Red Dwarf is generously sponsored by ZKorum SAS, creators of the Agora Citizen Network.

Are you or your organization eager to see more platforms and community built around democracy-supporting algorithms like these? Please consider getting in touch on Discord and supporting our continued work! (ping @patcon)

Usage

# OFFICIAL RELEASES

# For core, the Polis-compatible pipeline: PCA + K-means
# (~60MB beyond scikit-learn disk space)
pip install red-dwarf

# For additional algorithms beyond classic polis: PaCMAP, LocalMAP, HDBSCAN, etc.
pip install red-dwarf[alt-algos]

# For additional packages for visualizing plots
pip install red-dwarf[plots]

# For everything (~60MB beyond core packages)
pip install red-dwarf[all]
# pip install red-dwarf[alt-algos,plots]

See docs/notebooks/agora-demo.ipynb for the recommended quickstart using the Agora enhanced pipeline.

For the Polis compatibility baseline, see docs/notebooks/polis-implementation-demo.ipynb and the testing limits above.

screenshot of library-generated notebook screenshot of Polis-generated report
screen of the sample jupyter notebook screenshot of the polis report

Architecture

This is the generalized pipeline of Polis-like processes that we're aiming to accomodate. (See issue #53 for details.)

Get Involved

Running it for local development

  • Install python (preferrably virtual environment)
  • Install uv (python package manager) (e.g. pip install uv)
  • Install dependencies with make install-dev
  • Run make command alone to see other helpful make subcommands
  • Alternatively, run one of the ipynb notebooks; possibly replacing the install command at the top with %pip install -e ../../ to use the local source instead.

Contributing

  • Join the Polis User Group (PUG) Discord server.
  • Open a GitHub issue.
  • Submit a GitHub pull request.
  • Review the Awesome Polis directory to learn about related projects, academic papers, and other resources.
  • Use the "People" section to find other individuals and groups working in the field.

Changelog

See CHANGELOG.md.

License

MPL 2.0: Mozilla Public License 2.0 (See LICENSE)