<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Nonlinear Optimization: call nlphqn in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858697#M5960</link>
    <description>&lt;P&gt;Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Meanwhile I recommend to start exploring visually what the function looks like.&amp;nbsp;Mathematically I cannot help you. and I lack knowledge of a feasible data range for x, y, z. Here comes some code to get you started.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
x=do(0.1,10, 0.1);
y=do(0.1,10, 0.1);

xy=expandgrid(x,y);

start fxy(xx, yy);
gxy=1/xx+1/yy;
z=rand('uniform', 1, 10);
/* z=10; */
hxyz=xx/z+yy;
f=z||gxy/hxyz;
return(f);
finish fxy;

res=j(nrow(xy), 4, .);

do i=1 to nrow(xy);
res[i, 1:2]=xy[i,]; 
res[i, 3:4]=fxy(xy[i,1], xy[i,2]);
end;

create outs from res [colname={'x' 'y' 'z' 'res'}];
append from res;
close outs;
quit;


proc template;
  define statgraph surfaceplotparm;
    begingraph;
      entrytitle "Surface Plot of task";
      layout overlay3d / cube=false;
        surfaceplotparm x=x y=y z=res /
          reversecolormodel=true
          colorresponse=z
          colormodel=(red yellow green);
      endlayout;
    endgraph;
  end;
run;

proc sgrender data= outs template=surfaceplotparm;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 Feb 2023 11:07:26 GMT</pubDate>
    <dc:creator>acordes</dc:creator>
    <dc:date>2023-02-14T11:07:26Z</dc:date>
    <item>
      <title>Nonlinear Optimization: call nlphqn</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858646#M5959</link>
      <description>&lt;P&gt;Aims to minimize the function f(x, y), where the range of x and y are provided. f(x, y) is calculated by the ratio of functions g(x, y) and h(x, y, z), where h(x, y, z) is minimized for each (x, y) and the range z is provided.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;f(x, y)=g(x, y)/min (h(x, y, z));&lt;/P&gt;&lt;P&gt;g(x, y)=1/x+1/y;&lt;/P&gt;&lt;P&gt;h(x, y, z)=x/z+y;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below code is definitely not working but I like to show what the picture is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;iml&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;start funch(x) global(var1 var2);&lt;/P&gt;&lt;P&gt;&amp;nbsp; f = var1/x[&lt;STRONG&gt;1&lt;/STRONG&gt;]+var2;&lt;/P&gt;&lt;P&gt;*where var1 and var2 are x[1] and x[2] in funcf&lt;/P&gt;&lt;P&gt;return (f);&lt;/P&gt;&lt;P&gt;finish funch;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;start funcf(x);&lt;/P&gt;&lt;P&gt;&amp;nbsp;con = {&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;10&lt;/STRONG&gt;};&lt;/P&gt;&lt;P&gt;&amp;nbsp; x0 = {&lt;STRONG&gt;1&lt;/STRONG&gt;};&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; optn = {&lt;STRONG&gt;1&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;1&lt;/STRONG&gt;};&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call nlphqn(rc, xres, "funch", x0, optn) blc=con;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; h=x[&lt;STRONG&gt;1&lt;/STRONG&gt;]/xrec+x[&lt;STRONG&gt;2&lt;/STRONG&gt;];&lt;/P&gt;&lt;P&gt;&amp;nbsp; g=&lt;STRONG&gt;1&lt;/STRONG&gt;/x[&lt;STRONG&gt;1&lt;/STRONG&gt;]+&lt;STRONG&gt;1&lt;/STRONG&gt;/x[&lt;STRONG&gt;2&lt;/STRONG&gt;];&lt;/P&gt;&lt;P&gt;&amp;nbsp; f = g/h;&lt;/P&gt;&lt;P&gt;return (f);&lt;/P&gt;&lt;P&gt;finish funcf;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;con = {&lt;STRONG&gt;0.01&lt;/STRONG&gt; &lt;STRONG&gt;0.02&lt;/STRONG&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;0.05&lt;/STRONG&gt; &lt;STRONG&gt;0.05&lt;/STRONG&gt;};&lt;/P&gt;&lt;P&gt;x0 = {&lt;STRONG&gt;0.01 0.02&lt;/STRONG&gt;};&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;optn = {&lt;STRONG&gt;1&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;1&lt;/STRONG&gt;};&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;call nlphqn(rc, xres, "funcf", x0, optn) blc=con;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print xres;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help would be appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 00:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858646#M5959</guid>
      <dc:creator>Xing_</dc:creator>
      <dc:date>2023-02-14T00:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Optimization: call nlphqn</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858697#M5960</link>
      <description>&lt;P&gt;Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Meanwhile I recommend to start exploring visually what the function looks like.&amp;nbsp;Mathematically I cannot help you. and I lack knowledge of a feasible data range for x, y, z. Here comes some code to get you started.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
