Monte Carlo modeling in Python with probabilit (tommyodland.com)

🤖 AI Summary
probabilit is a new Python package (v0.1.0) for fast prototyping of Monte Carlo uncertainty analyses using a high‑level modeling language. It lets you build expressions from Constant and Distribution nodes (wrapping any SciPy distribution), compose transforms (Add, Power, Exp, etc.), and treat the whole setup as a lazily‑evaluated computational graph (a DAG that can be exported to networkx). Sampling is explicit — calling .sample(n, method=..., random_state=...) triggers evaluation and populates samples_ on ancestor nodes — and quasi‑Monte Carlo methods (Latin Hypercube, Sobol, Halton) are supported to reduce sampling variance. The tutorial shows practical examples: braking distance with uncertain speed and friction, multi‑year savings with lognormal returns (compound distributions), and a compound Poisson→Binomial ecology example. Key technical features and implications: direct use of SciPy distributions inside expressions, support for compound distributions where one distribution is an input to another, plotting and summary stats helpers, and Correlator objects for inducing correlations (usable both inside the modeling API and on raw numpy arrays). The package trades memory and runtime efficiency for a clean API and pedagogical clarity, so it’s best for classroom problems and prototyping rather than large production simulations. Important caveat: some correlators (e.g., Cholesky) preserve Pearson correlation but can distort marginals, so choose correlators carefully when marginal fidelity matters.
Loading comments...
loading comments...