-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
53 lines (32 loc) · 1.31 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
RandomT: declarative probabilistic programming in Python
========================================================
Installation
============
python setup.py build
python setup.py install
Usage
=====
1. Import language environment
from RandomT import *
2. Construct random variable
X = RndVar(lambda : randint(0,1)) # Is some random integer
3. Combine with other random variables using base class methods
Y = X + X
4. Run probability queries
print Pr(Y, {}, rejectionN(500))
How to make a RandomT random variable
=====================================
2 ways.
1. Create a 0-arg function (thunk) that performs a draw from the distribution.
The function must return values of a consistent type, or the operations on this
random variable will not be well defined.
from random import randint
X = RndVar(lambda : randint(0, 5))
2. Create a Dist, which holds a dictionary describing the full probability
distribution. The keys must all be of the same type and must be hashable
objects, otherwise the operations on this random variable are not well
defined/sampled values cannot be meaningfully compared for equality.
X = RndVar(Dist({0 : 0.2, 1: 0.2, 2: 0.2, 3: 0.2, 4: 0.2}))
Currently supported inference algorithms
========================================
rejectionN(numsamples) - simple rejection sampling, works on any model