Hi Hans,

I really appreciate your help and the detailed reply. Many thanks and have a
nice Thanks giving!

Best,
Hao

On Tue, Nov 23, 2010 at 11:46 AM, Hans W Borchers [via R] <
ml-node+3055782-1866096000-202...@n4.nabble.com<ml-node%2b3055782-1866096000-202...@n4.nabble.com>
> wrote:

> dhacademic <at> gmail.com <dhacademic <at> gmail.com> writes:
>
> > Hi,
> >
> > I have struggled on this "bound optimization with equality constraint" by
>
> > using optim function for two days, but still fail to prepare a good
> input.
> > Can anyone help to prepare the input for my specific case? Many thanks.
> >
> > Best,
> > Hao
>
> You did not disclose the the function f, is it linear or nonlinear, does it
>
> have (many) local minima, do you know its gradient?, etc.
>
> With some bloody tricks it is possible to emulate equality and inequality
> constraints with 'optim', too. But in general, I would suggest to apply
> 'constrOptim.nl' in the alabama package (or 'solnp' in Rsolnp). These are
> newer implementations and will handle equality constraints nicely.
>
> Assuming your original function f12 is a function of 12 variables, e.g.
>
>     f12 <- function(x) sum((1:12)*(x - 1:12)^2)
>
> define a new function f eliminating x3, x4, and x12 through
>
>     f <- function(x) {
>         xx1r  <- 1.5 - x[1] - sum(x)
>         x12  <- c(x[1], x[2], x[1], x[1], x[3:9], xx1r)
>         f12(x12)
>     }
>
> I would suggest 'solnp' in package "Rsolnp", as the bound constraints can
> be
> formulated somewhat easier; the start value has to be feasible(!):
>
>     lower <- c(-1, 0, -1, 0, 0, 0, 0, 0, 0)
>     upper <- c( 0, 1,  0, 1, 1, 1, 1, 1, 1)
>
>     fun <- function(x) 1.5 - 2*x[1] - x[2] - sum(x[3:9])
>     start <- c(-0.2, 0.2, -0.2, rep(0.2, 6))
>
>     S <- solnp(start, f, LB=lower, UB=upper, ineqfun=fun, ineqLB=0,
> ineqUB=1)
>
> This will return a (local?) minimum (-1, 0, -1, 0, 0, 0.5, 1, 1, 1) as:
>
>     S$pars
>   # [1] -1.000000e+00  1.209474e-08 -9.999999e-01  4.801754e-08
>  1.930926e-07
>   # [6]  4.999999e-01  9.999998e-01  1.000000e+00  1.000000e+00
>
> Hans Werner
>
> --------
> P. S.:  Sorry, Ravi, but I could not resist the temptation to at least
>         **indicate** one complete solution.
> --------
>
> ______________________________________________
> [hidden email] <http://user/SendEmail.jtp?type=node&node=3055782&i=0>mailing 
> list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
> ------------------------------
>  View message @
> http://r.789695.n4.nabble.com/question-about-constraint-minimization-tp3050880p3055782.html
>
> To unsubscribe from question about constraint minimization, click 
> here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3050880&code=ZGhhY2FkZW1pY0BnbWFpbC5jb218MzA1MDg4MHwtNjM2Nzc0NA==>.
>
>

-- 
View this message in context: 
http://r.789695.n4.nabble.com/question-about-constraint-minimization-tp3050880p3057370.html
Sent from the R help mailing list archive at Nabble.com.

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to