Skip to main content

A Python package for measure-theoretic probability theory.

Project description

SigAlg

codecov

A Python package for finite, measure-theoretic probability theory and stochastic processes. The library emphasizes mathematical fidelity while remaining practical for simulations and numerical experiments.

This package is under active development. Extensive documentation is coming soon.

Installation

pip install sigalg

Quick Examples

Build and simulate a random walk:

import matplotlib.pyplot as plt

from sigalg.core import Time
from sigalg.processes import RandomWalk

# Create a random walk with 100 discrete time steps
T = Time.discrete(length=100)
X = RandomWalk(p=0.7, time=T)

# Simulate 10 trajectories
X.from_simulation(n_trajectories=10, random_state=42)

# Plot trajectories
_, ax = plt.subplots(figsize=(7, 4))
X.plot_trajectories(ax=ax)
plt.show()

Compute conditional expectation of a random variable with respect to a $\sigma$-algebra:

from sigalg.core import (
    Operators,
    ProbabilityMeasure,
    RandomVariable,
    SampleSpace,
    SigmaAlgebra,
)

# Create a sample space with 4 outcomes, labeled 0, 1, 2, 3
Omega = SampleSpace().from_sequence(size=4)

# Define a probability measure by assigning probabilities to each outcome
P = ProbabilityMeasure(sample_space=Omega).from_dict(
    {
        0: 0.2,  # P(0) = 0.2
        1: 0.3,  # P(1) = 0.3
        2: 0.3,  # P(2) = 0.3
        3: 0.2,  # P(3) = 0.2
    }
)

# Define a random variable by assigning values to each outcome
X = RandomVariable(domain=Omega, name="X").from_dict(
    {
        0: 1,  # X(0) = 1
        1: 2,  # X(1) = 2
        2: 8,  # X(2) = 8
        3: 3,  # X(3) = 3
    }
)

# Sigma-algebras are defined by partitioning the sample space into atoms
F = SigmaAlgebra(sample_space=Omega, name="F").from_dict(
    {
        0: "A",  # outcome 0 is in atom A
        1: "A",  # outcome 1 is in atom A
        2: "B",  # outcome 2 is in atom B
        3: "B",  # outcome 3 is in atom B
    }
)

# Compute conditional expectation E(X|F), which is an instance of `RandomVariable`
E_X_F = Operators.expectation(rv=X, sigma_algebra=F, probability_measure=P)
print(E_X_F)

Documentation

Comprehensive documentation with tutorials, API reference, and mathematical background is coming soon.

License

MIT License. See LICENSE for details.

Author

John Myers

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

sigalg-0.1.0.tar.gz (72.7 kB view details)

Uploaded Source

Built Distribution

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

sigalg-0.1.0-py3-none-any.whl (94.7 kB view details)

Uploaded Python 3

File details

Details for the file sigalg-0.1.0.tar.gz.

File metadata

  • Download URL: sigalg-0.1.0.tar.gz
  • Upload date:
  • Size: 72.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for sigalg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bbd720c03de938798c167411a18e79caa681620b9e8bfa6f875f09db03a9cdb7
MD5 649dc312426c47843543920a52e6e01f
BLAKE2b-256 5be87c9651af27b7d8835a27c4535ffb49010b9dbd76b5bfa17add76457f7d11

See more details on using hashes here.

File details

Details for the file sigalg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sigalg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 94.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for sigalg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 684200a2e5bba6011a9ef05a4cc408c434a2525a44713c925b4717a7f385fe67
MD5 dbc07b8114e6216ae98a2641322e1bd5
BLAKE2b-256 cdc587e929e05ba164bb1e026bbf20562d2bc1712312ba18d31d3b98c160da36

See more details on using hashes here.

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