x=do(0.1,10, 0.1);
y=do(0.1,10, 0.1);

xy=expandgrid(x,y);

start fxy(xx, yy);
gxy=1/xx+1/yy;
z=rand('uniform', 1, 10);
/* z=10; */
hxyz=xx/z+yy;
f=z||gxy/hxyz;
return(f);
finish fxy;

res=j(nrow(xy), 4, .);

do i=1 to nrow(xy);
res[i, 1:2]=xy[i,]; 
res[i, 3:4]=fxy(xy[i,1], xy[i,2]);
end;

create outs from res [colname={'x' 'y' 'z' 'res'}];
append from res;
close outs;
quit;


proc template;
  define statgraph surfaceplotparm;
    begingraph;
      entrytitle "Surface Plot of task";
      layout overlay3d / cube=false;
        surfaceplotparm x=x y=y z=res /
          reversecolormodel=true
          colorresponse=z
          colormodel=(red yellow green);
      endlayout;
    endgraph;
  end;
run;

proc sgrender data= outs template=surfaceplotparm;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Feb 2023 11:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858697#M5960</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2023-02-14T11:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Optimization: call nlphqn</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858700#M5961</link>
      <description>&lt;P&gt;When you say, "h(x, y, z) is minimized for each (x, y) and the range z is provided," do you mean that you are treating h as a 1-D function? For each (x,y) value, you want to minimize h for z in the range [1, 10]?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, the minimum value is always z_max = 10 when x &amp;gt; 0, as it appears to be. The minimum of h(z; x, y) = x/z + y is achieved when z is as large as possible, and you have constrained z in [1, 10].&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem therefore reduces to minimizing the function &lt;BR /&gt;f(x,y) = (1/x + 1/y) / (x/10 + y)&lt;/P&gt;
&lt;P&gt;Both partial derivatives are negative when x&amp;gt;0 and y&amp;gt;0, so the minimum occurs when x and y are as large as possible. Therefore,&amp;nbsp;on the domain [0.01, 0.05] x [0.02, 0.05], the solution is at (x,y) = (0.05, 0.05).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this the correct interpretation of your question?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 11:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858700#M5961</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-02-14T11:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Optimization: call nlphqn</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858742#M5962</link>
      <description>&lt;P&gt;Thank you for the response. Yes, h(x, y, z) is a 1-dimention function for each x and y. The example I presented is simple since both functions are monotonic functions. The real ones are very complicated actually&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":frowning_face:"&gt;☹️&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 15:04:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858742#M5962</guid>
      <dc:creator>Xing_</dc:creator>
      <dc:date>2023-02-14T15:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Optimization: call nlphqn</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858755#M5963</link>
      <description>&lt;P&gt;OK. Here is the IML solution to the simple problem you posted. The problem is degenerate (no minima), so you get lots of NOTEs in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;

start funch(z) global(g_xy);
  x = g_xy[1]; y = g_xy[2]; 
  f = x / z + y;
  return (f);
finish funch;

/* first, test that we get the correct answer when we optimize funch()
   for fixed values of (x,y) */
g_xy = {0.1 0.15};
con = {1,
       10};
