In this document, we report the influence of simulation length and noise on the examples shown in the main text. In general, using longer simulation will improve the precision of the landscape estimation, but will require more computational resources. A noise level that is too high makes the boundaries between the basins less sharp, while a noise level that is too low may fail to converge and make the landscape look rugged and overly noisy, or bounded in a single basin. The exact influence of noise on the landscape depends on the specific system being studied. The landscape results should be interpreted with caution if the noise level may substantially influence the system’s dynamic behavior, especially when the noise level is altered for the landscape construction.

Example 1: Gene Expression

# Load the package.
library(simlandr)

# Specify the simulation function.
b <- 1
k <- 1
S <- 0.5
n <- 4
lambda <- 0.01

drift_gene <- c(
  rlang::expr(z * x^(!!n) / ((!!S)^(!!n) + x^(!!n)) + (!!b) * (!!S)^(!!n) / ((!!S)^(!!n) + y^(!!n)) - (!!k) * x),
  rlang::expr(z * y^(!!n) / ((!!S)^(!!n) + y^(!!n)) + (!!b) * (!!S)^(!!n) / ((!!S)^(!!n) + x^(!!n)) - (!!k) * y),
  rlang::expr(-(!!lambda) * z)
) |> as.expression()

diffusion_gene <- expression(
  0.2,
  0.2,
  0.2
)

diffusion_gene_strong_noise <- expression(
  1,
  1,
  1
)

diffusion_gene_weak_noise <- expression(
  0.05,
  0.05,
  0.05
)


if (!file.exists("data/single_output_gene_shorter.RDS")) {
  set.seed(1614)
  single_output_gene_shorter <- sim_SDE(drift = drift_gene, diffusion = diffusion_gene, N = 1e4, M = 10, Dt = 0.1, x0 = c(0, 0, 1), keep_full = FALSE)
  saveRDS(single_output_gene_shorter, "data/single_output_gene_shorter.RDS")
} else {
  single_output_gene_shorter <- readRDS("data/single_output_gene_shorter.RDS")
}

if (!file.exists("data/single_output_gene_strong_noise.RDS")) {
  set.seed(1614)
  single_output_gene_strong_noise <- sim_SDE(drift = drift_gene, diffusion = diffusion_gene_strong_noise, N = 1e6, M = 10, Dt = 0.1, x0 = c(0, 0, 1), keep_full = FALSE)
  saveRDS(single_output_gene_strong_noise, "data/single_output_gene_strong_noise.RDS")
} else {
  single_output_gene_strong_noise <- readRDS("data/single_output_gene_strong_noise.RDS")
}


if (!file.exists("data/single_output_gene_weak_noise.RDS")) {
  set.seed(1614)
  single_output_gene_weak_noise <- sim_SDE(drift = drift_gene, diffusion = diffusion_gene_weak_noise, N = 1e6, M = 10, Dt = 0.1, x0 = c(0, 0, 1), keep_full = FALSE)
  saveRDS(single_output_gene_weak_noise, "data/single_output_gene_weak_noise.RDS")
} else {
  single_output_gene_weak_noise <- readRDS("data/single_output_gene_weak_noise.RDS")
}

single_output_gene_shorter2 <- do.call(rbind, single_output_gene_shorter)
single_output_gene_shorter2 <- cbind(single_output_gene_shorter2[, "X"] - single_output_gene_shorter2[, "Y"], single_output_gene_shorter2[, "Z"])
colnames(single_output_gene_shorter2) <- c("delta_x", "a")

single_output_gene_strong_noise2 <- do.call(rbind, single_output_gene_strong_noise)
single_output_gene_strong_noise2 <- cbind(single_output_gene_strong_noise2[, "X"] - single_output_gene_strong_noise2[, "Y"], single_output_gene_strong_noise2[, "Z"])
colnames(single_output_gene_strong_noise2) <- c("delta_x", "a")

single_output_gene_weak_noise2 <- do.call(rbind, single_output_gene_weak_noise)
single_output_gene_weak_noise2 <- cbind(single_output_gene_weak_noise2[, "X"] - single_output_gene_weak_noise2[, "Y"], single_output_gene_weak_noise2[, "Z"])
colnames(single_output_gene_weak_noise2) <- c("delta_x", "a")

l_single_gene_3d_shorter <-
  make_3d_single(single_output_gene_shorter2, 
                 x = "delta_x", y = "a", 
                 lims = c(-1.5, 1.5, 0, 1.5), 
                 Umax = 8)
## Warning in truncate.grid(x = x, y = w, xmin = xmin, xmax = xmax): Points in x
## greater than xmax=c(1.5,1.5) have been excluded.
## Warning in truncate.grid(x = x, y = w, xmin = xmin, xmax = xmax): Points in x
## less than xmin=c(-1.5,0) have been excluded.
plot(l_single_gene_3d_shorter)
l_single_gene_3d_strong_noise <- 
  make_3d_single(single_output_gene_strong_noise2, 
                 x = "delta_x", y = "a", 
                 lims = c(-1.5, 1.5, 0, 1.5), 
                 Umax = 8)
