- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dual variables (or Lagrange multipliers) are available from the .DUAL suffix.
See the Dual Values and Suffixes sections of the documentation for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes i saw it but it´s not same than gradient function.
I reply my code with proc nlp in proc optmodel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you please share code and data for both versions (PROC NLP and PROC OPTMODEL)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I don't see any discrepancy between the results. The optimal solutions and objective values agree, and the gradients are essentially 0.
SAS Output
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
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 |
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
and how can i obtain Max Abs Gradient Element in proc optmodel?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For your problem:
print (max {k in I} abs(z[k].dual));
More generically:
print (max {j in 1.._NVAR_} abs(_VAR_[j].dual));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think gradient of proc nlp and lagrangian of proc optmodel are similar but not the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Are you looking for a symbolic formula for each partial derivative? Or do you just want to compute the gradient at a specific point?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 |
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 |
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 |
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?