如何使用可传参数调试R函数

时间:2015-02-28 01:40:23

标签: r debugging optimization parameter-passing

我尝试在R 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;
  

源( “test.R”)

我得到了

*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]>

所以,我的问题是我找到了

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

我怎么知道确切的“...”已经传递给“optimx.check” 谢谢!

0 个答案:

没有答案