Is there an equivalent of Squiggle's `cdf`?
erwald opened this issue · comments
Erich Grunewald commented
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.)
Peter Wildeford commented
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?
Peter Wildeford commented
BTW np.mean(sq.norm(mean=0, sd=2) @ 10000 >= 0.5)
also works and saves you a few keystrokes
Erich Grunewald commented
Oh cool that's nice enough, thanks! Closing this.