absolute value

609 views
Skip to first unread message

fn

unread,
Feb 20, 2021, 12:13:46 PM2/20/21
to am...@googlegroups.com
Hi, I'm new to AMPL. Does anyone know how can I write the to let all
regression coefficients should have an absolute value of at most 3? and how
to restrict the sum of the absolute values of the regression coefficients of
two features to be less than 3? Can someone give me some hints or help
Thank you so much!



--
Sent from: http://ampl.996311.n3.nabble.com/

AMPL Google Group

unread,
Feb 22, 2021, 11:16:34 AM2/22/21
to AMPL Modeling Language
For "abs(X) <= 3" where X is a variable, you can write "-3 <= X <= 3". But for "abs(X) + abs(Y) <= 3" a more extensive reformulation is necessary. Since this constraint consists of a convex piecewise-linear function to the left of a <= constraint, it can be converted to a linear formulation using only continuous variables. There are several possibilities:

1. Use AMPL's piecewise-linear notation to express the absolute value function explicitly as a piecewise-linear function with slope -1 to the left of 0 and +1 to the right of 0:

var X; var Y;
subj to absConstr: <<0;-1,+1>> X + <<0;-1,+1>> Y <= 3;


AMPL will then automatically convert to a linear formulation before sending the problem to the solver.

2. Represent each variable as the difference of two nonnegative variables, and the absolute value as the sum of those variables:

var Xpos >= 0; var Xneg >= 0; var X = Xpos - Xneg;
var Ypos >= 0; var Yneg >= 0; var Y = Ypos - Yneg;

subj to absConstr: (Xpos + Xneg) + (Ypos + Yneg) <= 3;


(AMPL uses this approach when it converts to a linear formulation.)

3. For abs(X) substitute a new variable that is >= X and >= -X, and similarly for abs(Y):

var X; var Y;
var Xabs >= 0; var Yabs >= 0;

subj to absConstr: Xabs + Yabs <= 3;
subj to XabsGE: Xabs >= -X; subj to XabsLE: Xabs >= X;
subj to YabsGE: Yabs >= -Y; subj to YabsLE: Yabs >= Y;



--
Robert Fourer
am...@googlegroups.com
{#HS:1431735006-101180#}
Reply all
Reply to author
Forward
0 new messages