Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/optimbase.gridsearch.R

Evaluate a constrained or unconstrained cost function on a grid of points around a given initial point estimate.

1 2 | ```
optimbase.gridsearch(fun = NULL, x0 = NULL, xmin = NULL,
xmax = NULL, npts = 3, alpha = 10)
``` |

`fun` |
A constrained or unconstrained cost function defined as described
in the vignette ( |

`x0` |
The initial point estimate, provided as a numeric vector. |

`xmin` |
Optional: a vector of lower bounds. |

`xmax` |
Optional: a vector of upper bounds. |

`npts` |
A integer scalar greater than 2, indicating the number of evaluation points will be used on each dimension to build the search grid. |

`alpha` |
A vector of numbers greater than 1, which give the factor(s) used
to calculate the evaluation range of each dimension of the search grid (see
Details). If |

`optimbase.gridsearch`

evaluates the cost function at each point
of a grid of `npts^length(x0)`

points. If lower (`xmin`

) and upper
(`xmax`

) bounds are provided, the range of evaluation points is limited
by those bounds and `alpha`

is not used. Otherwise, the range of
evaluation points is defined as `[x0/alpha,x0*alpha]`

.

`optimbase.gridsearch`

also determines if the cost function is
feasible at each evaluation point by calling `optimbase.isfeasible`

.

Return a data.frame with the coordinates of the evaluation point, the value of the cost function and its feasibility. The data.frame is ordered by feasibility and increasing value of the cost function.

Sebastien Bihorel ([email protected])

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ```
# Problem: find x and y that maximize 3.6*x - 0.4*x^2 + 1.6*y - 0.2*y^2 and
# satisfy the constrains:
# 2*x - y <= 10
# x >= 0
# y >= 0
#
gridfun <- function(x=NULL,index=NULL,fmsfundata=NULL,...){
f <- c()
c <- c()
if (index == 2 | index == 6)
f <- -(3.6*x[1] - 0.4*x[1]*x[1] + 1.6*x[2] - 0.2*x[2]*x[2])
if (index == 5 | index == 6)
c <- c(10 - 2*x[1] - x[2],
x[1],
x[2])
varargout <- list(f = f, g = c(), c = c, gc = c(), index = index)
return(varargout)
}
x0 <- c(0.35,0.3)
npts <- 6
alpha <- 10
res <- optimbase.gridsearch(fun=gridfun,x0=x0,xmin=NULL,xmax=NULL,
npts=npts,alpha=alpha)
# 3.5 and 3 is the actual solution of the optimization problem
print(res)
``` |

optimbase documentation built on May 29, 2017, 10:54 a.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.