我想在我的C程序中使用nlminb
包中的函数stats
。我知道几种不同的方法:使用Rcpp
在C代码中调用R函数。
但是函数nlminb
基本上是用Fortran编写的,并且用C代码包装。可以在R-3.2.1/src/library/stats/src
个文件portsrc.f
,port.c
和port.h
中找到此代码。
那么有没有办法直接在我的C代码中调用port.c
甚至portsrc.f
中的函数?
答案 0 :(得分:3)
你 使用nlminb
吗?请注意,optim
函数与nlminb
执行大部分相同的操作,其入口点记录在"写入R扩展"手册。
接口(在标题R_ext / Applic.h中定义)是
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);
共轭渐变:
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);