Skample!

[source]

Bins

Samples

Sketch anywhere in the box to create a continuous probability density function , and then to sample points from that density function. Clicking on the "Download" button will get you a CSV of those points (one column of unquoted floats, no header).

Sure! This is pretty performant, and will update as you change the numbers. If you set the number of samples to 1, then click in the box and hold the "up" arrow, you can watch the samples get get drawn from your distribution! Sampling up to 1,000,000 points on my laptop is pretty instantaneous.

Everything is done exactly, and it is all javascript, so it is running in your browser. Crazy big numbers will hurt only your computer! Probably 1 billion is crazy big, but it is a free country, so I'm not stopping you.

More rigorously, when you draw a line, that turns into a list of *(x, y)* tuples, which is
a piecewise-linear pdf. I integrate that exactly using the
trapezoidal rule, but in this
case *is the exact integral*, to get the
cdf, which will be piecewise
quadratic. Then I work out how to invert this cdf. You can see the math in
the repo,
or much more clearly written out in
my Python notes.

Sampling is then done by generating a random uniform number between 0 and 1, and passing that number
through the inverted cdf. All the samples you have generated for a sketch are stored in state, so
changing the number of samples from *n* to *n + 1* is *O(1)*.

Check out PyMC3 if you like Python!

Issues and pull requests welcome!

I'm Colin! I saw an interesting tweet asking for such an app. I have been working on an interactive UI for PyMC3 recently, and started adding this in before realizing you really do not need such a big hammer for this nail. I do wonder whether rejection sampling would be more efficient for this task.