Skip to content

Commit 16f2668

Browse files
committed
Cleaned up examples + moved outdated vignettes folder to workshops
1 parent 5289195 commit 16f2668

78 files changed

Lines changed: 1549 additions & 1815 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,57 @@
1+
# -------------------------------------------------
12
# R / RStudio
3+
# -------------------------------------------------
24
.Rproj.user/
35
.Rhistory
46
.RData
57
.Rbuildignore
68

9+
# -------------------------------------------------
710
# Git / Editor
11+
# -------------------------------------------------
812
.gitignore.swp
13+
.DS_Store
14+
Thumbs.db
915

16+
# -------------------------------------------------
17+
# R CMD check / build artefacts
18+
# -------------------------------------------------
19+
*.tar.gz
20+
*.Rcheck/
21+
.Rcheck/
22+
inst/doc/
23+
24+
# -------------------------------------------------
25+
# R Markdown / knitr
26+
# -------------------------------------------------
27+
README.html
28+
README_files/
29+
*.knit.md
30+
*.utf8.md
31+
*_cache/
32+
*_files/
33+
.cache/
34+
35+
# -------------------------------------------------
1036
# Working directories
37+
# -------------------------------------------------
1138
/wd/
1239
/deriv2Tests/
40+
inst/workshops/
1341

14-
# Files starting with .f
42+
# -------------------------------------------------
43+
# Temporary / generated files
44+
# -------------------------------------------------
1545
.f*
46+
*.log
47+
*.tmp
1648

49+
# -------------------------------------------------
1750
# Compiled objects
51+
# -------------------------------------------------
1852
*.c
1953
*.o
2054
*.so
21-
55+
*.dll
56+
*.a
57+
*.dylib

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Description: The framework provides functions to generate ODEs of reaction
1111
used for optimization whenever possible. Therefore, all major functions produce
1212
and can handle expressions for symbolic derivatives.
1313
License: GPL (>= 2)
14-
LinkingTo: BH
1514
Depends:
1615
cOde (>= 1.1)
1716
Imports:
@@ -35,7 +34,9 @@ Imports:
3534
abind,
3635
einsum,
3736
optimx,
38-
nleqslv
37+
nleqslv,
38+
reticulate,
39+
BH
3940
Remotes:
4041
simonbeyer1/CppODE@v1.0.0
4142
Suggests:
@@ -44,6 +45,5 @@ Suggests:
4445
knitr,
4546
rmarkdown,
4647
RoxygenNote: 7.3.3
47-
VignetteBuilder: knitr
4848
Encoding: UTF-8
4949
Roxygen: list(markdown = TRUE)

NAMESPACE

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,16 @@ S3method(wide2long,data.frame)
124124
S3method(wide2long,list)
125125
S3method(wide2long,matrix)
126126
export("%.*%")
127-
export("+.objlist")
128127
export("controls<-")
129128
export("modelname<-")
130129
export(Id)
131130
export(P)
132131
export(Pexpl)
133132
export(Pimpl)
134-
export(SVDIA)
135133
export(Xd)
136134
export(Xf)
137135
export(Xs)
136+
export(Xt)
138137
export(Y)
139138
export(addEvent)
140139
export(addReaction)
@@ -242,8 +241,6 @@ export(plotPrediction)
242241
export(plotProfile)
243242
export(plotProfilesAndPaths)
244243
export(plotResiduals)
245-
export(plotRightVector)
246-
export(plotSVDs)
247244
export(plotValues)
248245
export(prdfn)
249246
export(prdframe)
@@ -317,7 +314,6 @@ importFrom(ggplot2,ylab)
317314
importFrom(graphics,par)
318315
importFrom(nleqslv,nleqslv)
319316
importFrom(optimx,optimr)
320-
importFrom(parallel,mclapply)
321317
importFrom(reticulate,import)
322318
importFrom(reticulate,py_run_string)
323319
importFrom(rjson,fromJSON)

