简体   繁体   中英

Time complexity of algorithm with random component (Gillespie Algorithm)

I'm trying to find the time complexity of the Gillespie Algorithm.

General algorithm can be found: Here

More extended version: Here

The assumption is that the number of reactions and the number of proteins is constant. This might allow me to calculate the time complexity by the time variable alone.

But I get stuck since the time increase each iteration is based on a random value. Let me elaborate (removed non relevant code):

So this is the general loop, each iteration the reactions are updated, then the currentTime is updated.

currentTime = 0.0;
while(currentTime < timeEnd)
{
    reactions->calcHazard();
    currentTime += this->getNextTime();
}

The function getNextTime calculates a new time.

double Gillespie::getNextTime()
{
    double randVal;

    randVal = ((double) rand() / (double)(RAND_MAX));
    while ( randVal == 0)
    {
        randVal = ((double) rand() / (double)(RAND_MAX));
    }
    return ((1.0/reactions->getSum())*(log(1.0/randVal)));
}

The calculation of a the new time size is based on a random value R. The other variable component here is the result of reactions->getsum. The return value of this function is

sum(k*A(t))

Where k and A(t) are both vectors, k is the probability for each reaction and A(t) is the number of proteins at time t.

Better explanation about the time increase might be provided by page 7 of previous link.

Is it possible to say anything about the time complexity of this (iteration from tStart -> tEnd)? Or is this impossible without also including information about about #proteins and #reactions?

It's O(n) . You don't really need to calculate the expected return value of getNextTime() . It's enough to know that its return doesn't change in response to the simulation running.

Let's assume your code iterates that loop N times for a 1 hour simulation.

It's pretty obvious that these are equivalent...

timeEnd = currentTime + 2hours;
while (currentTime < timeEnd) { ... } // ??? iterations

is equivalent to

timeMid = currentTime + 1hour;
timeEnd = currentTime + 1hour;
while (currentTime < timeMid) { ... }  // N iterations
while (currentTime < timeEnd) { ... } // <=N iterations

So, it iterates the loop approx 2N times for a 2 hour simulation.

The assumption is that the number of reactions and the number of proteins is constant

That is useful assumption. Basically, that means that getNextTime() will not systematically increase or decrease as the simulation runs. If the return value of getNextTime() decreased over the course of the simulation (meaning A(t) was increasing over the course of the simulation), then the second loop would take more iterations than the first one.

You can probably make that assumption anyways if the system hits equilibrium at some point (that's inevitable right? I'm not a chemist). Because then A(t) is constant, since that's... what equilibrium is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM