# Poisson processes in patterns?

hey folks—i’m looking for the Right Way™ to generate a stream of events according to a poisson process. i’ve found so many features that look almost right but aren’t:

• i’m not looking for Ppoisson, which samples from a poisson distribution but doesn’t help me generate events according to a poisson process; i’d want to sample from an exponential distribution.

• i’m not looking for Pexprand or exprand, which, despite claiming to sample from an “exponential distribution”, actually seems to… well, i don’t know what it does, the documentation doesn’t say (or at least doesn’t say anything true). if there’s an actual exponential distribution sampler, i would love to have that.

• i’m not looking for Dust, which seems to be roughly what i’m looking for but i would like to live in sclang-land and not scsynth-land.

anyone have any suggestions here?

to answer my own question, it looks like there’s comprehensive functionality around beta functions and the beta distribution which i can derive an exponential distribution from. but if there’s a yet simpler way, let me know!

(fwiw, i’m trying to do pattern-side granulation with nondeterministic trigger at an average rate, a la Dust. so if someone thinks i’m completely off the right track on that, let me know!)

According to these notes: https://www.math.uchicago.edu/~may/VIGRE/VIGRE2010/REUPapers/Mcquighan.pdf

the beginning of section 4 says that the inter-onset intervals between successive events may be simulated as `(log(1 - 1.0.rand) * -1) / lambda`, where lambda is the average number of events per 1 time unit. So I think setting a `\dur` key to `(log(1 - Pwhite()) * -1) / lambda` will do it.

You can think of rrand taking a normalized random value 0.0 to 1.0 and mapping it onto the range lo to hi: `(hi - lo) * rand01 + lo`.

exprand promotes the operators: `((hi / lo) ** rand) * lo`.

The distribution of this random function does have the decay characteristic of an exponential distribution, and it is memoryless by definition (because 1.0.rand is memoryless). So I think, to say that exprand is categorically not exponential requires a deeper argument than simply that the parameters aren’t what you expected.

hjh

@nathan yeah makes sense, i think that’s the same relationship it has with the beta / the same relationship the beta has with the uniform. also just now i realized that scrolling down to the bottom of the wikipedia page on the exponential gives the same sampling process. my apologies for wasting forum time because i can’t use my mouse right

@jamshark70 what do you mean by “1.0.rand is memoryless”? the uniform distribution is not memoryless, and i don’t think that memorylessness “survives” nonlinear transformations (though my probability is very, very rusty as you can see). i think that the sampling process used by exprand is the inverse of that used for the exponential is suggestive that it’s not behaved the same.

appreciate the clear explanation of the exprand sampling process though. this would be good documentation to have in supercollider itself; i couldn’t discern that from any of the docs i found and simply had no idea what it did. (it’s a little odd that despite the analogy between rand and exprand, a SimpleNumber receiving rand understands itself to be the upper bound with implicit lower bound 0, whereas a SimpleNumber receiving exprand understands itself to be the lower bound with no implicit upper bound… an implicit lower bound of 1.0 would make a lot more sense.)

i’ll put up a PR to the docs as thanks to both of you for being so responsive to my recent questions here

an implicit lower bound of 1.0 would make a lot more sense

oh i see… exprand mimics rrand, not rand… sigh

I believe exprand is a log-uniform distribution, whose PDF is proportional to 1/x over a bounded interval. You’re correct that it isn’t an exponential distribution, whose PDF would be of the form `a * exp(-a * x)`.

I really appreciate the math corrections – thanks! Like a lot of users, I assumed that exprand “is” an exponential distribution. I’m glad to know there’s a different name for what it really does.

It would be very good to update exprand and Pexprand documentation to indicate that they produce exponentially-mapped random numbers, resulting in a log-uniform distribution.

About memory – I was glancing too quickly over some online documents and didn’t fully understand the concept. I’m a little more clear on it now, though I need to do a bit more reading to understand the uniform distribution’s memory property.

hjh