Stochtest is a Python library for performing statistical assertions on stochastic outputs.
Project description
stochtest
Stochtest is a Python library for performing statistical assertions on stochastic outputs (i.e. outputs described by probability distributions) using statistical methods. It enables automated testing for probabilistic code and Monte Carlo simulations.
Installation
pip install stochtest
Usage
1. Asserting Rates & Means
Use stochtest.assert_that(samples) to validate acceptance rates (proportions) or expected values (means).
import stochtest
import numpy as np
# --- Acceptance Rates (Proportions) ---
samples = np.random.normal(1000)
stochtest.assert_that(samples > 0).has_acceptance_rate_greater_than(0.4)
stochtest.assert_that(outcomes).has_acceptance_rate_between(0.45, 0.55)
# --- Expected Values (Means) ---
# Validated using one-sample Student's t-tests
returns = np.random.normal(1, 0.5, 1000)
stochtest.assert_that(returns).has_expected_value_greater_than(0.5)
stochtest.assert_that(returns).has_expected_value_between(0.9, 1.1)
2. Asserting Distributions
Use stochtest.distributions.assert_that(samples) to verify that an entire dataset matches a specific shape or theoretical distribution using a Bootstrapped Kolmogorov-Smirnov (KS) Test.
This asserts that the distributions are sufficiently similar by ensuring the KS distance is consistently within a specific margin with high confidence.
import numpy as np
import scipy.stats
import stochtest.distributions
samples = np.random.normal(0, 1, 1000)
# Assert samples follow a normal distribution (mean=0, std=1)
stochtest.distributions.assert_that(samples).has_normal_distribution(
loc=0, scale=1, margin=0.05
)
# Assert samples match a custom CDF (e.g., Uniform)
stochtest.distributions.assert_that(samples).has_distribution(
lambda x: scipy.stats.uniform.cdf(x),
margin=0.05
)
License
stochtest is distributed under the terms of the MIT license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stochtest-0.6.2.tar.gz.
File metadata
- Download URL: stochtest-0.6.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04d460bbe0d76c2dcfef9acec69912c17f5756c0eddcf23d28f17e65c027ad59
|
|
| MD5 |
da61b56ff4a5bfa40e37d282a8d4e578
|
|
| BLAKE2b-256 |
ac81a140a28ac2ffa69f20caa6dd8f8fc266e1f53e6f830957494c15997f55bf
|
Provenance
The following attestation bundles were made for stochtest-0.6.2.tar.gz:
Publisher:
publish.yml on MicahBrun/stochtest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stochtest-0.6.2.tar.gz -
Subject digest:
04d460bbe0d76c2dcfef9acec69912c17f5756c0eddcf23d28f17e65c027ad59 - Sigstore transparency entry: 768071050
- Sigstore integration time:
-
Permalink:
MicahBrun/stochtest@12fb8896711a761844b39905cb5c13d60c71a436 -
Branch / Tag:
refs/tags/v0.6.2 - Owner: https://github.com/MicahBrun
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@12fb8896711a761844b39905cb5c13d60c71a436 -
Trigger Event:
release
-
Statement type:
File details
Details for the file stochtest-0.6.2-py3-none-any.whl.
File metadata
- Download URL: stochtest-0.6.2-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a85cc725bf76dd39d795897b622edbc4aafb55b2248b0828878bd3e847639893
|
|
| MD5 |
2fbf3ac1cb839b49c591475c0f7bac87
|
|
| BLAKE2b-256 |
df86b76a3e7ad1ca25b3d88bc29ca3b8e670e85be474b9cb11a19aa64afe3feb
|
Provenance
The following attestation bundles were made for stochtest-0.6.2-py3-none-any.whl:
Publisher:
publish.yml on MicahBrun/stochtest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stochtest-0.6.2-py3-none-any.whl -
Subject digest:
a85cc725bf76dd39d795897b622edbc4aafb55b2248b0828878bd3e847639893 - Sigstore transparency entry: 768071056
- Sigstore integration time:
-
Permalink:
MicahBrun/stochtest@12fb8896711a761844b39905cb5c13d60c71a436 -
Branch / Tag:
refs/tags/v0.6.2 - Owner: https://github.com/MicahBrun
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@12fb8896711a761844b39905cb5c13d60c71a436 -
Trigger Event:
release
-
Statement type: