A modular Python framework for generating, analyzing, and visualizing random polynomial ensembles, including real and complex coefficients drawn from customizable distributions.
The system simulates ensembles of random polynomials, computes per-trial statistics (e.g. number of real roots, largest real gap, root angles), and provides flexible tools for summary analysis and visualization.
random-polynomials/
├── main.py # Entry point to run experiments and visualize results
├── analysis.py # Core Experiment & ExperimentResult classes
├── viz.py # Visualization utilities and dashboard API
├── polygen.py # Random polynomial generator
├── dist.py # Unified real and complex distribution library
├── polystat.py # Target functions and numerical statistics
├── requirements.txt # Python dependencies
└── README.md # This file :)
-
Clone the repository:
git clone https://github.com/generic-account/random-polynomials.git cd random-polynomials -
Create a virtual environment:
python3 -m venv .venv source .venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
main.py provides an entry point to run and visualize an experiment.
python3 main.pyBy default, it will:
- Generate random polynomials of a given degree (e.g., 30)
- Use coefficients sampled from a chosen distribution (e.g.,
Normal(0,1)) - Run a number of trials (e.g., 500)
- Compute statistics and plot visualizations
You can modify main.py or run interactively:
from polygen import Poly
from dist import Normal, ComplexNormal, Rademacher
from analysis import Experiment
from viz import Visualizer
# Define polynomial generator
poly = Poly(degree=30, dist=ComplexNormal(0, 1))
# Run experiment
exp = Experiment(poly, trials=500,
outputs=["n_real", "real_gap_max", "roots", "real_roots", "angles"])
results = exp.run(summary="basic")
# Visualize
viz = Visualizer(results)
viz.quick_summary()You’ll see output like:
Running experiment: 100%|███████████████████████| 500/500 [00:00<00:00, 950.13it/s]
Summary statistics (basic):
n_real: {'mean': 4.6, 'std': 2.1, 'min': 0.0, 'max': 10.0, 'median': 5.0}
real_gap_max: {'mean': 3.5, 'std': 1.2, 'min': 0.8, 'max': 6.7, 'median': 3.2}
and a dashboard of histograms and scatterplots on a single page.
A simple visualization API:
viz.show([
("hist", "angles"),
("hist", "real_gap_max"),
("scatter_complex", "roots"),
("scatter_real", "real_roots"),
], layout="auto", title="Custom Dashboard")- Multiple plots appear on one page
- Complex root scatterplots are automatically square
- Experiment parameters (degree, distribution, trials) appear in the title
| Distribution | Type | Description |
|---|---|---|
Normal(0,1) |
Real | Standard Gaussian |
Uniform(-1,1) |
Real | Uniform over [-1,1] |
Rademacher() |
Real | ±1 with equal probability |
Laplace(0,1) |
Real | Double-exponential |
ComplexNormal(0,1) |
Complex | Circularly symmetric complex Gaussian |
ComplexUniform(radius=1) |
Complex | Uniform in unit disk |
ComplexRademacher() |
Complex | Uniform on unit circle |
ComplexLaplace() |
Complex | Laplace-distributed real/imag parts |