biocircuits.gillespie_ssa¶
- biocircuits.gillespie_ssa(propensity_func, update, population_0, time_points, return_time_points=False, size=1, args=(), n_threads=1, progress_bar=False)¶
Uses the Gillespie stochastic simulation algorithm to sample from probability distribution of particle counts over time.
- Parameters
propensity_func (function) – Function with call signature `propensity_func(propensities, population, t, *args) that takes the current propensities and population of particle counts and updates the propensities for each reaction. It does not return anything.
update (ndarray, shape (num_reactions, num_chemical_species)) – Entry i, j gives the change in particle counts of species j for chemical reaction i.
population_0 (array_like, shape (num_chemical_species)) – Array of initial populations of all chemical species.
time_points (array_like, shape (num_time_points,)) – Array of points in time for which to sample the probability distribution.
size (int, default 1) – Number of trajectories to sample per thread.
args (tuple, default ()) – The set of parameters to be passed to propensity_func.
n_threads (int, default 1) – Number of threads to use in the calculation.
progress_bar (str or bool, default False) – If True, use standard tqdm progress bar. If ‘notebook’, use tqdm.notebook progress bar. If False, no progress bar.
- Returns
if return_time_points is False –
- samplesndarray
Entry i, j, k is the count of chemical species k at time time_points[j] for trajectory i. The shape of the array is (size*n_threads, num_time_points, num_chemical_species).
if return_time_points is True –
- sampleslist of 2d Numpy arrays
samples[i][j,k] is the count of chemical species k at the jth time point for trajectory i.
- timeslist of 1d Numpy arrays
Entry i corresponds to a trajectory. times[i][j] is the time for the transition that brought the simulation to a count given by samples[i][j,:].