Code Monkey home page Code Monkey logo

probs's Introduction

probs

Python 3.12+ PyPI version Build Status GitHub license codecov Downloads

Probability is a concept that many introductory Computer Science courses teach because of its frequent application in algorithms, data structures, and other mathematical fields. While numerous libraries for expressing probabilities exist (e.g. scipy, statistics, etc), the majority of them focus primarily on the application of these concepts rather than showcasing the mechanics of the mathematical theory.

The goal of this project is to leverage Python's built-in language features to expose an intuitive and expandable API for simple probabilitic expressions.

Usage

pip install probs

Examples

from probs import *

# define a normally-distributed random variable with
# mean = 0, variance = 1
X = Normal()

assert E(X) == 0
assert Var(X) == 1 / 12
assert X.pdf(0.5) == 2
# combine multiple random variables
u, v = Uniform(), Uniform()

assert E(u) == 1 / 2
assert Var(u) == 1 / 12

assert (u * v).pdf(0.5) == 39.0169
assert (1 * v).pdf(0.5) == 1

assert E(u + 1) == 1.5
assert E(u + v) == 1
assert E(u - v) == 0

assert Var(u + v) == 1 / 6

Documentation

Contributing

All issues and pull requests are much appreciated! To build the project:

  • probs is actively developed using the lastest version of Python.
    • First, be sure to run pre-commit install.
    • To run all tests and use auto-formatting tools, use pre-commit run.
    • To only run unit tests, run pytest.

TODO List

  • Use ApproxFloat across all operations.

  • Dataclasses are iffy, because:

    • Need to set super().init() in order to get the parent class's fields.

    • Need to set eq=False on all RandomVariables.

    • Need to set repr=False in order to get the parent's repr method.

    • However, clearer init function provided, other operators potentially builtin.

    • repr can be inherited without a rewrite

    • inheritance works so long as every parent is also a dataclass.

    • super short init syntax

  • Figure out how to merge pmf and custom pmf functions.

  • Convert all floats to Decimal? For precision.

probs's People

Contributors

tyleryep avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.