Skip to content

Add distributional arithmetic prototype - #77

Open
valayDave wants to merge 3 commits into
masterfrom
codex/implement-distributional-arithmetic-library
Open

Add distributional arithmetic prototype#77
valayDave wants to merge 3 commits into
masterfrom
codex/implement-distributional-arithmetic-library

Conversation

@valayDave

Copy link
Copy Markdown
Owner

Motivation

  • Provide a small, self-contained prototype that models scalar random variables as lazy expression graphs so dependence (shared vs independent sources) is explicit.
  • Offer a minimal API for building random-variable expressions, evaluating them with reproducible particle sampling, and inspecting summary statistics and event probabilities.
  • Create a platform to iterate toward planned features such as symbolic simplifications, FFT convolution and planner-based evaluation strategies.

Description

  • Add a new distarith package (distarith/__init__.py) implementing Distribution subclasses (NormalDistribution, LogNormalDistribution, EmpiricalDistribution) and a RandomVariable expression DAG with Constant, Source, UnaryExpr, and BinaryExpr nodes.
  • Implement arithmetic and comparison operators on RandomVariable to produce lazy expression graphs and support iid()/independent_copy() to create independent copies of a source while preserving source identity by default.
  • Provide particle-based evaluation with RandomVariable.evaluate(...) / sample(...), summary helpers mean(), variance(), std(), quantile(), an EvaluationResult container, and Event/CompoundEvent semantics with the helper P(...) for probability estimation using joint samples.
  • Add convenience constructors Normal(...), LogNormal(...), Empirical(...), and unary transforms exp/log, plus type hints and basic input validation.

Testing

  • Ran python -m pytest test/unit/test_distarith.py, which executed 4 unit tests and all tests passed.
  • Ran python -m py_compile distarith/__init__.py test/unit/test_distarith.py to verify byte-compilation, which succeeded.
  • Unit tests exercise source-identity semantics (x - x), independent copies (iid()), joint-event probability evaluation (P(profit < 0)), empirical quantiles, and compound event probabilities, and all assertions passed.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant