How jakorostami/expectation works
Project type and purpose
• Type: A Python library for sequential testing and monitoring using e-values.
• Purpose: Provide a simple API (SequentialTest) to run valid, anytime-valid statistical tests (means, proportions, quantiles, variance, conformal, confseq, etc.) on streaming or batch data.
File structure
• Top-level
• expectation/ – core package
• examples/ – demonstration notebooks
• tests/ – automated test suites
• docs/, assets/ – documentation and images
• CI config under .github/
• Submodules inside expectation/
• conformal/ – adaptive thresholds, cusum, conformal tests
• confseq/ – confidence sequences, config, implementation
• modules/ – building blocks: boundaries, martingales, e-power, hypothesis testing, order statistics, quantile tests
• parametric/ – generic t-test implementations
• seqtest/ – sequential e-testing orchestration (SequentialTest)
• utils/ – helper functions
README for additional insights
• Key API: SequentialTest(test_type, null_value, alternative)
• Workflow:
1. Instantiate test
2. Call .update(data_batch) repeatedly
3. Obtain e_value, reject_null, and e_process (cumulative evidence)
• Features: Always-valid inference, multiple test types, streaming support, easy extension
Main components
a. Client Code / User
– Jupyter notebooks, Python scripts importing expectation.SequentialTest
b. API Layer
– SequentialTest class in expectation/seqtest
c. Test-Type Modules
– Conformal (expectation/conformal)
– Confidence sequences (expectation/confseq)
– Parametric tests (expectation/parametric)
d. Core Engine / Modules
– Martingales, boundaries, e-power, hypothesis tests, order statistics, quantile tests (expectation/modules)
e. Utilities
– Helper functions (expectation/utils)
f. External Dependencies
– NumPy, SciPy, Pandas (as specified in requirements.txt)
g. Examples & Tests
– Example notebooks (examples/)
– Automated tests (tests/)
h. CI / Docs (optional)
– GitHub Actions, documentation site
Relationships and interactions
• Data flow:
User → API Layer (SequentialTest) → selects appropriate Test-Type Module → uses Core Engine modules → computes e-values and e-process → returns results to User
• Extensibility:
New test types plug into the API by implementing the same interface in expectation/modules or a new subpackage
• Utilities:
Shared by all modules for common tasks (random number generation, boundary computation)
Architectural patterns & design principles
• Modular design: each statistical test is its own subpackage
• Strategy pattern: SequentialTest dispatches to different test modules based on test_type
• Single Responsibility: modules focus on one statistical method or utility
• Plug-in architecture: easy to add new tests without touching core API