是否有可能调用R源代码函数写在C直接在我的C代码



我想在我的C程序中使用stats包中的nlminb函数。我知道有几种不同的方法可以做到这一点:在C代码中调用R函数,使用Rcpp

但是函数nlminb基本上是用Fortran写的,用C代码封装。你可以在R-3.2.1/src/library/stats/src文件portsrc.f, port.cport.h中找到这些代码。

那么有一种方法可以在port.c甚至portsrc.f中直接在我的C代码中调用函数吗?

使用nlminb吗?请注意,optim函数所做的大部分事情与nlminb相同,其入口点在"编写R扩展"中有文档说明。手册。

接口(定义在报头R_ext/application .h)是

Nelder米德:

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);

 bfg:

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);

共轭梯度:

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);

具有边界的有限内存BFGS:

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);

模拟退火:

void samin(int n, double *x, double *Fmin, optimfn fn, int maxit,
int tmax, double temp, int trace, void *ex);

最新更新