R/classes.R

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,17 +1421,19 @@ test_conditions <- function(c1, c2) {
14211421
#' @param ... arguments going to the appropriate S3 methods
14221422
#' @return Either a print-out or the values of the control.
14231423
#' @examples
1424-
#' ## parfn with condition
1425-
#' p <- P(eqnvec(x = "-a*x"), method = "implicit", condition = "C1")
1426-
#' controls(p)
1427-
#' controls(p, "C1", "keep.root")
1428-
#' controls(p, "C1", "keep.root") <- FALSE
1429-
#'
1430-
#' ## obsfn with NULL condition
1431-
#' g <- Y(g = eqnvec(y = "s*x"), f = NULL, states = "x", parameters = "s")
1432-
#' controls(g)
1433-
#' controls(g, NULL, "attach.input")
1434-
#' controls(g, NULL, "attach.input") <- FALSE
1424+
#' \dontrun{
1425+
#' ## parfn with condition
1426+
#' p <- P(eqnvec(x = "-a*x"), method = "implicit", condition = "C1")
1427+
#' controls(p)
1428+
#' controls(p, "C1", "keep.root")
1429+
#' controls(p, "C1", "keep.root") <- FALSE
1430+
#'
1431+
#' ## obsfn with NULL condition
1432+
#' g <- Y(g = eqnvec(y = "s*x"), f = NULL, states = "x", parameters = "s")
1433+
#' controls(g)
1434+
#' controls(g, NULL, "attach.input")
1435+
#' controls(g, NULL, "attach.input") <- FALSE
1436+
#' }
14351437
#' @export
14361438
controls <- function(x, ...) {
14371439
UseMethod("controls", x)

R/eventClass.R

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
#' @export
1616
#'
1717
#' @examples
18-
#' eventlist(var = "A", time = "5", value = 1, method = "add")
19-
#'
20-
#' events <- addEvent(NULL, var = "A", time = "5", value = 1, method = "add")
21-
#' events <- addEvent(events, var = "A", time = "10", value = 1, method = "add")
22-
#'
23-
#' # With symbols
24-
#' events <- eventlist()
25-
#' # Set "A" to "value_switch" at time "time_Switch"
26-
#' events <- addEvent(events, var = "A", time = "time_switch", value = "value_switch", method = "replace")
27-
#' # Set "B" to 2 when "A" reaches "A_target". The time-parameter for internal use will be "time_root".
28-
#' events <- addEvent(events, var = "B", time = "time_root", value = 2, root = "A - A_target", method = "replace")
18+
#' \dontrun{
19+
#' eventlist(var = "A", time = "5", value = 1, method = "add")
20+
#'
21+
#' events <- addEvent(NULL, var = "A", time = "5", value = 1, method = "add")
22+
#' events <- addEvent(events, var = "A", time = "10", value = 1, method = "add")
23+
#'
24+
#' # With symbols
25+
#' events <- eventlist()
26+
#' # Set "A" to "value_switch" at time "time_Switch"
27+
#' events <- addEvent(events, var = "A", time = "time_switch", value = "value_switch", method = "replace")
28+
#' # Set "B" to 2 when "A" reaches "A_target". The time-parameter for internal use will be "time_root".
29+
#' events <- addEvent(events, var = "B", time = "time_root", value = 2, root = "A - A_target", method = "replace")
30+
#' }
2931
eventlist <- function(var = NULL, time = NULL, value = NULL, root = NULL, method = NULL) {
3032

3133
# root is NULL if all are NULL or NA if any is not NULL

R/objClass.R

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,15 +1262,8 @@ nll_BLOQ <- function(nout.bloq,
12621262
#' the corresponding elements of out1 and out2 as they are.
12631263
#' @return List of length of out1.
12641264
#' @aliases sumobjlist
1265-
#' @export "+.objlist"
12661265
#' @export
12671266
#'
1268-
#' @examples
1269-
#' objlist1 <- dMod:::init_empty_objlist(c(a = 1, b = 2))
1270-
#' objlist1$value = 1; objlist1$gradient[1:2] <- 1; objlist1$hessian[1:4] <- 1
1271-
#' objlist2 <- dMod:::init_empty_objlist(c(a = 1, d = 2))
1272-
#' objlist2$value = 1; objlist2$gradient[1:2] <- 1; objlist2$hessian[1:4] <- 1
1273-
#' objlist1 + objlist2
12741267
"+.objlist" <- function(out1, out2) {
12751268

12761269
if (is.null(out1)) return(out2)

R/prediction.R

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ Xs.deSolve <- function(odemodel,
188188
#' and proper `dimnames` for variables and parameters.
189189
#'
190190
#' @examples
191-
#' # Example column names: "A.k1", "A.k2", "B.k1", "B.k2"
192-
#' mysens <- matrix(runif(40), nrow = 10)
193-
#' colnames(mysens) <- c("A.k1", "A.k2", "B.k1", "B.k2")
194-
#' reshapeSens(mysens, variables = c("A", "B"), parameters = c("k1", "k2"))
195-
#'
191+
#' \dontrun{
192+
#' # Example column names: "A.k1", "A.k2", "B.k1", "B.k2"
193+
#' mysens <- matrix(runif(40), nrow = 10)
194+
#' colnames(mysens) <- c("A.k1", "A.k2", "B.k1", "B.k2")
195+
#' reshapeSens(mysens, variables = c("A", "B"), parameters = c("k1", "k2"))
196+
#' }
196197
#' @keywords internal
197198
reshapeSens <- function(sensMatrix, variables, parameters) {
198199
n_times <- nrow(sensMatrix)
@@ -521,6 +522,7 @@ Xf <- function(odemodel, forcings = NULL, events = NULL, condition = NULL, optio
521522
#' the data frame), and possibly "pouter", a named numeric vector which is generated
522523
#' from `data$value`.
523524
#' @examples
525+
#' \dontrun{
524526
#' # Generate a data.frame and corresponding prediction function
525527
#' timesD <- seq(0, 2*pi, 0.5)
526528
#' mydata <- data.frame(name = "A", time = timesD, value = sin(timesD),
@@ -533,6 +535,7 @@ Xf <- function(odemodel, forcings = NULL, events = NULL, condition = NULL, optio
533535
#' prediction <- x(times, pouter)
534536
#' plot(prediction)
535537
#'
538+
#' }
536539
#' @export
537540
Xd <- function(data, condition = NULL) {
538541

@@ -1030,51 +1033,53 @@ Y <- function(g, f = NULL, states = NULL, parameters = NULL, condition = NULL,
10301033
}
10311034

10321035

1033-
# #' Generate a prediction function that returns times
1034-
# #'
1035-
# #' Function to deal with non-ODE models within the framework of dMod. See example.
1036-
# #'
1037-
# #' @param condition either NULL (generic prediction for any condition) or a character, denoting
1038-
# #' the condition for which the function makes a prediction.
1039-
# #' @return Object of class [prdfn].
1040-
# #' @examples
1041-
# #' x <- Xt()
1042-
# #' g <- Y(c(y = "a*time^2+b"), f = NULL, parameters = c("a", "b"))
1043-
# #'
1044-
# #' times <- seq(-1, 1, by = .05)
1045-
# #' pars <- c(a = .1, b = 1)
1046-
# #'
1047-
# #' plot((g*x)(times, pars))
1048-
# #' @export
1049-
# Xt <- function(condition = NULL) {
1050-
#
1051-
#
1052-
#
1053-
# # Controls to be modified from outside
1054-
# controls <- list()
1055-
#
1056-
# P2X <- function(times, pars, deriv=TRUE){
1057-
#
1058-
# out <- matrix(times, ncol = 1, dimnames = list(NULL, "time"))
1059-
# sens <- deriv <- out
1060-
#
1061-
# prdframe(out, deriv = deriv, sensitivities = sens, parameters = pars)
1062-
#
1063-
# }
1064-
#
1065-
# attr(P2X, "parameters") <- NULL
1066-
# attr(P2X, "equations") <- NULL
1067-
# attr(P2X, "forcings") <- NULL
1068-
# attr(P2X, "events") <- NULL
1069-
#
1070-
#
1071-
# prdfn(P2X, NULL, condition)
1072-
#
1073-
#
1074-
#
1075-
#
1076-
# }
1077-
1036+
#' Generate a prediction function that returns times
1037+
#'
1038+
#' Function to deal with non-ODE models within the framework of dMod. See example.
1039+
#'
1040+
#' @param condition either NULL (generic prediction for any condition) or a character, denoting
1041+
#' the condition for which the function makes a prediction.
1042+
#' @return Object of class [prdfn].
1043+
#' @examples
1044+
#' x <- Xt()
1045+
#' g <- Y(c(y = "a*time^2+b"), f = NULL, parameters = c("a", "b"))
1046+
#'
1047+
#' times <- seq(-1, 1, by = .05)
1048+
#' pars <- c(a = .1, b = 1)
1049+
#'
1050+
#' plot((g*x)(times, pars))
1051+
#' @export
1052+
Xt <- function(condition = NULL) {
1053+
# Controls to be modified from outside
1054+
controls <- list()
1055+
P2X <- function(times, pars, deriv = TRUE, deriv2 = FALSE, ...) {
1056+
n_times <- length(times)
1057+
n_pars <- length(pars)
1058+
par_names <- names(pars)
1059+
1060+
# Output: matrix with time column
1061+
out <- matrix(times, ncol = 1, dimnames = list(NULL, "time"))
1062+
1063+
# Sensitivities (deriv): 3D array [n_times, n_states, n_pars]
1064+
# time has no dependence on parameters, so all zeros
1065+
sens <- array(0,
1066+
dim = c(n_times, 1, n_pars),
1067+
dimnames = list(NULL, "time", par_names))
1068+
1069+
# Second derivatives (deriv2): 4D array [n_times, n_states, n_pars, n_pars]
1070+
# All zeros since time is independent of parameters
1071+
deriv2_arr <- array(0,
1072+
dim = c(n_times, 1, n_pars, n_pars),
1073+
dimnames = list(NULL, "time", par_names, par_names))
1074+
1075+
prdframe(out, deriv = sens, deriv2 = deriv2_arr, parameters = pars)
1076+
}
1077+
attr(P2X, "parameters") <- NULL
1078+
attr(P2X, "equations") <- NULL
1079+
attr(P2X, "forcings") <- NULL
1080+
attr(P2X, "events") <- NULL
1081+
prdfn(P2X, NULL, condition)
1082+
}
10781083

10791084

10801085
#' An identity function which vanishes upon concatenation of fns

0 commit comments

Comments
 (0)