1

Is it possible to set a seed (like R's set.seed() function) in the diffeqr package in R, while solving stochastic differential equations?

Example

library(diffeqr)
f <- function(u,p,t) {
  return(1.01*u)
}
g <- function(u,p,t) {
  return(0.87*u)
}
u0 = 1/2
tspan <- list(0.0,1.0)
sol = sde.solve(f,g,u0,tspan, alg = "SKenCarp()")
udf = as.data.frame(sol$u)
plotly::plot_ly(udf, x = sol$t, y = sol$u, type = 'scatter', mode = 'lines')

I found in the documentation, that the possibility was present to set a seed, however, if I add it to:

sde.solve(f,g,u0,tspan, alg = "SKenCarp()", seed = 123)

It won't work. Is it possible to set a seed in this R package?

Chris Rackauckas
  • 18,645
  • 3
  • 50
  • 81
user213544
  • 2,046
  • 3
  • 22
  • 52

1 Answers1

1
library(diffeqr)
diffeqr::diffeq_setup()
f <- function(u,p,t) {
  return(1.01*u)
}
g <- function(u,p,t) {
  return(0.87*u)
}
u0 = 1/2
tspan <- list(0.0,1.0)
sol = sde.solve(f,g,u0,tspan, alg = "SKenCarp()", seed=1)
udf = as.data.frame(sol$u)
plotly::plot_ly(udf, x = sol$t, y = sol$u, type = 'scatter', mode = 'lines')

Now works on diffeqr v0.1.3, which was just submitted to CRAN.

BTW, SKenCarp probably isn't the right method for this problem, but I assume you're testing it for other reasons.

Chris Rackauckas
  • 18,645
  • 3
  • 50
  • 81