Antonio Coppola edited C++ Functions.tex  over 9 years ago

Commit id: 0322a5135e3d5862a82c23179cfe3c6ba4b2a10f

deletions | additions      

       

Then we compile the functions and their pointer-assigners, taking care to map the functions' signatures correctly:  \begin{lstlisting}  likelihood.body <- '  typedef Rcpp::NumericVector (*funcPtr)(SEXP, SEXP);  return(XPtr(new funcPtr(&lhood))); 

gradient.CPP <- cxxfunction(signature(), body=gradient.body,   inc=gradient.inc, plugin="RcppArmadillo")  \end{lstlisting}  We then instantiate a new R environment with the required objects, and run the optimization routine:  \begin{lstlisting}  data(Leukemia)  X <- Leukemia$x  y <- Leukemia$y  X1 <- cbind(1, X)  init <- rep(0, ncol(X1))  env <- new.env()  env[["X"]] <- X1  env[["y"]] <- y  env[["prec"]] <- 1  output <- lbfgs(likelihood.CPP(), gradient.CPP(), init, environment=env)  \end{lstlisting}