Closed bragef closed 1 year ago
If ifelse() is used in the objective function, the class attribute is lost, resulting in an error.
ifelse()
> class(ifelse(TRUE,advector(1),advector(1))) [1] "complex"
Example
library(RTMB) Z <- rnorm(10) > 0 Y <- rnorm(10,10) * Z + rnorm(10,-10) * (1-Z) par <- list(a=1) f <- function(par) { a <- par$a logls <- ifelse(Z, dnorm(Y, par$a, log=TRUE), dnorm(Y, -par$a,log=TRUE)) # class(logls) <- "advector" -sum(logls) } obj <- MakeADFun(f, par) opt <- nlminb(obj$par,obj$fn) sdreport(obj)
Yes, I've noticed that too. ifelse is used so frequently that it has to be fixed.
ifelse
If
ifelse()
is used in the objective function, the class attribute is lost, resulting in an error.Example