## Warning in truncate.grid(x = x, y = w, xmin = xmin, xmax = xmax): Points in x
## greater than xmax=c(1.5,1.5) have been excluded.
## Warning in truncate.grid(x = x, y = w, xmin = xmin, xmax = xmax): Points in x
## less than xmin=c(-1.5,0) have been excluded.
plot(l_single_gene_3d_strong_noise)
l_single_gene_3d_weak_noise <-
  make_3d_single(single_output_gene_weak_noise2, 
                 x = "delta_x", y = "a", 
                 lims = c(-1.5, 1.5, 0, 1.5), 
                 Umax = 8)
## Warning in truncate.grid(x = x, y = w, xmin = xmin, xmax = xmax): Points in x
## greater than xmax=c(1.5,1.5) have been excluded.
## Warning in truncate.grid(x = x, y = w, xmin = xmin, xmax = xmax): Points in x
## less than xmin=c(-1.5,0) have been excluded.
plot(l_single_gene_3d_weak_noise)

Example 2: Panic disorder

library(PanicModel)

# Create a function that performs a simulation using the `simPanic` function from `PanicModel`.
# Some default options are modified for the illustration.

sim_fun_panic <- function(x0, par, lambda_N = 200, length = 5000) {
  
  # Change several default parameters
  pars <- pars_default 
  # Increase the noise strength to improve sampling efficiency
  pars$N$lambda_N <- lambda_N
  # Make S constant through the simulation
  pars$TS$r_S_a <- 0
  pars$TS$r_S_e <- 0
  
  # Specify the initial values of A and PT according to the format requirement by `multi_init_simulation()`, while the other variables use the default initial values.
  initial <- initial_default
  initial$A <- x0[1]
  initial$PT <- x0[2]
  
  # Specify the value of S according to the format requirement by `batch_simulation()`.
  initial$S <- par$S
  
  # Extract the simulation output from the result by simPanic(). Only keep the core variables. 
  return(
    as.matrix(
      simPanic(1:length, initial = initial, parameters = pars)$outmat[, c("A", "PT", "E")]
      )
    )
}

# Perform a single simulation from multiple starting points.
# Use parallel computing to speed up the simulation.

if (file.exists("data/single_output_panic_shorter.RDS")) {
  single_output_panic_shorter <- readRDS("data/single_output_panic_shorter.RDS")
} else {
  future::plan("multisession")
  set.seed(1614, kind = "L'Ecuyer-CMRG")
  single_output_panic_shorter <- multi_init_simulation(
    sim_fun = sim_fun_panic,
    range_x0 = c(0, 1, 0, 1),
    R = 4,
    par = list(S = 0.5),
    length = 500
  )
  saveRDS(single_output_panic_shorter, "data/single_output_panic_shorter.RDS")
}

if (file.exists("data/single_output_panic_strong_noise.RDS")) {
  single_output_panic_strong_noise <- readRDS("data/single_output_panic_strong_noise.RDS")
} else {
  future::plan("multisession")
  set.seed(1614, kind = "L'Ecuyer-CMRG")
  single_output_panic_strong_noise <- multi_init_simulation(
    sim_fun = sim_fun_panic,
    range_x0 = c(0, 1, 0, 1),
    R = 4,
    par = list(S = 0.5),
    lambda_N = 500
  )
  saveRDS(single_output_panic_strong_noise, "data/single_output_panic_strong_noise.RDS")
}

if (file.exists("data/single_output_panic_weak_noise.RDS")) {
  single_output_panic_weak_noise <- readRDS("data/single_output_panic_weak_noise.RDS")
} else {
  future::plan("multisession")
  set.seed(1614, kind = "L'Ecuyer-CMRG")
  single_output_panic_weak_noise <- multi_init_simulation(
    sim_fun = sim_fun_panic,
    range_x0 = c(0, 1, 0, 1),
    R = 4,
    par = list(S = 0.5),
    lambda_N = 60
  )
  saveRDS(single_output_panic_weak_noise, "data/single_output_panic_weak_noise.RDS")
}


l_single_panic_3d_shorter <- make_3d_single(
  single_output_panic_shorter |> window(start = 100), 
  x = "A", y = "PT", h = 0.005, lims = c(-1, 1.5, -0.5, 1.5))
plot(l_single_panic_3d_shorter, 2)

l_single_panic_3d_strong_noise <- make_3d_single(
  single_output_panic_strong_noise |> window(start = 100), 
  x = "A", y = "PT", h = 0.005, lims = c(-1, 1.5, -0.5, 1.5))
## Warning in truncate.grid(x = x, y = w, xmin = xmin, xmax = xmax): Points in x
## greater than xmax=c(1.5,1.5) have been excluded.
## Warning in truncate.grid(x = x, y = w, xmin = xmin, xmax = xmax): Points in x
## less than xmin=c(-1,-0.5) have been excluded.
plot(l_single_panic_3d_strong_noise, 2)

l_single_panic_3d_weak_noise <- make_3d_single(
  single_output_panic_weak_noise |> window(start = 100), 
  x = "A", y = "PT", h = 0.005, lims = c(-1, 1.5, -0.5, 1.5))
plot(l_single_panic_3d_weak_noise, 2)