# First Reaction Method

Gillespie's first reaction method generates a uniform random deviate for each reaction at each time step. These uniform deviates are used to compute exponential deviates which are the times at which each reaction will next fire. By selecting the minimum of these times, one identifies the time and the index of the first reaction to fire. The algorithm for a single step is given below.

1. for m in [1..M]:
   1. Compute am from X.
   2. Generate a unit, uniform random number r.
   3. τm = -ln(r) / am
2. τ = minm τm
3. μ = index of the minimum τm
4. t = t + τ
5. X = X + Vμ

As with the direct method, using an efficient exponential deviate generator will improve the performance. But with the first reaction method an exponential deviate is generated for each reaction, so using a good generator is critical. One can also improve the efficiency by only computing those propensities that have changed. For this one needs a reaction influence data structure. The implementation of the first reaction method in Cain uses these optimizations.

The first reaction method is not as efficient as the direct method. Taking a step has linear complexity in the number of reactions and it requires more random numbers than the direct method. For small problems it has acceptable performance, but it is not efficient for large problems. The first reaction method may be adapted to re-use the reaction times instead of regenerating them at each step. This method is introduced next.