Skip to main content

Stochtest is a Python library for performing statistical assertions on stochastic outputs.

Project description

stochtest

PyPI - Version PyPI - Python Version


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_of(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

stochtest-0.6.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stochtest-0.6.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file stochtest-0.6.1.tar.gz.

File metadata

  • Download URL: stochtest-0.6.1.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

Hashes for stochtest-0.6.1.tar.gz
Algorithm Hash digest
SHA256 5fa9b4bd482eaffe092021a6bd9af3b567ce611dc2768ee88aa1d3fc879544a3
MD5 df4921a735eba7cd238cca580eac9570
BLAKE2b-256 cfcbc6ca21c84d734726e101d108392e6f8990b78e2260032c4a27e2fd1c26f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for stochtest-0.6.1.tar.gz:

Publisher: publish.yml on MicahBrun/stochtest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stochtest-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: stochtest-0.6.1-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

Hashes for stochtest-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a6bc11a6800a24dcb772275c6913739610e0aaa4ec60d882f88baad60bd7e677
MD5 7543daeb88b3ff94634989bb5e7855c6
BLAKE2b-256 17a814b57df82d552ea32abc21edd365b1584ea46a93cdfd74c03f6e8703b6f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for stochtest-0.6.1-py3-none-any.whl:

Publisher: publish.yml on MicahBrun/stochtest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page