Problems with eigen()

21 views
Skip to first unread message

Jan-Ole Koslik

unread,
Jun 13, 2025, 4:16:49 AMJun 13
to TMB Users
Hi, I encountered a problem which I don't understand:

library(RTMB)
f <- function(par) {
  # don't know if these are necessary
  "[<-" <- ADoverload("[<-")
  "c" <- ADoverload("c")
  "diag<-" <- ADoverload("diag<-")
 
  # build Q matrix with special structure from par
  N <- as.integer(0.5 + sqrt(0.25 + length(par)), 0)
  Q <- diag(N)
  Q[!Q] <- exp(par)
  diag(Q) <- 0
  diag(Q) = -rowSums(Q)
 
  svd_res <- eigen(Q, symmetric = FALSE)
  svd_res$values
}
> MakeTape(f, rep(-2, 6))
Error: Not compatible with requested type: [type=S4; target=double].

traceback() gives me no useful information. 

I tried out what happens when doing par <- advector(par) and running the code. It seems like then Q has complex entries which eigen() does not like?
But I'm not sure if this is supposed to be that way or something weird is going on here.

Thanks :)

Kasper Kristensen

unread,
Jun 13, 2025, 4:32:26 AMJun 13
to TMB Users
It's because `eigen(.,symmetric=FALSE)` gives a complex factorization - perhaps you want symmetric=TRUE?

The error message is more informative (?) in the development version of RTMB:

> MakeTape(f, rep(-2, 6))
Error in .MakeTape(f, x) :
  Return value 'adcomplex' not allowed. Please use extractors Re(.), Im(.), Mod(.)
Reply all
Reply to author
Forward
0 new messages