Skip to content

Commit

Permalink
update manual with info about ignore vs ADbreak
Browse files Browse the repository at this point in the history
  • Loading branch information
paciorek committed Dec 11, 2023
1 parent a401281 commit b40bd9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions UserManual/src/chapter_AD.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ Because derivatives are not tracked for integer or logical variables, arguments

Note the more elaborate value for `buildDerivs`. Above, this was just a character vector. Here it is a named list, with each element itself being a list of control values. The control value `ignore` is a character vector of variable names to ignore in derivative tracking. `buildDerivs = 'run'` is equivalent to `buildDerivs = list(run = list())`.

#### Holding variables passed from a model out of derivative tracking

In the case of not tracking derivatives for variables passed from a model, using `ignore` will not work. Instead, one should use `ADbreak`. For example if one has a model variable that is passed into a nimbleFunction as the argument `x`, one would do `x_noDeriv <- ADbreak(x)`.

`ignore` doesn't work because it makes the input argument be a base type (`double`) rather than an AD type (`CppAD::AD<double>`). This will not work for model variables passed in as arguments, because all model variables are of a special "AD" type.

### Using AD with multiple nimbleFunctions

Derivatives will be tracked through whatever series of calculations occur in a method, possibly including calls to other methods or nimbleFunctions that have `buildDerivs` set. Let's look at an example where we have a separate function to return the element-wise square root of an input vector. The net calculation for derivatives will be `sqrt(exp(-d*x)))`.
Expand Down
1 change: 1 addition & 0 deletions packages/nimble/R/types_symbolTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ symbolBasic <-
}
},
genCppVar = function(functionArg = FALSE) {
browser()
if(type == 'void') return(cppVoid())
else if(type == 'integer') cType <- 'int'
else if(type == 'double') cType <- 'double'
Expand Down

0 comments on commit b40bd9b

Please sign in to comment.