Title: | Simulation-Based Landscape Construction for Dynamical Systems |
---|---|
Description: | A toolbox for constructing potential landscapes for dynamical systems using Monte Carlo simulation. The method is based on the potential landscape definition by Wang et al. (2008) <doi:10.1073/pnas.0800579105> (also see Zhou & Li, 2016 <doi:10.1063/1.4943096> for further mathematical discussions) and can be used for a large variety of models. |
Authors: | Jingmeng Cui [aut, cre] |
Maintainer: | Jingmeng Cui <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.4.0 |
Built: | 2025-02-16 06:34:56 UTC |
Source: | https://github.com/Sciurus365/simlandr |
An argument set contains the descriptions of the relevant variables in a
batch simulation. Use new_arg_set()
to create an arg_set
object, and use add_arg_ele()
to add an element to the arg_set
. After
adding all elements in the argument set, use make_arg_grid()
to make an
argument grid that can be used directly for running batch simulation.
new_arg_set() add_arg_ele(arg_set, arg_name, ele_name, start, end, by) nele(arg_set) narg(arg_set) ## S3 method for class 'arg_set' print(x, detail = FALSE, ...) make_arg_grid(arg_set) ## S3 method for class 'arg_grid' print(x, detail = FALSE, ...)
new_arg_set() add_arg_ele(arg_set, arg_name, ele_name, start, end, by) nele(arg_set) narg(arg_set) ## S3 method for class 'arg_set' print(x, detail = FALSE, ...) make_arg_grid(arg_set) ## S3 method for class 'arg_grid' print(x, detail = FALSE, ...)
arg_set |
An |
arg_name , ele_name
|
The name of the argument and its element in the simulation function |
start , end , by
|
The data points where you want to test the variables.
Passed to |
x |
An |
detail |
Do you want to print the object details as a full list? |
... |
Not in use. |
new_arg_set()
returns an arg_set
object.
add_arg_ele()
returns an arg_set
object.
nele()
returns an integer.
narg()
returns an integer.
make_arg_gird()
returns an arg_grid
object.
new_arg_set()
: Create an arg_set
.
add_arg_ele()
: Add an element to an arg_set
.
nele()
: The number of elements in an arg_set
.
narg()
: The number of arguments in an arg_set
.
print(arg_set)
: Print an arg_set
object.
make_arg_grid()
: Make an argument grid from an argument set.
print(arg_grid)
: Print an arg_grid
object
batch_simulation()
for running batch simulation and a
concrete example.
This function can be used to convert a list of simulation output to a mcmc.list object. This may be useful when the output of the simulation is a list of matrices, and you want to perform convergence checks using the functions in the coda package. See coda::mcmc.list()
for more information, and also see the examples in the documentation of sim_SDE()
.
## S3 method for class 'list' as.mcmc.list(x, ...)
## S3 method for class 'list' as.mcmc.list(x, ...)
x |
A list of simulation output |
... |
Not used |
A mcmc.list object
Attach all matrices in a batch simulation
attach_all_matrices(bs, backingpath = "bp")
attach_all_matrices(bs, backingpath = "bp")
bs |
A |
backingpath |
Passed to |
A batch_simulation
object with all hash_big_matrix
es attached.
This layer can show the saddle point (2d) and the minimal energy path (3d) on the landscape.
## S3 method for class 'barrier' autolayer(object, path = TRUE, ...)
## S3 method for class 'barrier' autolayer(object, path = TRUE, ...)
object |
A |
path |
Show the minimum energy path in the graph? |
... |
Not in use. |
A ggplot2
layer that can be added to an existing landscape plot.
Perform a batch simulation.
batch_simulation( arg_grid, sim_fun, default_list = list(), bigmemory = TRUE, ... ) ## S3 method for class 'batch_simulation' print(x, detail = FALSE, ...)
batch_simulation( arg_grid, sim_fun, default_list = list(), bigmemory = TRUE, ... ) ## S3 method for class 'batch_simulation' print(x, detail = FALSE, ...)
arg_grid |
An |
sim_fun |
The simulation function. See |
default_list |
A list of default values for |
bigmemory |
Use |
... |
Other parameters passed to |
x |
An |
detail |
Do you want to print the object details as a full list? |
A batch_simulation
object, also a data frame.
The first column, var
, is a list of
ele_list
that contains all the variables; the second to the second
last columns are the values of the variables; the last column is the
output of the simulation function.
batch_simulation()
: Perform a batch simulation.
batch_arg_set_grad <- new_arg_set() batch_arg_set_grad <- batch_arg_set_grad %>% add_arg_ele( arg_name = "parameter", ele_name = "a", start = -6, end = -1, by = 1 ) batch_grid_grad <- make_arg_grid(batch_arg_set_grad) batch_output_grad <- batch_simulation(batch_grid_grad, sim_fun_grad, default_list = list( initial = list(x = 0, y = 0), parameter = list(a = -4, b = 0, c = 0, sigmasq = 1) ), length = 1e2, seed = 1614, bigmemory = FALSE ) print(batch_output_grad)
batch_arg_set_grad <- new_arg_set() batch_arg_set_grad <- batch_arg_set_grad %>% add_arg_ele( arg_name = "parameter", ele_name = "a", start = -6, end = -1, by = 1 ) batch_grid_grad <- make_arg_grid(batch_arg_set_grad) batch_output_grad <- batch_simulation(batch_grid_grad, sim_fun_grad, default_list = list( initial = list(x = 0, y = 0), parameter = list(a = -4, b = 0, c = 0, sigmasq = 1) ), length = 1e2, seed = 1614, bigmemory = FALSE ) print(batch_output_grad)
Functions for calculating energy barrier from landscapes
calculate_barrier(l, ...) ## S3 method for class ''2d_landscape'' calculate_barrier( l, start_location_value, start_r, end_location_value, end_r, base = exp(1), ... ) ## S3 method for class ''3d_landscape'' calculate_barrier( l, start_location_value, start_r, end_location_value, end_r, Umax, expand = TRUE, omit_unstable = FALSE, base = exp(1), ... ) ## S3 method for class ''2d_landscape_batch'' calculate_barrier( l, bg = NULL, start_location_value, start_r, end_location_value, end_r, base = exp(1), ... ) ## S3 method for class ''3d_landscape_batch'' calculate_barrier( l, bg = NULL, start_location_value, start_r, end_location_value, end_r, Umax, expand = TRUE, omit_unstable = FALSE, base = exp(1), ... )
calculate_barrier(l, ...) ## S3 method for class ''2d_landscape'' calculate_barrier( l, start_location_value, start_r, end_location_value, end_r, base = exp(1), ... ) ## S3 method for class ''3d_landscape'' calculate_barrier( l, start_location_value, start_r, end_location_value, end_r, Umax, expand = TRUE, omit_unstable = FALSE, base = exp(1), ... ) ## S3 method for class ''2d_landscape_batch'' calculate_barrier( l, bg = NULL, start_location_value, start_r, end_location_value, end_r, base = exp(1), ... ) ## S3 method for class ''3d_landscape_batch'' calculate_barrier( l, bg = NULL, start_location_value, start_r, end_location_value, end_r, Umax, expand = TRUE, omit_unstable = FALSE, base = exp(1), ... )
l |
A |
... |
Not in use. |
start_location_value , end_location_value
|
The initial position (in value) for searching the start/end point. |
start_r , end_r
|
The search radius (in L1 distance) for the start/end point. |
base |
The base of the log function. |
Umax |
The highest possible value of the potential function. |
expand |
If the values in the range all equal to |
omit_unstable |
If a state is not stable (the "local minimum" overlaps with the saddle point), omit that state or not? |
bg |
A |
A barrier
object that contains the (batch) barrier calculation result(s).
Compare the distribution of different stages of simulation (for plot_type == "bin"
or plot_type = "density"
), or show how the percentiles of the distribution evolve over time (for plot_type == cumuplot
, see coda::cumuplot()
for details). More convergence checking methods for MCMC data are available at the coda
package. Be cautious: each convergence checking method has its shortcomings, so do not blindly use any results as the definitive conclusion that a simulation converges or not.
check_conv(output, vars, sample_perc = 0.2, plot_type = "bin") ## S3 method for class 'check_conv' print(x, ask = TRUE, ...)
check_conv(output, vars, sample_perc = 0.2, plot_type = "bin") ## S3 method for class 'check_conv' print(x, ask = TRUE, ...)
output |
A matrix of simulation output, or a |
vars |
The names of variables to check. |
sample_perc |
The percentage of data sample for the initial, middle, and final stage of the simulation. Not required if |
plot_type |
Which type of plots should be generated? ("bin", "density", or "cumuplot" which uses |
x |
The object. |
ask |
Ask to press enter to see the next plot? |
... |
Not in use. |
A check_conv
object that contains the convergence checking result(for plot_type == "bin"
or plot_type = "density"
), or draw the cumuplot without a return value (for plot_type == cumuplot
).
print(check_conv)
: Print a check_conv
object.
Get the probability distribution from a landscape object
get_dist(l, index = 1)
get_dist(l, index = 1)
l |
A |
index |
1 to get the distribution in tidy format; 2 or "raw" to get the raw simulation result ( |
A data.frame
that contains the distribution in the tidy format or the raw simulation result.
hash_big_matrix
class is a modified class from bigmemory::big.matrix-class()
. Its purpose is to
help users operate big matrices within hard disk in a reusable way, so that the large matrices do not consume
too much memory, and the matrices can be reused for the next time.
Comparing with bigmemory::big.matrix-class()
, the major enhancement of hash_big_matrix
class
is that the backing files are, by default, stored in a permanent place, with the md5 of the object as the file
name. With this explicit name, hash_big_matrix
objects can be easily reloaded into workspace every time.
as_hash_big_matrix(x, backingpath = "bp", silence = TRUE, ...) attach_hash_big_matrix(x, backingpath = "bp")
as_hash_big_matrix(x, backingpath = "bp", silence = TRUE, ...) attach_hash_big_matrix(x, backingpath = "bp")
x |
A matrix, vector, or data.frame for |
backingpath , ...
|
Passed to |
silence |
Suppress messages? |
as_hash_big_matrix()
: Create a hash_big_matrix
object from a matrix.
attach_hash_big_matrix()
: Attach a hash_big_matrix
object from the backing file to the workspace.
md5
The md5 value of the matrix.
address
Inherited from big.matrix
.
Make a matrix of 2D static landscape plots for one or two parameters
make_2d_matrix( bs, x, rows = NULL, cols, lims, kde_fun = c("ks", "base"), n = 200, h, adjust = 1, Umax = 5, individual_landscape = TRUE )
make_2d_matrix( bs, x, rows = NULL, cols, lims, kde_fun = c("ks", "base"), n = 200, h, adjust = 1, Umax = 5, individual_landscape = TRUE )
bs |
A |
x |
The name of the target variable. |
rows , cols
|
The names of the parameters. |
lims |
The limits of the range for the density estimator as |
kde_fun |
Which kernel estimator to use? Choices: "ks" |
n |
The number of equally spaced points in each axis, at which the density is to be estimated. |
h |
A number, or possibly a vector for 3D and 4D landscapes, specifying the smoothing bandwidth to be used. If missing, the default value of the kernel estimator will be used (but |
adjust |
The multiplier to the bandwidth. The bandwidth used is actually |
Umax |
The maximum displayed value of potential. |
individual_landscape |
Make individual landscape for each simulation? Default is |
A 2d_matrix_landscape
object that describes the landscape of the system, including the smoothed distribution and the landscape plot.
Make 2D static landscape plot for a single simulation output
make_2d_static( output, x, lims, kde_fun = c("ks", "base"), n = 200, h, adjust = 1, Umax = 5, weight_var = NULL ) make_2d_single( output, x, lims, kde_fun = c("ks", "base"), n = 200, h, adjust = 1, Umax = 5, weight_var = NULL )
make_2d_static( output, x, lims, kde_fun = c("ks", "base"), n = 200, h, adjust = 1, Umax = 5, weight_var = NULL ) make_2d_single( output, x, lims, kde_fun = c("ks", "base"), n = 200, h, adjust = 1, Umax = 5, weight_var = NULL )
output |
A matrix of simulation output, or a |
x |
The name of the target variable. |
lims |
The limits of the range for the density estimator as |
kde_fun |
Which kernel estimator to use? Choices: "ks" |
n |
The number of equally spaced points in each axis, at which the density is to be estimated. |
h |
A number, or possibly a vector for 3D and 4D landscapes, specifying the smoothing bandwidth to be used. If missing, the default value of the kernel estimator will be used (but |
adjust |
The multiplier to the bandwidth. The bandwidth used is actually |
Umax |
The maximum displayed value of potential. |
weight_var |
The name of the weight variable, in case the weight of each observation is different. This may be useful when a weighted MC (e.g., importance sampling) is used. Only effective for |
A 2d_static_landscape
object that describes the landscape of the system, including the smooth distribution and the landscape plot.
Make 3d animations from multiple simulations
make_3d_animation( bs, x, y, fr, lims, kde_fun = c("ks", "MASS"), n = 200, h, adjust = 1, Umax = 5, individual_landscape = TRUE, mat_3d = FALSE )
make_3d_animation( bs, x, y, fr, lims, kde_fun = c("ks", "MASS"), n = 200, h, adjust = 1, Umax = 5, individual_landscape = TRUE, mat_3d = FALSE )
bs |
A |
x , y
|
The names of the target variables. |
fr |
The names of the parameters used to represent frames in the animation. |
lims |
The limits of the range for the density estimator as |
kde_fun |
Which kernel estimator to use? Choices: "ks" |
n |
The number of equally spaced points in each axis, at which the density is to be estimated. |
h |
A number, or possibly a vector for 3D and 4D landscapes, specifying the smoothing bandwidth to be used. If missing, the default value of the kernel estimator will be used (but |
adjust |
The multiplier to the bandwidth. The bandwidth used is actually |
Umax |
The maximum displayed value of potential. |
individual_landscape |
Make individual landscape for each simulation? Default is |
mat_3d |
Also make the matrix by |
A 3d_animation_landscape
object that describes the landscape of the system, including the smoothed distribution and the landscape plot.
Currently only 3D (x, y, color) is supported. Matrices with 3D (x, y, z) plots are not supported.
make_3d_matrix( bs, x, y, rows = NULL, cols, lims, kde_fun = c("ks", "MASS"), n = 200, h, adjust = 1, Umax = 5, individual_landscape = TRUE )
make_3d_matrix( bs, x, y, rows = NULL, cols, lims, kde_fun = c("ks", "MASS"), n = 200, h, adjust = 1, Umax = 5, individual_landscape = TRUE )
bs |
A |
x , y
|
The names of the target variables. |
rows , cols
|
The names of the parameters. |
lims |
The limits of the range for the density estimator as |
kde_fun |
Which kernel estimator to use? Choices: "ks" |
n |
The number of equally spaced points in each axis, at which the density is to be estimated. |
h |
A number, or possibly a vector for 3D and 4D landscapes, specifying the smoothing bandwidth to be used. If missing, the default value of the kernel estimator will be used (but |
adjust |
The multiplier to the bandwidth. The bandwidth used is actually |
Umax |
The maximum displayed value of potential. |
individual_landscape |
Make individual landscape for each simulation? Default is |
A 3d_matrix_landscape
object that describes the landscape of the system, including the smoothed distribution and the landscape plot.
Make 3D static landscape plots from simulation output
make_3d_static( output, x, y, lims, kde_fun = c("ks", "MASS"), n = 200, h, adjust = 1, Umax = 5, weight_var = NULL ) make_3d_single( output, x, y, lims, kde_fun = c("ks", "MASS"), n = 200, h, adjust = 1, Umax = 5, weight_var = NULL )
make_3d_static( output, x, y, lims, kde_fun = c("ks", "MASS"), n = 200, h, adjust = 1, Umax = 5, weight_var = NULL ) make_3d_single( output, x, y, lims, kde_fun = c("ks", "MASS"), n = 200, h, adjust = 1, Umax = 5, weight_var = NULL )
output |
A matrix of simulation output, or a |
x , y
|
The names of the target variables. |
lims |
The limits of the range for the density estimator as |
kde_fun |
Which kernel estimator to use? Choices: "ks" |
n |
The number of equally spaced points in each axis, at which the density is to be estimated. |
h |
A number, or possibly a vector for 3D and 4D landscapes, specifying the smoothing bandwidth to be used. If missing, the default value of the kernel estimator will be used (but |
adjust |
The multiplier to the bandwidth. The bandwidth used is actually |
Umax |
The maximum displayed value of potential. |
weight_var |
The name of the weight variable, in case the weight of each observation is different. This may be useful when a weighted MC (e.g., importance sampling) is used. Only effective for |
A 3d_static_landscape
object that describes the landscape of the system, including the smooth distribution and the landscape plot.
Make 4D static space-color plots from simulation output
make_4d_static( output, x, y, z, lims, kde_fun = "ks", n = 50, h, adjust = 1, Umax = 5, weight_var = NULL ) make_4d_single( output, x, y, z, lims, kde_fun = "ks", n = 50, h, adjust = 1, Umax = 5, weight_var = NULL )
make_4d_static( output, x, y, z, lims, kde_fun = "ks", n = 50, h, adjust = 1, Umax = 5, weight_var = NULL ) make_4d_single( output, x, y, z, lims, kde_fun = "ks", n = 50, h, adjust = 1, Umax = 5, weight_var = NULL )
output |
A matrix of simulation output, or a |
x , y , z
|
The names of the target variables. |
lims |
The limits of the range for the density estimator as |
kde_fun |
Which kernel estimator to use? Choices: "ks" |
n |
The number of equally spaced points in each axis, at which the density is to be estimated. |
h |
A number, or possibly a vector for 3D and 4D landscapes, specifying the smoothing bandwidth to be used. If missing, the default value of the kernel estimator will be used (but |
adjust |
The multiplier to the bandwidth. The bandwidth used is actually |
Umax |
The maximum displayed value of potential. |
weight_var |
The name of the weight variable, in case the weight of each observation is different. This may be useful when a weighted MC (e.g., importance sampling) is used. Only effective for |
A 4d_static_landscape
object that describes the landscape of the system, including the smoothed distribution and the landscape plot.
Make a grid for calculating barriers for 2d landscapes
make_barrier_grid_2d( ag, start_location_value, start_r, end_location_value, end_r, df = NULL, print_template = FALSE )
make_barrier_grid_2d( ag, start_location_value, start_r, end_location_value, end_r, df = NULL, print_template = FALSE )
ag |
An |
start_location_value , start_r , end_location_value , end_r
|
Default values for finding local minimum. See |
df |
A data frame for the variables. Use |
print_template |
Print a template for |
A barrier_grid_2d
object that specifies the condition for each barrier calculation.
Make a grid for calculating barriers for 3d landscapes
make_barrier_grid_3d( ag, start_location_value, start_r, end_location_value, end_r, df = NULL, print_template = FALSE )
make_barrier_grid_3d( ag, start_location_value, start_r, end_location_value, end_r, df = NULL, print_template = FALSE )
ag |
An |
start_location_value , start_r , end_location_value , end_r
|
Default values for finding local minimum. See |
df |
A data frame for the variables. Use |
print_template |
Print a template for |
A barrier_grid_3d
object that specifies the condition for each barrier calculation.
Simulate multiple Monte Carlo simulations of 1-3D Markovian Stochastic Differential Equations from a grid or random sample of initial values.
Parallel processing is supported. To register a parallel backend, use future::plan()
. For example, future::plan(future::multisession)
. For more information, see future::plan()
. Functions imported from other programming languages, such as C++ or Python functions, may not work in parallel processing.
If you are uncertain whether there are unknown stable states of the system that are difficult to reach, it is recommended to start with running a large number (i.e., increasing R
) of short simulations to see if the system reaches to the known stable states.
multi_init_simulation( sim_fun, R = 10, range_x0, sample_mode = c("grid", "random"), ..., .furrr_options = list(.options = furrr::furrr_options(seed = TRUE)), return_object = c("mcmc.list", "raw") )
multi_init_simulation( sim_fun, R = 10, range_x0, sample_mode = c("grid", "random"), ..., .furrr_options = list(.options = furrr::furrr_options(seed = TRUE)), return_object = c("mcmc.list", "raw") )
sim_fun |
The simulation function to use. It should accept an argument |
R |
The number of initial values to sample. If |
range_x0 |
The range of initial values to sample in a vector of length 2 for each dimension (i.e., |
sample_mode |
The mode of sampling initial values. Either "grid" or "random". If "grid", the initial values will be sampled from a grid. If "random", the initial values will be sampled randomly. |
... |
Additional arguments passed to |
.furrr_options |
A list of options to be passed to |
return_object |
The type of object to return. Either "mcmc.list" or "raw". If "mcmc.list", a list of mcmc objects will be returned. If "raw", a tibble of initial values and raw simulation results will be returned. |
A list of mcmc objects or a tibble of initial values and raw simulation results, depending on the value of return_object
.
# Adapted from the example in the Sim.DiffProc package set.seed(1234, kind = "L'Ecuyer-CMRG") mu <- 4 sigma <- 0.1 fx <- expression(y, (mu * (1 - x^2) * y - x)) gx <- expression(0, 2 * sigma) multiple_mod2d <- multi_init_simulation(sim_SDE, range_x0 = c(-3, 3, -10, 10), R = 3, sample_mode = "grid", drift = fx, diffusion = gx, N = 1000, Dt = 0.01, type = "str", method = "rk1", keep_full = FALSE, M = 2) # The output is a mcmc.list object. You can use the functions # in the coda package to modify it and perform convergence check, # for example, library(coda) plot(multiple_mod2d) window(multiple_mod2d, start = 500) effectiveSize(multiple_mod2d)
# Adapted from the example in the Sim.DiffProc package set.seed(1234, kind = "L'Ecuyer-CMRG") mu <- 4 sigma <- 0.1 fx <- expression(y, (mu * (1 - x^2) * y - x)) gx <- expression(0, 2 * sigma) multiple_mod2d <- multi_init_simulation(sim_SDE, range_x0 = c(-3, 3, -10, 10), R = 3, sample_mode = "grid", drift = fx, diffusion = gx, N = 1000, Dt = 0.01, type = "str", method = "rk1", keep_full = FALSE, M = 2) # The output is a mcmc.list object. You can use the functions # in the coda package to modify it and perform convergence check, # for example, library(coda) plot(multiple_mod2d) window(multiple_mod2d, start = 500) effectiveSize(multiple_mod2d)
Make plots from landscape objects
## S3 method for class 'landscape' plot(x, index = 1, ...)
## S3 method for class 'landscape' plot(x, index = 1, ...)
x |
A landscape object |
index |
Default is 1. For some landscape objects, there is a second plot (usually 2d heatmaps for 3d landscapes)
or a third plot (usually 3d matrices for 3d animations).
Use |
... |
Not in use. |
The plot.
Save landscape plots
save_landscape(l, path = NULL, selfcontained = FALSE, ...)
save_landscape(l, path = NULL, selfcontained = FALSE, ...)
l |
A landscape object |
path |
The path to save the output. Default: "/pics/x_y.html". |
selfcontained |
For 'plotly' plots, save the output as a self-contained html file? Default: FALSE. |
... |
Other parameters passed to |
The function saves the plot to a specific path. It does not have a return value.
This is a toy stochastic gradient system which can have bistability in some conditions. Model specification:
sim_fun_grad( initial = list(x = 0, y = 0), parameter = list(a = -4, b = 0, c = 0, sigmasq = 1), length = 1e+05, stepsize = 0.01, seed = NULL )
sim_fun_grad( initial = list(x = 0, y = 0), parameter = list(a = -4, b = 0, c = 0, sigmasq = 1), length = 1e+05, stepsize = 0.01, seed = NULL )
initial , parameter
|
Two sets of parameters. |
length |
The length of simulation. |
stepsize |
The step size used in the Euler method. |
seed |
The initial seed that will be passed to |
A matrix of simulation results.
sim_fun_nongrad()
and batch_simulation()
.
This is a toy stochastic non-gradient system which can have multistability in some conditions. Model specification:
sim_fun_nongrad( initial = list(x1 = 0, x2 = 0, a = 1), parameter = list(b = 1, k = 1, S = 0.5, n = 4, lambda = 0.01, sigmasq1 = 8, sigmasq2 = 8, sigmasq3 = 2), constrain_a = TRUE, amin = -0.3, amax = 1.8, length = 1e+05, stepsize = 0.01, seed = NULL, progress = TRUE )
sim_fun_nongrad( initial = list(x1 = 0, x2 = 0, a = 1), parameter = list(b = 1, k = 1, S = 0.5, n = 4, lambda = 0.01, sigmasq1 = 8, sigmasq2 = 8, sigmasq3 = 2), constrain_a = TRUE, amin = -0.3, amax = 1.8, length = 1e+05, stepsize = 0.01, seed = NULL, progress = TRUE )
initial , parameter
|
Two sets of parameters. |
constrain_a |
Should the value of |
amin , amax
|
If |
length |
The length of simulation. |
stepsize |
The step size used in the Euler method. |
seed |
The initial seed that will be passed to |
progress |
Show progress bar of the simulation? |
A matrix of simulation results.
Wang, J., Zhang, K., Xu, L., & Wang, E. (2011). Quantifying the Waddington landscape and biological paths for development and differentiation. Proceedings of the National Academy of Sciences, 108(20), 8257-8262. doi:10.1073/pnas.1017017108
sim_fun_grad()
and batch_simulation()
.
A simple simulation function for testing
sim_fun_test(arg1, arg2, length = 1000)
sim_fun_test(arg1, arg2, length = 1000)
arg1 , arg2
|
Two parameters. |
length |
The length of simulation. |
A matrix of simulation results.
sim_fun_grad()
and sim_fun_nongrad()
for more realistic
examples.
A wrapper to the simulation utilities provided by the Sim.DiffProc package. You may skip this step and write your own simulation function for more customized simulation.
sim_SDE( N = 1000, M = 1, x0, t0 = 0, T = 1, Dt = rlang::missing_arg(), drift, diffusion, corr = NULL, alpha = 0.5, mu = 0.5, type = "ito", method = "euler", keep_full = TRUE )
sim_SDE( N = 1000, M = 1, x0, t0 = 0, T = 1, Dt = rlang::missing_arg(), drift, diffusion, corr = NULL, alpha = 0.5, mu = 0.5, type = "ito", method = "euler", keep_full = TRUE )
N |
The number of time steps. |
M |
The number of simulations. |
x0 |
The initial values of the SDE. The number of values determine the dimension of the SDE. |
t0 |
initial time. |
T |
terminal time. |
Dt |
time step. If missing, default will be (T - t0) / N. |
drift |
An expression of the drift function. The number of expressions determine the dimension of the SDE. Should be the function of |
diffusion |
An expression of the diffusion function. The number of expressions determine the dimension of the SDE. Should be the function of |
corr |
The correlations between the Brownian motions. Only used for 2D or 3D cases. Must be a real symmetric positive-definite matrix of size 2x2 or 3x3. If NULL, the default is the identity matrix. |
alpha , mu
|
weight of the predictor-corrector scheme; the default |
type |
if |
method |
numerical methods of simulation, the default |
keep_full |
Whether to keep the full snssde1d/snssde2d/snssde3d object. If TRUE, the full object will be returned. If FALSE, only the simulated values will be returned as a matrix or a list of matrices (when |
Depending on the value of keep_full
, the output will be a list of snssde1d
, snssde2d
or snssde3d
objects, or a matrix or a list of matrices of the simulated values.
# From the Sim.DiffProc package set.seed(1234, kind = "L'Ecuyer-CMRG") mu <- 4 sigma <- 0.1 fx <- expression(y, (mu * (1 - x^2) * y - x)) gx <- expression(0, 2 * sigma) mod2d <- sim_SDE(drift = fx, diffusion = gx, N = 1000, Dt = 0.01, x0 = c(0, 0), type = "str", method = "rk1", M = 2, keep_full = FALSE) print(as.mcmc.list(mod2d))
# From the Sim.DiffProc package set.seed(1234, kind = "L'Ecuyer-CMRG") mu <- 4 sigma <- 0.1 fx <- expression(y, (mu * (1 - x^2) * y - x)) gx <- expression(0, 2 * sigma) mod2d <- sim_SDE(drift = fx, diffusion = gx, N = 1000, Dt = 0.01, x0 = c(0, 0), type = "str", method = "rk1", M = 2, keep_full = FALSE) print(as.mcmc.list(mod2d))
barrier
objectSummarize the barrier height from a barrier
object
## S3 method for class 'barrier' summary(object, ...)
## S3 method for class 'barrier' summary(object, ...)
object |
A |
... |
Not in use. |
A vector (for a single barrier calculation result) or a data.frame
(for batch barrier calculation results) that contains the barrier heights on the landscape.