this my code and after I run it I got this error message:
ERROR: Overflow error in NLPQN.
operation : NLPQN at line 5279 column 1
operands : *LIT1222, k, optn, , , , , , *LIT1223
*LIT1222 1 row 1 col (character, size 3)
fun
k 1 row 2 cols (numeric)
0 0
optn 1 row 11 cols (numeric)
*LIT1223 1 row 1 col (character, size 3)
con
statement : CALL at line 5279 column 1
*****************************************
where l and g are vectors
the code is :
proc iml;
start fun(K) global
(l,e,g,p);
sumf=0;
do i = 1to p;
sumf = sumf + (((e*l)+ ( k**2
* g**2 )) /(l+ k)**2);
end;
return (sumf);
finish fun;
start con(k) global
(l,lg,e1,n,ny,p,g2,z,g);
c=j(5,1,0);
sumc1=0;
do i = 1to p;
sumc1 = sumc1 + (
(g2*l**2)
/(l+k)**2 );
end;
sumc3=0;
do i = 1to p;
sumc3 = sumc3 + (((e1*l)+ ( k**2
* g**2 )) /(l+ k)**2);
end;
sumc41=0;
do i = 1to n;
sumc41 = sumc41 +(
(ny-((z[i,1]*g[1]*l[1])/(la[1]+k[1]))-((z[i,2]*g[2]*l[2])/(l[2]+k[2]))
)**2 );
end;
sumc42=0;
do i=1to n;
sumc42=sumc42+( 1-((z[i,1]**2)/(l[1]+k[1]))-((z[i,2]**2)/(l[2]+k[2]))
);
end;
sumc4=(n*sumc41)/(sumc42)**2;
c[1]= lenghtg-sumc1;
c[2]=k[1];
c[3]=k[2];
c[4]=3-sumc3;
c[5]=4-sumc4;
return (c);
finish con;
k=j(1,2,0);
optn=j(1,11,.);
optn[11]=0;
optn[10]=5;
call nlpqn (rc, kres, "fun", k, optn) nlc="con";
Since you haven't provided values for the global variables, we can't run your program, but a likely cause of your problem is that you are dividing by zero. Notice that your functions have expressions like
sumf = sumf + ((stuff) /(l+ k)**2);
which is undefined when l=k=0.
Notice also that you have set k={0 0} as an initial value.
An easy way to debug these problems is to evaluate the objective functions (FUN) and the constraint function (CON) at several points in the domain prior to trying to use them in an optimization. For an example of evaluating the objective function and for getting a good initial guess, see the article "How to find an initial guess for an optimization"
I tried another initial values and this error message disappeared but I repeate this code 50000 times in simulation study. and now the runs do not stop even along the whole day. So can I use call nlpnms instead of call nlpqn for this optimization model?
Would you like to share what you are trying to accomplish? What is the objective function? Are you sure that there is an optimum value?
As to the speed, you would solve this problem much faster if you got rid of all those DO loops and vectorized the problem. For example, it looks like the objective function is just
return( sum((e*l+ (k##2 # g##2)) /(l+ k)##2) );
If you aren't familiar with vectorization, look at some of these examples: http://blogs.sas.com/content/iml/tag/vectorization
I tried this code :
return( sum((e*l+ (k##2 # g##2)) /(l+ k)##2) );
but I got this error message
ERROR: (execution) Matrices do not conform to the operation.
operation : # at line 4183 column 39
operands : _TEM1002, _TEM1003
_TEM1002 1 row 2 cols (numeric)
0 25
_TEM1003 2 rows 1 col (numeric)
0.1154035
0.3658517
statement : RETURN at line 4183 column 1
traceback : module FUN at line 4183 column 1
ERROR: (execution) Matrices do not conform to the operation.
operation : NLPQN at line 4235 column 1
operands : *LIT1218, k, optn, , , , , , *LIT1219
*LIT1218 1 row 1 col (character, size 3)
fun
k 1 row 2 cols (numeric)
0 5
optn 1 row 11 cols (numeric)
*LIT1219 1 row 1 col (character, size 3)
con
statement : CALL at line 4235 column 1
The error says that k is 1x2 whereas g is 2x1, so you'll need to transpose one of them.
After I remove all the do loops and specify the initial values, I got the following error message using NLPQN.
How can I increase the number of iterations or number of function calls inside the optimization code?
ERROR: QUANEW Optimization cannot be completed.
ERROR: QUANEW needs more than 200 iterations or 500 function calls.
WARNING: The point x is feasible only at the LCEPSILON= 0.1 range.
Sometimes in constrained optimization there is no solution inside the feasible region. A canonical example is when you try to optimize the function f(x)=1/x subject to the contraint that x>0. For your problem, I suspect that the variable K is trying to get close to L. You can watch the progress by printing the iteration history.
The documentation describes how to print the iteration history and how to increase the iterations:
Control printing: SAS/IML(R) 13.1 User's Guide
Control stopping criterion: SAS/IML(R) 13.1 User's Guide
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.