2017-02-15 2 views
0

'nloptr'을 사용하여 r에서 간단한 함수를 최적화하고 있으며 인수를 목적 함수에 전달하는 데 어려움을 겪고 있습니다. r에있는 nloptr에 인수 전달

res <- nloptr(x0=Wghts,eval_f = pf.vol,eval_g_ineq=pf.return,opts=list(algorithm="NLOPT_GN_ISRES"), x=Wghts,C=Correl)

require("nloptr") 

Correl <- matrix(c(1,-.3,-.3,1), nrow=2, ncol=2) 
Wghts <- c(.01,.99) 
floor <- .035 
expret <- c(.05,.02) 
pf.return <- function(r, x, threshold=0){ 

return(r * x - threshold) 
} 

pf.vol <- function(x, C){ 

return(sqrt(x %*% C %*% x)) 
} 
은 (내가 여기 매개 변수를보고 싶어 알고 있지만 내가 이해할 수없는 행동을 강조하기 위해 노력하고있어) 가 실행이은을 제공합니다 : 여기에 내가 사용하고 코드입니다 다음과 같은 오류 :

Error in .checkfunargs(eval_f, arglist, "eval_f") : x' passed to (...) in 'nloptr' but this is not required in the eval_f function.

그냥 제가 X 인수없이 실행 시도 할 수 있습니다 어떻게되는지 :

오류를 범 0

res <- nloptr(x0=Wghts,eval_f = pf.vol,eval_g_ineq=pf.return,opts=list(algorithm="NLOPT_GN_ISRES"), C=Correl)

:

Error in .checkfunargs(eval_g_ineq, arglist, "eval_g_ineq") : eval_g_ineq requires argument 'x' but this has not been passed to the 'nloptr' function.

그래서 x 그것이 불필요하다고 에러 발생을 포함하고 그것이 생략되었다는 (적어도 이해할)에서 에러가 발생 생략한다. 후손에 대한 확인

답변

1

는 : 그들은 동일한 순서로, 인수의 동일한 세트를 가지고 있도록

나는 기능을 다시 썼다.

x=Wghts 비트도 생략 했으므로 검색 할 매개 변수입니다.