Benjamin B.
2010-Dec-06 15:43 UTC
[R] How to formulate constraint like abs(x) = y in constrOptim (or other)
Hello list reader, I am trying to form some constraints for an optimization I am working on. I think I have understand the use of the constraints in matrix form. I use them like: constr_mat<- -diag(2) constr_vec<- rep(-0.05,2) constr_mat<- rbind(constr_mat, diag(2)) constr_vec<- c(constr_vec, rep(-1, 2)) To get parameters in the interval [-1, 0.05]. (And this works so far) Now I would like to formulate a constraint like Sum(Abs(x_i))<=limit But I have no idea how I could get such a condition by using the matrix constraint formulation. I have already searched the help, web and all searchable R resources I could find, but got no helping result. Is constrOptim the right function to use? Maybe you can give me a hint or can point me to a good description of constraint handling. Greetings and thanks in advance, Benjamin Benjamin B. Hamburg, Germany
Hans W Borchers
2010-Dec-06 18:07 UTC
[R] How to formulate constraint like abs(x) = y in constrOptim (or other)
Benjamin B. <benj.bad.ac <at> googlemail.com> writes:> Hello list reader, > > I am trying to form some constraints for an optimization I am working on. > I think I have understand the use of the constraints in matrix form. I use > them like: > > [...] > > Now I would like to formulate a constraint like > > Sum(Abs(x_i))<=limit > > But I have no idea how I could get such a condition by using the matrix > constraint formulation. > > I have already searched the help, web and all searchable R resources I could > find, but got no helping result. > > Is constrOptim the right function to use? > > Maybe you can give me a hint or can point me to a good description of > constraint handling. > > Greetings and thanks in advance, > > Benjamin > > Benjamin B. > Hamburg, GermanyWith 'constrOptim' you can formulate linear constraints only, and in most cases abs() is not linear. You might try one of the nonlinear optimization packages. Another possibility is to reformulate the absolute value with two binary values, if your optimization function itself is linear; you didn't tell us the whole story. Hans Werner