<?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: call NLPQN generating &amp;quot;Matrices do not conform error&amp;quot; while module runs fine in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/call-NLPQN-generating-quot-Matrices-do-not-conform-error-quot/m-p/183422#M1838</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks so much - all your suggestions are very helpful!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 17 Jul 2014 21:46:35 GMT</pubDate>
    <dc:creator>acsb</dc:creator>
    <dc:date>2014-07-17T21:46:35Z</dc:date>
    <item>
      <title>call NLPQN generating "Matrices do not conform error" while module runs fine</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/call-NLPQN-generating-quot-Matrices-do-not-conform-error-quot/m-p/183420#M1836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi - I am a very new IML user and I'd appreciate any help.&amp;nbsp; I'm trying to optimize a system of pricing equations subject to a set of nonlinear constraints.&amp;nbsp; Setting this up, I wrote a module to calculate the total profit, which will be my objective function.&amp;nbsp; That code (below) when called with my initial values for the objective function returns the value I expect.&amp;nbsp; However, when I try to call NLPQN, I get an error (below) directing me to the calculation of A, the average prices.&amp;nbsp; It reports that I'm trying to multiply a 186 x 558 matrix by a 1 x 558 vector, which obviously won't work.&amp;nbsp; However, the vector X should be 558 x 1.&amp;nbsp; Can anybody shed any light on this for me?&amp;nbsp; I've tried transposing the vector, but I get the same error. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;**INITIAL VALUES FOR PRICES;&lt;/P&gt;&lt;P&gt;&amp;nbsp; use &amp;amp;OPT_DATA.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; read all var{PRICE1,PRICE2,PRICE3} into prices;&lt;/P&gt;&lt;P&gt;&amp;nbsp; X0 = prices[,1]//prices[,2]//prices[,3];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;start PROFIT(X);&lt;/P&gt;&lt;P&gt;**READING IN THE RAW DATA;&lt;/P&gt;&lt;P&gt;&amp;nbsp; use &amp;amp;OPT_INTCRS.(keep=EFF:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; read all var _ALL_ into CI;&lt;/P&gt;&lt;P&gt;&amp;nbsp; use &amp;amp;OPT_EXTCRS.(keep=EXT_COEF EXT_FIXED);&lt;/P&gt;&lt;P&gt;&amp;nbsp; read all var _ALL_ into CX;&lt;/P&gt;&lt;P&gt;&amp;nbsp; use &amp;amp;OPT_DATA.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; read all var{A1,A2,A3,A4} into param;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**CREATING PARAMETERS USED IN OBJECTIVE FUNCTION;&lt;/P&gt;&lt;P&gt;&amp;nbsp; S = (j(&amp;amp;N.,2*&amp;amp;N.,0)||I(&amp;amp;N.)); *Selection Matrix;&lt;/P&gt;&lt;P&gt;&amp;nbsp; A = S*X; *Average Prices;&lt;/P&gt;&lt;P&gt;&amp;nbsp; M = A - param[,4]; *Margin;&lt;/P&gt;&lt;P&gt;&amp;nbsp; C = param[,1]#I(&amp;amp;N.)||param[,2]#I(&amp;amp;N.)||(T(CI) + (CX[,1]#I(&amp;amp;N.))); *Coefficients on Prices;&lt;/P&gt;&lt;P&gt;&amp;nbsp; F = CX[,2] + param[,3]; *Fixed Effect;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Q = exp(C*log(X) + F); *Total Quantity;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**OBJECTIVE FUNCTION;&lt;/P&gt;&lt;P&gt;&amp;nbsp; P = T(M)*Q; *Profit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; return(P);&lt;/P&gt;&lt;P&gt;finish PROFIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**When I run this bit of code it reports the expected value;&lt;/P&gt;&lt;P&gt;z = PROFIT(X0);&lt;/P&gt;&lt;P&gt;print z;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**However, when I try to optimize (even without the constraints), I get the following error;&lt;/P&gt;&lt;P&gt;call NLPQN(rc,xres,"PROFIT",X0,optn) nlc="CONSTRAINTS";&lt;/P&gt;&lt;P&gt;ERROR: (execution) Matrices do not conform to the operation.&lt;/P&gt;&lt;P&gt;operation : * at line 33514 column 12&lt;/P&gt;&lt;P&gt;operands&amp;nbsp; : S, X&lt;/P&gt;&lt;P&gt;S&amp;nbsp;&amp;nbsp;&amp;nbsp; 186 rows&amp;nbsp;&amp;nbsp;&amp;nbsp; 558 cols&amp;nbsp;&amp;nbsp;&amp;nbsp; (numeric)&lt;/P&gt;&lt;P&gt;X&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 row&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 558 cols&amp;nbsp;&amp;nbsp;&amp;nbsp; (numeric)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 16:46:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/call-NLPQN-generating-quot-Matrices-do-not-conform-error-quot/m-p/183420#M1836</guid>
      <dc:creator>acsb</dc:creator>
      <dc:date>2014-07-17T16:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: call NLPQN generating "Matrices do not conform error" while module runs fine</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/call-NLPQN-generating-quot-Matrices-do-not-conform-error-quot/m-p/183421#M1837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/viewer.htm#imlug_langref_sect264.htm"&gt;documentation for the NLP functions &lt;/A&gt;states that "the argument x0 specifies a row vector," so your objective function should expect a row vector. The easiest way to do that without rewriting the code is to define the function as&lt;/P&gt;&lt;P&gt;start PROFIT(TX); /* argument is row vector */&lt;/P&gt;&lt;P&gt;X = T(TX); /* transpose to column vector */&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;finish;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's an unsolicited tip for efficiency. Currently you are reading three data sets for each call to the objective function. This will be GLACIALLY slow!&amp;nbsp; Instead, read the data sets OUTSIDE the objective function and use a GLOBAL statement to pass in those parameters:&lt;/P&gt;&lt;P&gt;start PROFIT(TX) global(CI, CX, param);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another tip: The matrix multiplication S*X is merely extracting the bottom 62 (=&amp;amp;N.) elements of the X vector.&lt;/P&gt;&lt;P&gt;A more efficient way to get that data is to extract it with subscripts:&lt;/P&gt;&lt;P&gt;A = X[(2*&amp;amp;N.+1):(3*&amp;amp;N.)];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to look at an online examples of optimization, see&lt;A href="http://blogs.sas.com/content/iml/2011/10/12/maximum-likelihood-estimation-in-sasiml/" title="http://blogs.sas.com/content/iml/2011/10/12/maximum-likelihood-estimation-in-sasiml/"&gt;&amp;nbsp; Maximum likelihood estimation in SAS/IML - The DO Loop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 18:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/call-NLPQN-generating-quot-Matrices-do-not-conform-error-quot/m-p/183421#M1837</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-07-17T18:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: call NLPQN generating "Matrices do not conform error" while module runs fine</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/call-NLPQN-generating-quot-Matrices-do-not-conform-error-quot/m-p/183422#M1838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks so much - all your suggestions are very helpful!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 21:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/call-NLPQN-generating-quot-Matrices-do-not-conform-error-quot/m-p/183422#M1838</guid>
      <dc:creator>acsb</dc:creator>
      <dc:date>2014-07-17T21:46:35Z</dc:date>
    </item>
  </channel>
</rss>

