0

Please note that I am not very familiar with R and I am trying to solve the following optimization (minimization). Any inputs would be greatly appreciated. The issue seems to be with the initial values; am unsure how to pick valid initial values. Though it seems to satisfy the criteria given in the documentation.

  thetaImp = 5*(10^-5);
  eps1 = -0.23;
  eps2 = 0.31;
  minFunc <- function(x) {
    x1 <- x[1];
    x2 <- x[2];
    -1*(max(thetaImp*x1+eps1,0)*(x1) + max(thetaImp*x2+eps2,0)*(x1+x2))
  }
  ui = rbind(c(1,1), c(1,0), c(0,1));
  ci = c(10000,0,0);
  initValues = c(5000,5000);
  constrOptim(initValues, minFunc, NULL, ui, ci);
  ui %*% initValues - ci

Please note that this is also posted on the statistics website with the full description of the problem. The above is only a sample.

enter image description here

https://stats.stackexchange.com/questions/355166/constrained-minimization-closed-form-if-available-or-r-suggestions

1 Answer 1

1

For optimization with an equality constraint, there is the Rsolnp package.

library(Rsolnp)

thetaImp = 5*(10^-5);
eps1 = -0.23;
eps2 = 0.31;
W = 10000

f <- function(x) { # function to minimize
  x1 <- x[1];
  x2 <- x[2];
  max(thetaImp*x1+eps1,0)*x1 + max(thetaImp*x2+eps2,0)*W
}

eqfun <- function(x){ # function defining the equality
  x[1] + x[2]
}

solnp(c(5000, 5000), # starting values 
      f, 
      eqfun = eqfun, 
      eqB = W, # the equality constraint
      LB=c(0,0) # lower bounds
) 

Output:

Iter: 1 fn: 5435.5000    Pars:  7300.06425 2699.93575
Iter: 2 fn: 5435.5000    Pars:  7300.06425 2699.93575
solnp--> Completed in 2 iterations
$pars
[1] 7300.064 2699.936
......

In this case K=2, we can equivalently solve the problem with an unidimensional optimization, to check:

g <- function(t) { # function to minimize
  x1 <- t
  x2 <- W-t;
  max(thetaImp*x1+eps1,0)*x1 + max(thetaImp*x2+eps2,0)*W
}
optim(5000, g, method="L-BFGS-B", lower=0, upper=W) 


> optim(5000, g, lower=0, upper=W)
$par
[1] 7300
......

We get almost the same result.

Sign up to request clarification or add additional context in comments.

8 Comments

thanks for this detailed answer (and your other suggestions on the stats website). I will try it out. Also, in case later I need to change the constraints to inequalities, how would I make it work in the above case using constrOptim? Also, I suppose closed form solutions are to be ruled out?
@user249613 You mean you need an inequality constraint on $\sum S_i$ ?
Thanks Stephane,appreciate your time to provide these suggestions. The constraints would be on the sum (currently in your eqfun <- function(x)) and also on the individual $$S_{i}$$ as you mention.
@user249613 There's a uneqfun argument in the solnp function which is exactly for dealing with this kind of constraints.
@stehaneLaurent, Thanks for your suggestions thus far. solnp seems to be working fine for the most part. A couple of issues. Issue One: Sometimes it seems to go into an infinite loop and never returns. Anything we can do in such situations.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.