A short tutorial on building compound (mixture) probability distributions in Python and drawing random samples from them.
Reza Ehsani & Hoshin V. Gupta
A compound PDF is a weighted mixture of standard densities:
P(x) = Σ wᵢ · pᵢ(x), with Σ wᵢ = 1, 0 < wᵢ < 1
where each pᵢ(x) is a standard PDF (Uniform, Normal, Exponential, ...). The
notebook defines a compound_distribution class on top of SciPy's
rv_continuous, so the mixture behaves like any other SciPy distribution — its
PDF, CDF, and random sampling all come for free — and walks through two worked
examples with plots.
Compound_Distribution.ipynb — the tutorial notebook:
- a
compound_distribution(rv_continuous)class that combines any list of SciPy densities under a set of weights - a
plot_compoundhelper that overlays the PDF, CDF, and a sampled histogram - Example 1 — Uniform + Normal, 10,000 samples
- Example 2 — Uniform + Normal + Exponential, 50,000 samples
Open in Colab (badge above), or run locally:
pip install numpy scipy matplotlib
jupyter notebook Compound_Distribution.ipynbNumPy, SciPy, and Matplotlib.