BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zocoj
Calcite | Level 5

Dears,

 

I am trying to apply the minimization algorithm mentioned in the attached pdf with SAS 9.2. 

 

I am using the following code with the data attached (values already centered).

 

proc iml;
use in_data;
read all into in_data;
in_data=in_data;

start F(x) global(in_data);
x = {0, 0, 0};
f = sum(exp(in_data*x));
return(f);
finish F;

start G(x) global(in_data);
x = {0, 0, 0};
g = (exp(in_data*x)`)*in_data;
return(g);
finish G;

x = {0, 0, 0};
optn = {0 2};
call nlpnra(rc, xres, "F", x, optn) grd="G";

print xres;
quit;

 

xres gives me the following result: 0.0301847 -0.008427 0.0540752

 

When I use R, I get the following results: 0.4941690 -0.2042731 1.5939447. I would like to know how could I fix the code so that the results are more similar to those provided by R.
 

Any help would be highly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
IanWakeling
Barite | Level 11

I think the following will fix the problem.  Always use a row vector for x0 and don't try to modify x within the functions F and G.

 

proc iml;
use test;
read all into in_data;

start F(x) global(in_data);
f = sum(exp(in_data*x`));
return(f);
finish F;

start G(x) global(in_data);
g = (exp(in_data*x`)`)*in_data;
return(g);
finish G;

x0 = {0 0 0};
optn = {0 2};
call nlpnra(rc, xres, "F", x0, optn) grd="G";

print xres;
quit;

View solution in original post

2 REPLIES 2
IanWakeling
Barite | Level 11

I think the following will fix the problem.  Always use a row vector for x0 and don't try to modify x within the functions F and G.

 

proc iml;
use test;
read all into in_data;

start F(x) global(in_data);
f = sum(exp(in_data*x`));
return(f);
finish F;

start G(x) global(in_data);
g = (exp(in_data*x`)`)*in_data;
return(g);
finish G;

x0 = {0 0 0};
optn = {0 2};
call nlpnra(rc, xres, "F", x0, optn) grd="G";

print xres;
quit;
zocoj
Calcite | Level 5
Thanks a lot! it works :).

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1768 views
  • 2 likes
  • 2 in conversation