ssa: Invoking the stochastic simulation algorithm

Description Usage Arguments Details Value See Also Examples

Description

Main interface function to the implemented SSA methods. Runs a single realization of a predefined system. For a detailed explanation on how to set up your first SSA system, check the introduction vignette: vignette("an_introduction", package = "GillespieSSA2"). If you're transitioning from GillespieSSA to GillespieSSA2, check out the corresponding vignette: vignette("converting_from_GillespieSSA", package = "GillespieSSA2").

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
ssa(
  initial_state,
  reactions,
  final_time,
  params = NULL,
  method = ssa_exact(),
  census_interval = 0,
  stop_on_neg_state = TRUE,
  max_walltime = Inf,
  log_propensity = FALSE,
  log_firings = FALSE,
  log_buffer = FALSE,
  verbose = FALSE,
  console_interval = 1,
  sim_name = NA_character_,
  return_simulator = FALSE
)

Arguments

initial_state

[named numeric vector] The initial state to start the simulation with.

reactions

A list of reactions, see reaction().

final_time

[numeric] The final simulation time.

params

[named numeric vector] Constant parameters to be used in the propensity functions.

method

[ssa_method]] Which SSA algorithm to use. Must be one of: ssa_exact(), ssa_btl(), or ssa_etl().

census_interval

[numeric] The approximate interval between recording the state of the system. Setting this parameter to 0 will cause each state to be recorded, and to Inf will cause only the end state to be recorded.

stop_on_neg_state

[logical] Whether or not to stop the simulation when the a negative value in the state has occured. This can occur, for instance, in the ssa_etl() method.

max_walltime

[numeric] The maximum duration (in seconds) that the simulation is allowed to run for before terminated.

log_propensity

[logical] Whether or not to store the propensity values at each census.

log_firings

[logical] Whether or not to store number of firings of each reaction between censuses.

log_buffer

[logical] Whether or not to store the buffer at each census.

verbose

[logical] If TRUE, intermediary information pertaining to the simulation will be displayed.

console_interval

[numeric] The approximate interval between intermediary information outputs.

sim_name

[character] An optional name for the simulation.

return_simulator

Whether to return the simulator itself, instead of the output.

Details

Substantial improvements in speed and accuracy can be obtained by adjusting the additional (and optional) ssa arguments. By default ssa uses conservative parameters (o.a. ssa_exact()) which prioritise computational accuracy over computational speed.

Approximate methods (ssa_etl() and ssa_btl()) are not fool proof! Some tweaking might be required for a stochastic model to run appropriately.

Value

Returns a list containing the output of the simulation:

See Also

GillespieSSA2 for a high level explanation of the package

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
initial_state <- c(prey = 1000, predators = 1000)
params <- c(c1 = 10, c2 = 0.01, c3 = 10)
reactions <- list(
  #        propensity function     effects                       name for reaction
  reaction(~c1 * prey,             c(prey = +1),                 "prey_up"),
  reaction(~c2 * prey * predators, c(prey = -1, predators = +1), "predation"),
  reaction(~c3 * predators,        c(predators = -1),            "pred_down")
)

out <-
  ssa(
    initial_state = initial_state,
    reactions = reactions,
    params = params,
    method = ssa_exact(),
    final_time = 5,
    census_interval = .001,
    verbose = TRUE
  )

plot_ssa(out)

GillespieSSA2 documentation built on July 14, 2020, 5:08 p.m.