vendredi 27 février 2015

How to debug R function with passable parameters


Vote count:

0




I tried to debug a function in R version 3.0.1 (2013-05-16)



library(optimx)
options(error=recover)
Ez <- matrix(runif(16,0,1),4,4)
L <- 4
Y <- matrix(0,L);
## Function
fLogit <- function(BetaPrior,YandEz){
XL <- length(BetaPrior);
BetaPrior <- matrix(as.numeric(BetaPrior), ncol=1, nrow=XL);
Y=YandEz[[1]];
Ez=YandEz[[2]];
-sum(Ez*(Y %*% BetaPrior) - log(1+exp(Y %*% BetaPrior))) ;
}
## Gradient
gLogit <- function(BetaPrior,YandEz){
XL <- length(BetaPrior);
BetaPrior <- matrix(as.numeric(BetaPrior), ncol=1, nrow=XL);
Y=YandEz[[1]];
Ez=YandEz[[2]];
myPi <- plogis(Y %*% BetaPrior)
-t(Ez-myPi) %*% Y
}
BetaPrior <- as.list(matrix(1,L,1));
BetaFit <- optimx(BetaPrior,fLogit,gLogit,YandEz=list(Y,Ez),method="BFGS");
BetaPrior<-BetaFit$par;



source("test.R")



I got



*Error in optimx.check(par, optcfg$ufn, optcfg$ugr, optcfg$uhess, lower, :
Cannot evaluate function at initial parameters

Enter a frame number, or 0 to exit

1: source("test.R")
2: withVisible(eval(ei, envir))
3: eval(ei, envir)
4: eval(expr, envir, enclos)
5: test.R#29: optimx(BetaPrior, fLogit, gLogit, YandEz = list(Y, Ez), method =
6: optimx.check(par, optcfg$ufn, optcfg$ugr, optcfg$uhess, lower, upper, hessi

Selection:6
Called from: eval(substitute(browser(skipCalls = skip), list(skip = 7 - which)),
envir = sys.frame(which))
Browse[1]> ls()
[1] "ctrl" "firsttry" "have.bounds" "hessian" "infeasible"
[6] "lower" "npar" "optchk" "par" "ufn"
[11] "ugr" "uhess" "upper" "usenumDeriv"
Browse[1]>


So, My question is I found



optimx.check <- function(par, ufn, ugr, uhess, lower=-Inf, upper=Inf,.
hessian=FALSE, ctrl, have.bounds=FALSE, usenumDeriv=FALSE, ...)


How did I know what exact "..." have been passed to "optimx.check" Thanks!


I don't have more details. Stackoverlflow required me for more details, so I have to put meaningless stuff here.........I don't have more details. Stackoverlflow required me for more details, so I have to put meaningless stuff here.........I don't have more details. Stackoverlflow required me for more details, so I have to put meaningless stuff here.........I don't have more details. Stackoverlflow required me for more details, so I have to put meaningless stuff here.........I don't have more details. Stackoverlflow required me for more details, so I have to put meaningless stuff here.........



asked 1 min ago







How to debug R function with passable parameters

Aucun commentaire:

Enregistrer un commentaire