rethinkpriorities / squigglepy

Squiggle programming language for intuitive probabilistic estimation features in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there an equivalent of Squiggle's `cdf`?

erwald opened this issue · comments

See Squiggle docs (not much info there though).

Right now I'm doing something like this:

import squigglepy as sq
import numpy as np

samples = sq.norm(mean=0, sd=2) @ 10000
num_above_threshold = np.size(np.where(np.array(samples) >= 0.5))
print(num_above_threshold / len(samples)) # prints 0.4023

Which would be equivalent to this in Squiggle:

x = normal(0, 2)
1.0 - (x |> cdf(0.5)) // outputs 0.401

Is there already such a function in squigglepy? If not, it'd be convenient to have one built in. (I'd be happy to implement it if you want to add it, but up to you of course.)

I mainly implement this via:

import squigglepy as sq
import numpy as np
np.mean((sq.norm(mean=0, sd=2) >= 0.5) @ 10000)

What do you think of that?

BTW np.mean(sq.norm(mean=0, sd=2) @ 10000 >= 0.5) also works and saves you a few keystrokes

Oh cool that's nice enough, thanks! Closing this.