2

I want to use function nlminb from stats package in my C program. I am aware of few different ways to do this: call R function within C code, using Rcpp.

But the function nlminb basically is written in Fortran and is wrapped in C code. One can find this code in R-3.2.1/src/library/stats/src files portsrc.f, port.c and port.h.

So is there a way to call functions in port.c or even in portsrc.f directly within my C code?

1 Answer 1

3

Do you have to use nlminb? Note that the optim function does most of the same things as nlminb, and its entry points are documented in the "Writing R Extensions" manual.

The interfaces (defined in header R_ext/Applic.h) are

Nelder Mead:

void nmmin(int n, double *xin, double *x, double *Fmin, optimfn fn,
int *fail, double abstol, double intol, void *ex,
double alpha, double beta, double gamma, int trace,
int *fncount, int maxit);

 BFGS:

void vmmin(int n, double *x, double *Fmin,
optimfn fn, optimgr gr, int maxit, int trace,
int *mask, double abstol, double reltol, int nREPORT,
void *ex, int *fncount, int *grcount, int *fail);

 Conjugate gradients:

void cgmin(int n, double *xin, double *x, double *Fmin,
optimfn fn, optimgr gr, int *fail, double abstol,
double intol, void *ex, int type, int trace,
int *fncount, int *grcount, int maxit);

 Limited-memory BFGS with bounds:

void lbfgsb(int n, int lmm, double *x, double *lower,
double *upper, int *nbd, double *Fmin, optimfn fn,
optimgr gr, int *fail, void *ex, double factr,
double pgtol, int *fncount, int *grcount,
int maxit, char *msg, int trace, int nREPORT);

 Simulated annealing:

void samin(int n, double *x, double *Fmin, optimfn fn, int maxit,
int tmax, double temp, int trace, void *ex);
1
  • Yes I need to use nlminb. Aug 7, 2015 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.