Probly is a Python-like mini-language for probabilistic estimation. It's based on Starlark and implemented in Go.
You may use any Starlark syntax. There are only the following differences to Starlark:
math
module is imported by default, so you can directly use it e.g. math.sqrt(2)
. Probly also has a built-in sum
function not available in Starlark.This page will show you the probability distributions of all the numeric (scalar or distribution) global variables in your program (except those starting with an underscore). The values are taken at the end of the program's execution.
Name | to p10 to p90 |
pm plus/minus |
td times/divide |
Quantiles | Notes | |||||
---|---|---|---|---|---|---|---|---|---|---|
Normal |
mean |
sd |
2 | |||||||
LogNormal |
mu |
sigma |
2 | Alternatively: mean , sd |
||||||
Beta |
alpha |
beta |
||||||||
PERT |
min |
mode |
max |
[lambd] |
Like the triangular, but smoother (Wikipedia) | |||||
Uniform |
a |
b |
2 | a need not be less than b |
||||||
LogUniform |
a |
b |
2 | a need not be less than b |
||||||
Bernoulli |
p |
|||||||||
Binomial |
n |
p |
||||||||
Discrete |
x_1 |
p_1 |
x_2 |
p_2 |
... | Generic discrete distribution over any finite set of values |
These mathematical functions and constants are available in the math
module:
pow(x, y)
- Returns x raised to the power of yexp(x)
sqrt(x)
log(x, [base])
- Natural logarithm by default if base is not specifiede
pi
ceil(x)
floor(x)
fabs(x)
- Returns the absolute value of x as floatcopysign(x, y)
- Returns a value with the magnitude of x and the sign of ymod(x, y)
- Returns x
modulo y
remainder(x, y)
round(x)
- Returns the nearest integer, rounding half away from zeroacos(x)
asin(x)
atan(x)
atan2(y, x)
- Returns atan(y / x). The result is between -pi and picos(x)
sin(x)
tan(x)
degrees(x)
- Converts angle x from radians to degreesradians(x)
- Converts angle x from degrees to radiansacosh(x)
asinh(x)
atanh(x)
cosh(x)
sinh(x)
tanh(x)
hypot(x, y)
- Returns the Euclidean norm, sqrt(x^2 + y^2); the distance from the origin to (x, y)gamma(x)
- Returns the Gamma function at xThis code provides an example of the syntax of Starlark:
# Define a number
number = 18
# Define a list
numbers = [1, 2, 3, 4, 5]
# List comprehension
halves = [n / 2 for n in numbers]
# Define a function
def is_even(n):
"""Return True if n is even."""
return n % 2 == 0
# Define a dictionary
people = {
"Alice": 22,
"Bob": 40,
"Charlie": 55,
"Dave": 14,
}
names = ", ".join(people.keys()) # Alice, Bob, Charlie, Dave
# Modify a variable in a loop
sum_even_ages = 0
for age in people.values():
if is_even(age):
sum_even_ages += age
# Append to a list in a loop
over_30_names = []
for name, age in people.items():
if age > 30:
over_30_names.append(name)
If you've ever used Python, this should look very familiar. In fact, the code above is also valid Python code. Still, this short example shows most of the language. Starlark is a very small language that implements a limited subset of Python.
For our purposes, one notable difference to Python is that the exponentiation operator **
is not supported. You have to use math.pow
.
You can also look at the Starlark language specification.
Though not designed for speed, Probly is fast enough for practical purposes: around 10 milliseconds for 3,000 samples, for most examples on this page. This is due to being implemented in Go.
The time taken to return results on this page is spent overwhelmingly in web application code, not in Probly evaluation.
Interestingly, Probly is still slower than Python code that uses entirely numpy
array operations, which are very well optimised.
This should only begin to matter at very large scales, or if latency is critical.
It's not currently possible to obtain and manipulate properties of a distribution within an Probly program, like so:
x = Normal(1 to 10)
y = x.std() # Not possible
Supporting this would require some fundamental changes to the implementation of Probly, which is currently very simplistic.
The to
binary operator was inspired by Squiggle.
This example reproduces a 2018 GiveWell cost-effectiveness analysis for iron and folic acid (IFA) supplementation of school-age children.
The model considers the direct benefits of reducing anemia, as well as benefits via cognitive improvements and their effects on long-term wages. These benefits are weighed against potential risks like increased malaria mortality and side effects.
The final output is the humanitarian value per $10,000 spent, and a comparison of this value to the impact of donating the same amount to GiveDirectly.
In this model, the cost-effectiveness is largely driven by the long-term cognitive benefits of IFA supplementation.
Additional background information
GiveWell is a global health funder. They conduct in-depth research to estimate the cost-effectiveness of a given program — in terms of humanitarian benefit (e.g. lives saved) per dollar.
GiveWell developed this cost-effectiveness analysis in the context of this grant investigation. GiveWell also has a report about iron supplementation generally.
Mean | 8.27 |
Std. dev. | 8.14 |
Variance | 66.3 |
Quantile | |
---|---|
0.05 | 2.18 |
0.25 | 3.76 |
0.50 | 5.87 |
0.75 | 9.79 |
0.95 | 21.6 |
Mean | 130 |
Std. dev. | 105 |
Variance | 11 000 |
Quantile | |
---|---|
0.05 | 44.4 |
0.25 | 69.9 |
0.50 | 100 |
0.75 | 150 |
0.95 | 319 |
Mean | 0.461 |
Std. dev. | 0.076 2 |
Variance | 0.005 80 |
Quantile | |
---|---|
0.05 | 0.338 |
0.25 | 0.407 |
0.50 | 0.461 |
0.75 | 0.513 |
0.95 | 0.585 |
_cohort | p_anemia | value_per_10_000_usd | multiples_of_cash | |
---|---|---|---|---|
0 | 10 000 | 0.326 | 32.9 | 7.08 |
1 | 10 000 | 0.489 | 86.0 | 3.35 |
2 | 10 000 | 0.442 | 83.4 | 12.0 |
... | ... | ... | ... | ... |
2997 | 10 000 | 0.513 | 229 | 8.39 |
2998 | 10 000 | 0.487 | 534 | 5.22 |
2999 | 10 000 | 0.635 | 251 | 7.57 |
Get the simulation data (and more) in a machine-readable format:
/api/sim/aBeeLicUYGXdzdY4k8nBRh/