Contributor
Posts: 38

# proc optmodel options

[ Edited ]

Hi for all!

I´m migrating proc nlp to proc optmodel code. I can show  Gradient Objective Function with PROC NLP  but i didnt found it in proc OPTMODEL.

Anyone could help?

thanks

SAS Employee
Posts: 575

## Re: Is there one way to show Gradient Objective Function (proc nlp) in proc optmodel?

Dual variables (or Lagrange multipliers) are available from the .DUAL suffix.

See the Dual Values and Suffixes sections of the documentation for details.

Contributor
Posts: 38

## Re:

[ Edited ]

Yes i saw it but it´s not same than gradient function.

I reply my code with proc nlp in proc optmodel.

SAS Employee
Posts: 575

## Re: Is there one way to show Gradient Objective Function (proc nlp) in proc optmodel?

Can you please share code and data for both versions (PROC NLP and PROC OPTMODEL)?

Contributor
Posts: 38

## Re:

[ Edited ]

Yes Rob, you can see it :

Proc NLP

``````proc nlp ;
array par1[2] 5.5 4.1   ;
array par2[2] 3.1 2.1;
array z[2] z1-z2;
min y;
decvar z1-z2;
do n=1 to 2;
y= y+( par1[n]*par2[n]*z[n]**3);
end;
run;``````

And using proc optmodel now.

``````PROC OPTMODEL;
set I = 1..2;
number n=2;
number parm1 {I} =[5.545455 4.47841 ];
number parm2 {I} =[3.121211 2.04111];
var z{I};
MIN y = SUM{k IN I} (z[k] * (parm1[k] + (z[k] / parm2[k])));
SOLVE with nlp;
PRINT parm1 parm2 z.sol z.dual;
QUIT;``````
SAS Employee
Posts: 575

## Re: Is there one way to show Gradient Objective Function (proc nlp) in proc optmodel?

The optimization problem you specified in PROC OPTMODEL is different than the one that uses PROC NLP.  Also, the PROC NLP problem is unbounded, which you can see by letting z[n] approach negative infinity.

Contributor
Posts: 38

## Re

[ Edited ]

sorry it was my fault. I´m trying with multiple models

You will see with this code.

``````proc nlp ;
array par1[2] 5.545455 4.47841 ;
array par2[2] 3.121211 2.04111;
array z[2] z1-z2;
min y;
decvar z1-z2;
do n=1 to 2;
y= y+(z[n]*(par1[n]+z[n]/par2[n]));
end;
run;

PROC OPTMODEL;
set I = 1..2;
number n=2;
number parm1 {I} =[5.545455 4.47841 ];
number parm2 {I} =[3.121211 2.04111];
var z{I};
MIN y = SUM{k IN I} (z[k] * (parm1[k] + (z[k] / parm2[k])));
SOLVE with nlp;
PRINT parm1 parm2 z.sol z.dual;
QUIT;``````
SAS Employee
Posts: 575

## Re: Is there one way to show Gradient Objective Function (proc nlp) in proc optmodel?

I don't see any discrepancy between the results.  The optimal solutions and objective values agree, and the gradients are essentially 0.

SAS Output

PROC NLP: Nonlinear Minimization
Optimization Results
Parameter Estimates
N Parameter Estimate Gradient
Objective
Function
1 z1 -8.654268 4.440892E-16
2 z2 -4.570464 -4.44089E-16

 Value of Objective Function = -34.2301309

SAS Output

The OPTMODEL Procedure
Solution Summary
Solver NLP
Algorithm Interior Point
Objective Function y
Solution Status Optimal
Objective Value -34.2301309

Optimality Error 2.391962E-15
Infeasibility 0

Iterations 4
Presolve Time 0.00
Solution Time 0.00

[1] parm1 parm2 z.SOL z.DUAL
1 5.5455 3.1212 -8.6543 1.1546E-14
2 4.4784 2.0411 -4.5705 -2.3093E-14
Contributor
Posts: 38

## Re:

[ Edited ]

and how can i obtain Max Abs Gradient Element in proc optmodel?

SAS Employee
Posts: 575

## Re: Is there one way to show Gradient Objective Function (proc nlp) in proc optmodel?

``````print (max {k in I} abs(z[k].dual));
``````

More generically:

``````print (max {j in 1.._NVAR_} abs(_VAR_[j].dual));
``````
Contributor
Posts: 38

## Re: Is there one way to show Gradient Objective Function (proc nlp) in proc optmodel?

[ Edited ]

I think gradient of proc nlp and lagrangian of proc optmodel are similar but not the same.

SAS Employee
Posts: 575

## Re: Is there one way to show Gradient Objective Function (proc nlp) in proc optmodel?

Are you looking for a symbolic formula for each partial derivative?  Or do you just want to compute the gradient at a specific point?

Contributor
Posts: 38

## Re: Is there one way to show Gradient Objective Function (proc nlp) in proc optmodel?

i was looking for the second option (using the same start points that proc nlp) but if you can specify first option too it will be really help!

thanks

SAS Employee
Posts: 575

## Re: Is there one way to show Gradient Objective Function (proc nlp) in proc optmodel?

[ Edited ]

This blog post discusses symbolic derivatives with SAS.

And here's an undocumented way to compute the gradient at a given point (in this case, the initial solution from PROC NLP):

``````PROC OPTMODEL;
set I = 1..2;
number parm1 {I} =[5.545455 4.47841];
number parm2 {I} =[3.121211 2.04111];
var z{I};
z[1] = 0.478582;
z[2] = 0.451506;
MIN y = SUM{k IN I} (z[k] * (parm1[k] + (z[k] / parm2[k])));
SOLVE with none;
PRINT parm1 parm2 z.sol z.dual;
QUIT;``````

SAS Output

 The SAS System

The OPTMODEL Procedure
Solution Summary
Solver None
Objective Function y
Solution Status Optimal
Objective Value 4.8492418235

Iterations 0
Presolve Time 0.00
Solution Time 0.00

[1] parm1 parm2 z.SOL z.DUAL
1 5.5455 3.1212 0.47858 5.8521
2 4.4784 2.0411 0.45151 4.9208

You can see that the values match the PROC NLP initial solution, shown here:

SAS Output

 The SAS System

PROC NLP: Nonlinear Minimization
Optimization Start
Parameter Estimates
N Parameter Estimate Gradient
Objective
Function
1 z1 0.478582 5.852119
2 z2 0.451506 4.920822

 Value of Objective Function = 4.8492430842

Contributor
Posts: 38

## Re:

[ Edited ]

Hi Rob!

thanks for your quick answer. I´m triying to reproduce your results but i dont get same solution:

1º Using proc NLP

`````` proc nlp ;
array par1[2] 5.545455 4.47841 ;
array par2[2] 3.121211 2.04111;
array z[2] z1-z2;
min y;
decvar z1-z2;
do n=1 to 2;
y= y+(z[n]*(par1[n]+(z[n]/par2[n])));
end;
run;``````

Then i use proc optmodel with -8.654268 and -4.570464

``````PROC OPTMODEL;
set I = 1..2;
number parm1 {I} =[5.545455 4.47841];
number parm2 {I} =[3.121211 2.04111];
var z{I};
z[1] = -8.654268	;
z[2] = -4.570464;
MIN y = SUM{k IN I} (z[k] * (parm1[k] + (z[k] / parm2[k])));
SOLVE with none;
PRINT parm1 parm2 z.sol z.dual;
QUIT;``````

As you can see it not the same

what do i do wrong?

Discussion stats
• 15 replies
• 452 views
• 0 likes
• 2 in conversation