Statistical programming, matrix languages, and more

using nlpcg in sas iml

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

using nlpcg in sas iml

I am trying to minimize the function

f =(w1+a1x+b1y)^2 +(w2+a2x+b2y)^2 subject to

1 < x,y< 55 using the nlpcg routine.

I first define a global variable m which contains the

coefficients Wi, Ai, Bi-the data. So

m is a 2x3 matrix with first row (w1 a1 b1) and second row

(w2 a2 b2).The starting point is x=(1,1). I want the optimal x that will minimize f.I have the following sas code to define the Objective function.

Start f(x) global (m);

               sum= m [,2:3]*x + m [,1];

                res = ssq (sum);

                return res;

Finish f;

con={ 1        1,

            55      55};

x=j (2,1,1);

opt={0 3};

call nlpcg (rc, xr,"f", x, con);

print rc; print xr;

I get an error that says (execution) matrix does not conform to operation pointing to the line inside f where I do the multiplication m [,2:3]*x. I don't recall the exact words in the message but IML objects to the part where I multiply m and x. Then it says rc and xr do not have values.  I have tried doing the multiplication inside a DO LOOP ...extracting each row of m and multiplying by x. This also gives an error though the message is slightly different-it says rc=100. I thought rc is at most 10. In any case I would rather not use the DO loop.


Would appreciate any help with the problem.


Accepted Solutions
Solution
‎06-10-2014 04:15 PM
SAS Employee
Posts: 94

Re: using nlpcg in sas iml

The problem is that when IML calls your objective function during the optimization, it is supplying a row vector for x. Try transposing x in the second line of your objective module, i.e.

sum= m [,2:3]*x` + m [,1];

and see if that doesn't work as it is supposed to.

View solution in original post


All Replies
Solution
‎06-10-2014 04:15 PM
SAS Employee
Posts: 94

Re: using nlpcg in sas iml

The problem is that when IML calls your objective function during the optimization, it is supplying a row vector for x. Try transposing x in the second line of your objective module, i.e.

sum= m [,2:3]*x` + m [,1];

and see if that doesn't work as it is supposed to.

Contributor
Posts: 41

Re: using nlpcg in sas iml

I tried that but it gives me a different error now :

Execution error as noted previously (rc = 100).I have also dropped the constants with from my input since they should not make a difference to the minimization.

What does this rc=100 indicate?

Thanks for any help.

SAS Employee
Posts: 94

Re: using nlpcg in sas iml

Could you post your current program, and your run-time log?

Contributor
Posts: 41

Re: using nlpcg in sas iml

Actually you're suggestion does work. I think that in addition to the transposed vector x, the variable passed into f was called something else inside the body of f( it was not called x inside).

Thanks so much for the help!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 434 views
  • 0 likes
  • 2 in conversation