Skip to main content

Pragmastat: Pragmatic Statistical Toolkit

Project description

Python

Install from PyPI:

pip install pragmastat==8.0.0

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

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

Demo

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


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

    rng = Rng("demo-uniform")
    print(rng.uniform())  # 0.2640554428629759
    print(rng.uniform())  # 0.9348534835582796

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

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

    rng = Rng("demo-resample")
    print(rng.resample([1, 2, 3, 4, 5], 7))  # [5, 1, 1, 3, 3, 4, 5]

    # --- Distribution Sampling ---

    rng = Rng("demo-dist-uniform")
    dist = Uniform(0, 10)
    print(dist.sample(rng))  # 6.54043657816832

    rng = Rng("demo-dist-additive")
    dist = Additive(0, 1)
    print(dist.sample(rng))  # 0.17410448679568188

    rng = Rng("demo-dist-exp")
    dist = Exp(1)
    print(dist.sample(rng))  # 0.6589065267276553

    rng = Rng("demo-dist-power")
    dist = Power(1, 2)
    print(dist.sample(rng))  # 1.023677535537084

    rng = Rng("demo-dist-multiplic")
    dist = Multiplic(0, 1)
    print(dist.sample(rng))  # 1.1273244602673853

    # --- Single-Sample Statistics ---

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

    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

    # --- One-Sample Bounds ---

    x = list(range(1, 11))

    print(center(x))  # 5.5
    bounds = center_bounds(x, 0.05)  # Bounds(lower=3.5, upper=7.5)
    print(f"Bounds(lower={bounds.lower}, upper={bounds.upper})")

    # --- Two-Sample Bounds ---

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

    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-8.0.0.tar.gz (35.0 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for pragmastat-8.0.0.tar.gz
Algorithm Hash digest
SHA256 9fa7f783bde45c69511166ae2703ad1adbcb1c47963989154d3b073b23a5faed
MD5 cc033993699e0dc992677b5ccfb4f829
BLAKE2b-256 d93899b2d052703b1e6915b34ae22f21be5974cde325a4de8be407c27a670a32

See more details on using hashes here.

Provenance

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