G | R Documentation |
Extract the gradient from its argument (typically a ROI
object of class "objective"
).
G(x, ...)
x |
an object used to select the method. |
... |
further arguments passed down to the
|
By default ROI uses the "grad"
function from the
numDeriv package to derive the gradient information.
An alternative function can be provided via "ROI_options"
.
For example ROI_options("gradient", myGrad)
would tell ROI to use the function "myGrad"
for the
gradient calculation. The only requirement to the function
"myGrad"
is that it has the argument "func"
which takes a function with a scalar real result.
a "function"
.
## Not run:
f <- function(x) {
return( 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 )
}
x <- OP( objective = F_objective(f, n=2L),
bounds = V_bound(li=1:2, ui=1:2, lb=c(-3, -3), ub=c(3, 3)) )
G(objective(x))(c(0, 0)) ## gradient numerically approximated by numDeriv
f.gradient <- function(x) {
return( c( -400 * x[1] * (x[2] - x[1] * x[1]) - 2 * (1 - x[1]),
200 * (x[2] - x[1] * x[1])) )
}
x <- OP( objective = F_objective(f, n=2L, G=f.gradient),
bounds = V_bound(li=1:2, ui=1:2, lb=c(-3, -3), ub=c(3, 3)) )
G(objective(x))(c(0, 0)) ## gradient calculated by f.gradient
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.