Skip to main content

Pragmastat: Pragmatic Statistical Toolkit

Project description

Python

Install from PyPI:

pip install pragmastat==6.0.0

Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v6.0.0/py

Pragmastat on PyPI: https://pypi.org/project/pragmastat/

Demo

from pragmastat import (
    Rng,
    median,
    center,
    spread,
    rel_spread,
    shift,
    ratio,
    avg_spread,
    disparity,
    pairwise_margin,
    shift_bounds,
    ratio_bounds,
)
from pragmastat.distributions import Additive, Exp, Multiplic, Power, Uniform


def main():
    # --- Randomization ---

    rng = Rng(1729)
    print(rng.uniform())  # 0.3943034703296536
    print(rng.uniform())  # 0.5730893757071377

    rng = Rng("experiment-1")
    print(rng.uniform())  # 0.9535207726895857

    rng = Rng(1729)
    print(rng.sample([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 3))  # [6, 8, 9]

    rng = Rng(1729)
    print(rng.shuffle([1, 2, 3, 4, 5]))  # [4, 2, 3, 5, 1]

    # --- Distribution Sampling ---

    rng = Rng(1729)
    dist = Uniform(0, 10)
    print(dist.sample(rng))  # 3.9430347032965365

    rng = Rng(1729)
    dist = Additive(0, 1)
    print(dist.sample(rng))  # -1.222932972163442

    rng = Rng(1729)
    dist = Exp(1)
    print(dist.sample(rng))  # 0.5013761944646019

    rng = Rng(1729)
    dist = Power(1, 2)
    print(dist.sample(rng))  # 1.284909255071668

    rng = Rng(1729)
    dist = Multiplic(0, 1)
    print(dist.sample(rng))  # 0.2943655336550937

    # --- Single-Sample Statistics ---

    x = [1, 3, 5, 7, 9]

    print(median(x))  # 5
    print(center(x))  # 5
    print(spread(x))  # 4
    print(spread([v + 10 for v in x]))  # 4
    print(spread([v * 2 for v in x]))  # 8
    print(rel_spread(x))  # 0.8

    # --- Two-Sample Comparison ---

    x = [0, 3, 6, 9, 12]
    y = [0, 2, 4, 6, 8]

    print(shift(x, y))  # 2
    print(shift(y, x))  # -2
    print(avg_spread(x, y))  # 5
    print(disparity(x, y))  # 0.4
    print(disparity(y, x))  # -0.4

    x = [1, 2, 4, 8, 16]
    y = [2, 4, 8, 16, 32]
    print(ratio(x, y))  # 0.5
    print(ratio(y, x))  # 2

    # --- Confidence Bounds ---

    x = list(range(1, 31))
    y = list(range(21, 51))

    print(pairwise_margin(30, 30, 1e-4))  # 390
    print(shift(x, y))  # -20
    bounds = shift_bounds(x, y, 1e-4)  # Bounds(lower=-30, upper=-10)
    print(f"Bounds(lower={bounds.lower}, upper={bounds.upper})")

    x = [1, 2, 3, 4, 5]
    y = [2, 3, 4, 5, 6]
    bounds = ratio_bounds(x, y, 0.05)  # Bounds(lower=0.333..., upper=1.5)
    print(f"Bounds(lower={bounds.lower}, upper={bounds.upper})")


if __name__ == "__main__":
    main()

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

pragmastat-6.0.0.tar.gz (32.6 kB view details)

Uploaded Source

File details

Details for the file pragmastat-6.0.0.tar.gz.

File metadata

  • Download URL: pragmastat-6.0.0.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pragmastat-6.0.0.tar.gz
Algorithm Hash digest
SHA256 301188bd4f7ad0813af6720224e2cd79d5f2c63f1b413aade40d7b37f1eaa1e3
MD5 10a5752d45b35e87175f202f9cefe4b6
BLAKE2b-256 638f4d17fcb387788250a795bb17946a55d2b45c3159df8fd0c70589b75cd8b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pragmastat-6.0.0.tar.gz:

Publisher: publish.yml on AndreyAkinshin/pragmastat

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