x0 = {1};          
optn = {1,              
        0};            * no printing!;
call nlphqn(rc, xres, "funch", x0, optn) blc=con; 
print xres;


/* now set up the real objective function problem */
start funcf(x) global(g_xy);
   g_xy = x;       /* copy x -&amp;gt; g_xy */
   con = {1,
          10};
   x0 = {1};          
   optn = {1,              
           0};            /* no printing! */
   call nlphqn(rc, z, "funch", x0, optn) blc=con; 
   h=x[1]/z + x[2];
   g=1/x[1]+1/x[2];
   f = g/h;
   return (f);
finish funcf;

con = {0.01 0.02,
       0.05 0.05};
x0 = {0.01 0.02};          
optn = {1,              
        1};            
call nlphqn(rc, xres, "funcf", x0, optn) blc=con; 
print xres;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Feb 2023 15:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/858755#M5963</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-02-14T15:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Optimization: call nlphqn</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/859232#M5964</link>
      <description>&lt;P&gt;Thank you for the code. It really helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The log file shows either "NOTE: ABSGCONV convergence criterion satisfied." or "NOTE: All parameters are actively constrained. Optimization cannot proceed." Is something wrong with the second note? It sounds that no optimization procedure was done. Any input here?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 16:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/859232#M5964</guid>
      <dc:creator>Xing_</dc:creator>
      <dc:date>2023-02-16T16:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Optimization: call nlphqn</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/859254#M5965</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;gt; &lt;EM&gt;"NOTE: All parameters are actively constrained. Optimization cannot proceed."&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The note means that the algorithm wants to take a step in the "downhill" direction, but the constraints prevent it from doing so. As I said, your toy problem is degenerate. Every subproblem has the solution on the boundary of the constraint region.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The messages in the log are NOTEs. They are not WARNINGs or ERRORs. So there is something unusual happening, but nothing is wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 19:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/859254#M5965</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-02-16T19:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Optimization: call nlphqn</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/859974#M5966</link>
      <description>&lt;P&gt;One more question about&amp;nbsp; optn= {1}; Does it mean to solve a maximization problem? It aims to minimize the function, the optn[1] value should be 0 instead of 1? When I replace 1 by 0, the error message is shown as below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: NLPHQN call: The number of observations must be set.&lt;BR /&gt;Use the first element of the OPT vector.&lt;BR /&gt;ERROR: (execution) Matrices do not conform to the operation.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 18:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/859974#M5966</guid>
      <dc:creator>Xing_</dc:creator>
      <dc:date>2023-02-21T18:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Optimization: call nlphqn</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/859976#M5967</link>
      <description>&lt;P&gt;You stated that you wanted to use the NLPHQN subroutine. &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/imlug/imlug_langref_sect290.htm" target="_self"&gt;The documentation states&lt;/A&gt; "The NLPHQN subroutine uses a hybrid quasi-Newton &lt;EM&gt;least squares method&lt;/EM&gt;&amp;nbsp;[emphasis added] to compute an optimum value of a function." Later on the same page, it states "&lt;SPAN&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;: In least squares subroutines, you must set the first element of the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=" aa-argument"&gt;opt&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;vector to&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=" aa-mathtext"&gt;m&lt;/SPAN&gt;&lt;SPAN&gt;, the number of functions.&lt;/SPAN&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the objective function in this problem is scalar-valued, you can use a different optimizer (such as NLPNRA or NLPQN) to solve the problem. If you use a different optimizer, then you can set opt[1]=0, which specifies that the optimizer should find a minimum of a scalar-valued function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 18:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/859976#M5967</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-02-21T18:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Nonlinear Optimization: call nlphqn</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/860002#M5968</link>
      <description>&lt;P&gt;Got it! Thank you so much!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 20:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Nonlinear-Optimization-call-nlphqn/m-p/860002#M5968</guid>
      <dc:creator>Xing_</dc:creator>
      <dc:date>2023-02-21T20:13:43Z</dc:date>
    </item>
  </channel>
</rss>

