Skip to main content

Probability library

Project description

Probnode

"Buy Me A Coffee"

Description

Probability expression library

Features

  • Basic events and probability expressions modeling, similar to SymPy
  • Calculation on a chain of probability expressions
  • Contract and/or expand probability expressions chain, using probability mathematical characteristics

Installation

pip install probnode

Quick Usage

  • Events and probability modeling:
  from probnode import Event, P

  e1 = Event("Sample event 1")
  p1 = P(e1)
  e2 = Event("Sample event 2")
  p2 = P(e2)
  
  p3 = P(p1 | p2) # Or Probability expression
  p4 = P(p1 & p2) # And Probability expression
  p5 = P(p1 // p2) # Conditional Probability expression

  # Display mathematical representation of the object(s)
  print(repr(p1))
  • Mathematical treatment on probability expressions:
  # First convert probability expression to math node
  from probnode import N
  n1 = N(p1) # Each below is a (math) node
  n2 = N(p2)
  n3 = N(p3)
  n4 = N(p4)
  n5 = N(p5)

  # A sum of nodes
  snode = n1 + n2 - n4 
  # A product of nodes
  pnode = n5 * n2
  • Contract/ expand mathematical chain of probability nodes

    • Contract
      from probnode.computation import contract
    
      c1 = contract(snode) # P(A) + P(B) - P(A and B) -> P(A or B)
      print(repr(c1))
      c2 = contract(pnode)
      print(repr(c2)) # P(A when B) * P(B) -> P(A and B)
    
    • Expand
      from probnode.computation import expand
    
      x = expand(n3)
      print(repr(x[0])) # P(A or B) -> P(A) + P(B) - P(A and B)
    
  • Value calculations

    node.value will return the value of node If node is a chain node (comprising multiple nodes in sum / product mathematic operation), and either children node.value is not defined, the result parent node.value will be None

    n1.value # None

    Node value can be calculated from probability expression value

    p1.value = 0.7
    n1.value # equals 0.7
    

    Or by assigning value to itself

    n1.value = 0.6
    n1.value # equals 0.6
    

    The value assigned to itself takes precedence over the calculated value from its probability expression, or calculated from children nodes (if it is a chain node)

Notes

  • Nodes, probabilities, events comparisons:

    • Events will be compared based on its name only

    • Probability compared based on its representation (type, value)

    • Nodes compared based on its underlying structure (its probability expressions, children nodes (respecting order))

    • node.is_permutation_of(other) will check if 2 nodes are permutations

  • Expansion returns a list of expanded nodes

  • Contraction return a single contracted node

  • Expansion and contraction will be done 1 time, not exhaustively until unexpandable / uncontractable

"Buy Me A Coffee"

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

probnode-0.1.0a0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

probnode-0.1.0a0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file probnode-0.1.0a0.tar.gz.

File metadata

  • Download URL: probnode-0.1.0a0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for probnode-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 755e99782877779ff7ac27490a3e252a7ce47533ee55e050209bb09ce06f950a
MD5 cb9d1d1d6c1d9b33fd248c90c04085e5
BLAKE2b-256 50851c0cb8a53a0b87998b7a59d67e379ae9552c7e9af30b6e941064a5dc096a

See more details on using hashes here.

File details

Details for the file probnode-0.1.0a0-py3-none-any.whl.

File metadata

  • Download URL: probnode-0.1.0a0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for probnode-0.1.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bf7e19b106a154bbfcc1b2043936215baea662c86d045f9b4f22b36132a116d
MD5 70c39b47751779c69fc4ae47178537e8
BLAKE2b-256 ebca0688d4320d211223b5e65c3666bc36988353655bb3e1045a904abfb7e1a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page