minFit-methods | R Documentation |
minFit
in Package momentfit ~~This is a method to minimize a function using an algorithm defined by
the minAlgo
class. This is way of homogenizing the call of
minimization functions. It is used by solveGmm
to offer
the possibility of using external solvers.
## S4 method for signature 'minAlgoNlm'
minFit(object, start, fct, gr,
...)
## S4 method for signature 'minAlgoStd'
minFit(object, start, fct, gr,
...)
object |
A object of class |
start |
A vector of starting values. |
fct |
The function to minimize. |
gr |
An optional function that returns the gradient. The
arguments of |
... |
Arguments to pass the optimization algorithm and to the
functions |
A list with the following elements:
solution |
The vector of solution for the minimization problem. |
value |
The value of the function at the solution. |
message |
The convergence message from the solver. |
convergence |
The convergence code from the solver. |
signature(model = "minAlgoStd")
This class includes all solvers that have a standard set of
arguments. These arguments are the function, the gradient and the
starting values (e.g. optim
).
signature(model = "minAlgoNlm")
This method is for solvers like nlm
. The solver is quite
different from any other solvers, because the gradient is returned by
the main function as an attribute. That's why it needs a different
method to use it.
f <- function(x, a=2, b=4) (x[1]-a)^2+(x[2]-b)^2
g <- function(x, a=2, b=4) c(2*(x[1]-a), 2*(x[2]-b))
## Using optim
algo1 <- algoObj("optim")
minFit(algo1, start=c(1,1), fct=f, gr=g, method="BFGS", b=6)
## Using nlm: very different structure, but same call
algo2 <- algoObj("nlm")
minFit(algo2, start=c(1,1), fct=f, gr=g, b=6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.