1 lexp <- function(idmc_model, par, var, time, eps) {
3 checkModelParVar(m, par, var)
4 checkPositiveScalar(time)
5 if(getModelType(m)=='C') {
7 eps <- getOption('ts.eps')
8 message('using eps = ', eps)
10 checkPositiveScalar(eps)
11 ans <- .Call("ridmc_lexp_ode", m$model, as.double(par), as.double(var),
12 as.double(time), as.double(eps), PACKAGE='RiDMC')
14 ans <- .Call("ridmc_lexp", m$model,
15 as.double(par), as.double(var), as.integer(time), PACKAGE='RiDMC')
20 LyapunovExponents <- function(idmc_model, par, var, time, eps,
21 which.par.vary=1, par.min, par.max, par.howMany=100) {
22 checkModelParVar(idmc_model, par, var)
23 checkPositiveScalar(time)
24 modelType <- getModelType(idmc_model)
27 eps <- getOption('ts.eps')
28 message('using eps = ', eps)
30 checkPositiveScalar(eps)
35 parValues <- seq(par.min, par.max, length=np)
38 for(i in seq_along(parValues)) {
39 par[which.par.vary] <- parValues[i]
40 val[i,] <- .Call("ridmc_lexp", m$model,
41 as.double(par), as.double(var),
42 as.integer(time), PACKAGE='RiDMC')
44 } else if(modelType=='C'){
45 for(i in seq_along(parValues)) {
46 par[which.par.vary] <- parValues[i]
47 val[i,] <- .Call("ridmc_lexp_ode",
48 m$model, as.double(par), as.double(var),
49 as.double(time), as.double(eps), PACKAGE='RiDMC')
52 stop('invalid model type')
54 ans$model <- idmc_model
58 ans$par.values <- parValues
59 ans$which.par <- getModelParNames(m)[which.par.vary]
60 class(ans) <- 'idmc_lexp_diagram'
63 as.matrix.idmc_lexp_diagram <- function(x, ...)
66 print.idmc_lexp_diagram <- function(x, ...) {
68 cat('=iDMC Lyapunov exponents diagram=\n')
69 cat('Model: ', getModelName(m), '\n')
70 cat('Starting point: ')
71 tmp <- getModelVarNames(m)
72 cat(paste(tmp, x$var, sep=' = ', collapse=', '), '\n')
73 cat('Parameter values: ')
74 tmp <- getModelParNames(m)
75 cat(paste(tmp, x$par, sep=' = ', collapse=', '), '\n')
76 cat('Varying par.: ', x$which.par, '\n')
77 cat('Varying par. range: [', paste(range(x$par.values), collapse=', '), ']\n')
78 mle <- range(apply(x$values, 1, max, na.rm=TRUE), na.rm=TRUE)
79 cat('MLE range: [', paste(format(mle, digits=4), collapse=', '), ']\n')
82 as.grob.idmc_lexp_diagram <- function(x, col, lty, ylim = NULL, ...) {
92 ylim <- range(as.vector(y))
95 lines[[j]] <- linesGrob(x1, y[,j], gp=gpar(col=col[j], lty=lty[j], ...), default.units = "native")
96 lines <- do.call(gList, lines)
97 cG <- gTree(children=lines, name='lines')
98 contentsGrob(cG, xlim=xlim, ylim=ylim)
101 plot.idmc_lexp_diagram <- function(x, y, col, lty,
102 main = getModelName(x$model),
104 ylab = 'Lyapunov exponent',
110 cG <- as.grob(x, col, lty, ylim = NULL, ...)
111 pG <- plotGrob(cG, axes=axes, main=main, xlab=xlab, ylab=ylab, mar=mar)