0

I'm making an app that needs to generate deterministic random events. They need to be deterministic so I can compute which events happened when the app was closed. I would like to find a function f(time1, time2) that tells me how many events happened between any two points in time, without generating the full process. It should also be that f(t1,t3) = f(t1,t2) + f(t2, t3).

I started out with this question but started this new one so I could rewrite it now that I have a better idea of what I'm looking for.

I've started a question on Math Overflow about finding a formula for f since it seems to be more of a math problem than a coding problem.

Community
  • 1
  • 1
Nathan Breit
  • 1,661
  • 13
  • 33

2 Answers2

0

Let's rewrite the problem. Suppose that your f existed. Then you can use a binary search can find the time of the next event to whatever precision that you want. So construct f first.

So how can we create f? Well, we only need to calculate f from 0 to any arbitrary t and then f(s, t) = f(0, t) - f(0, s).

We don't even need to be able to calculate it directly for every t. If we can calculate it at every integer, and also if we have it at both ends of an interval if we can calculate it at the midpoint, that is enough. Since f is non-decreasing and always an integer, a bisection algorithm will eventually wind up with t sandwiched between two points that we know f at which have the same value.

And now we have an approach. We will calculate it at integers. Then once we have t sandwiched, start bisecting until we have lower and upper bounds for f(0,t) that are the same.

We can go from integer to integer by generating a random number, then using a Poisson distribution to find how many events happened. If we know f at two ends of an interval, we can find it at the midpoint with the same trick, but this time knowing that the number of events that happened in the first half of the interval is described by a binomial distribution.

The trick to worry about that we need a pseudorandom generator with 2 unrelated "move next" options. One of them for when we move next interval/land in top half of an interval. The other for when we stop moving intervals/land in bottom half of an interval. And we need paths we walk between the two to not give the same answer. Else your random events will be distributed in an oddly periodic manner. I would suggest doing this by having two different generators that use seeds in the same range. (If they are close, but not the same, you can just repeat the one you're doing until the seed winds up in the common range...) Which generator you use depends on which direction the last flip took you.

Figuring out the right ones to use may require some thought. But hopefully that is easier to figure out than the problem you started with!

btilly
  • 43,296
  • 3
  • 59
  • 88
  • I'm not able to follow your answer after the "We don't even need it for every t..." part. If might be clearer to me if you could post some code for computing f or some mathematical notation that defines it more concretely. – Nathan Breit Oct 28 '13 at 09:55
  • @Nathan Does the end of the explanation make more sense now? – btilly Oct 28 '13 at 14:36
  • You're talking about creating f on the fly by using a random number generator to compute every integer interval. I want to be able to compute f from a fixed mathematical formula that only appears to be random. – Nathan Breit Oct 28 '13 at 16:02
0

If I understand your constraint, you (A) don't want to store your process, because it is huge. and (B) don't want to generate the processes repeatedly for the same reason. But you can try a hybrid strategy.

Get any random number generator R that you can (A) seed deterministically and (B) read the state (see below how you can fake this).

Now:

  • Store R.state (or set it using something hardcoded)
  • Generate N samples and use them to generate you poisson process.
  • Store a triple of (time, Poisson CDF, R.state)

Later when you go back over your data, you can find the last time before the interval of interest, lookup R.state and CDF and start re-generating your poisson process. You will never have to generate more than N extra samples, but you will only have to store every Nth state.

Now how do you store the state of a random number generator? Some of them have API functions for reading out their state. Another trick is to use two generators, R1, R2. Then you seed R2 every N points using R1. The value of R1 is then the "state" that you store.

Adrian Ratnapala
  • 5,485
  • 2
  • 29
  • 39