I am new to C.
I am trying to use optim function from C. According to “Writing R Extension” Section 5.8, the Nelder Mead method requires 16 arguments:
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);
In my understanding, unlike R which accepts default values in arguments of functions, C requires users of the function to provide all the arguments.
Although I read optim hep page, I still have troubles understanding the meaning of some of these arguments i.e.:
- fail
- intol
- ex
- fncount
I highly appreciate if anyone can direct me where the descriptions of all the arguments are.
p.s.
The followings are the arguments that I figure out what they are:
- n: the number of parameters,
- xin: the initial value of the parameter
- x: storage for the final parameters on exit, with fi
- Fmin: the final value of the objective function
- fn: the objective function
- abstol: absolute tolerance
- maxit: the maximum number of iterations
- trace: Non-negative integer. If positive, tracing information on the progress of the optimization is produced.
The followings are some arguments specific for the Nelder Mead method:
-
alpha: R optim function uses = 1
-
beta: R optim function uses = 0.5
-
gamma: R optim function uses = 2
(I found these default values by reading the optim function codes)
fail – receives true if the function failed
intol – user-initialized conversion tolerance
ex – data to pass to the optimization function (fn)
alpha – reflection factor
beta – contraction and reduction factor
gamma – extension factor
fncount – receives the number of times the optimization function was called in the iteration loop
You can see how these parameters are used here:
http://fossies.org/dox/R-2.15.1/optim_8c_source.html#l00674
For instance, intol is used like so:
There are some more details about the Nelder-Mead algorithm here, with Pascal code:
http://books.google.com/books?id=M9hTn3UAheQC&pg=PA173
(Compact Numerical Methods for Computers: Linear Algebra and Function Minimisation by John C. Nash)