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_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

stochtest-0.6.2.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.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

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

Hashes for stochtest-0.6.2.tar.gz
Algorithm Hash digest
SHA256 04d460bbe0d76c2dcfef9acec69912c17f5756c0eddcf23d28f17e65c027ad59
MD5 da61b56ff4a5bfa40e37d282a8d4e578
BLAKE2b-256 ac81a140a28ac2ffa69f20caa6dd8f8fc266e1f53e6f830957494c15997f55bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for stochtest-0.6.2.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.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

Hashes for stochtest-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a85cc725bf76dd39d795897b622edbc4aafb55b2248b0828878bd3e847639893
MD5 2fbf3ac1cb839b49c591475c0f7bac87
BLAKE2b-256 df86b76a3e7ad1ca25b3d88bc29ca3b8e670e85be474b9cb11a19aa64afe3feb

See more details on using hashes here.

Provenance

The following attestation bundles were made for stochtest-0.6.2-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