<?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: TensorFlow MNIST in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318991#M3139</link>
    <description>&lt;P&gt;Thanks for your reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't figure out how to use NLPQN.&amp;nbsp; When I submit&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; nlpqn(rc,xrv,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'ml'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,wbv);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I get the following errors.&lt;/P&gt;
&lt;P&gt;ERROR: QUANEW Optimization cannot be completed.&lt;/P&gt;
&lt;P&gt;ERROR: The function value of the objective function cannot be computed during the optimization process.&lt;/P&gt;
&lt;P&gt;ERROR: Execution error as noted previously. (rc=100)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Dec 2016 16:42:55 GMT</pubDate>
    <dc:creator>mcs</dc:creator>
    <dc:date>2016-12-14T16:42:55Z</dc:date>
    <item>
      <title>TensorFlow MNIST</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318708#M3130</link>
      <description>&lt;P&gt;I'd like to&amp;nbsp;implement TensorFlow's&amp;nbsp;MNIST for ML Beginners&amp;nbsp; in SAS.&amp;nbsp; &lt;A href="https://www.tensorflow.org/tutorials/mnist/beginners/" target="_blank"&gt;https://www.tensorflow.org/tutorials/mnist/beginners/&lt;/A&gt;&amp;nbsp; It classifies handwritten digits based on pixel intensities.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Their model is y = softmax(Wx + b), where&lt;/P&gt;
&lt;P&gt;&amp;nbsp; y = output vector of digit probabilities&lt;/P&gt;
&lt;P&gt;&amp;nbsp; W = weight matrix&lt;/P&gt;
&lt;P&gt;&amp;nbsp; x = pixel intensities&lt;/P&gt;
&lt;P&gt;&amp;nbsp; b = bias vector&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They optimize W and b&amp;nbsp;by minimizing&amp;nbsp;cross-entropy, H = -Σy'log(y).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've got some working SAS code, but it's not fast enough to do what I want yet.&amp;nbsp; Using 10 principal components (instead of all the pixel values), and 10 training batches of 100 observations each, my code runs in about 2 minutes.&amp;nbsp; I'd like to increase each of those parameteres by a factor of 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the part of my code implementing their model..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;wbv = j(1,10*&amp;amp;pc+10,0.1);			/* 10 weights per pc + 10 bias, vector format */
start ml(wbv) global(x,yp);			/* x is pc scores, yp is 1-hot digit labels */
	wb = shape(wbv,&amp;amp;pc+1,10);		/* weight and bias, matrix format */
	logy = x*wb-log(exp(x*wb)[,+]); 	/* y is softmax of evidence */
	ce = (-yp#logy)[:,+];			/* mean cross-entropy */
	return ce;
finish;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm using&amp;nbsp;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; nlpnra(rc,xrv,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'ml'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,wbv) &lt;/FONT&gt;as the optimization routine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there an easy way to get a big speedup?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 21:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318708#M3130</guid>
      <dc:creator>mcs</dc:creator>
      <dc:date>2016-12-13T21:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: TensorFlow MNIST</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318739#M3131</link>
      <description>&lt;P&gt;What version of SAS/IML are you running? Which operating system?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you've posted is not very time intensive. It can be marginally improved, but not by 10-fold. &amp;nbsp;Some ideas you can try:&lt;/P&gt;
&lt;P&gt;1. Compute xwb = x*wb one time and use it in the formul for logy&lt;/P&gt;
&lt;P&gt;2. Shape the wbv parameter vector once outside the function and pass it in, instead of reshaping it every call of the optimization.&lt;/P&gt;
&lt;P&gt;3. Provide better initial guesses for the optimization routine. &amp;nbsp;In particular, using all zeros or all ones is a bad idea. If you are doing an iterative method, use estimates from the previous iteration to seed the next iteration.See steps 3 and 4 of &lt;A href="http://blogs.sas.com/content/iml/2016/05/11/tips-before-optimization.html" target="_self"&gt;"Ten tips before you run an optimization"&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;4. If your matrices are large,&lt;A href="http://blogs.sas.com/content/iml/2015/07/31/large-matrices.html" target="_self"&gt; make sure your RAM is large enough&lt;/A&gt; to hold multiple copies of these large matrices.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recommend that that you use the TIME function to profile the various steps of the algorithm to fid out where it is spending most of the time. The I/O? The eigenvalue computation? &amp;nbsp;Depending on what you find, see if &amp;nbsp;you can optimize the bottleneck. &amp;nbsp; The general code snippet is&lt;/P&gt;
&lt;P&gt;t0 = time();&lt;/P&gt;
&lt;P&gt;/* computation here */&lt;/P&gt;
&lt;P&gt;tElapsed = time()-t0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See also the general pricipals in the first three tips in the article &lt;A href="http://blogs.sas.com/content/iml/2012/06/06/tips-to-make-your-simulation-run-faster.html" target="_self"&gt;"Eight tips to make your simulation run faster.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 01:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318739#M3131</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-12-14T01:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: TensorFlow MNIST</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318746#M3132</link>
      <description>&lt;P&gt;NLPQN (Dual) Quasi-Newton Method&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;could get you a little faster.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 03:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318746#M3132</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-14T03:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: TensorFlow MNIST</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318990#M3138</link>
      <description>&lt;P&gt;Thanks for the reply.&amp;nbsp; I'm running SAS/IML 13.2 on Windows 7.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;OK, I did this.&amp;nbsp; It shaved&amp;nbsp;20 seconds or so off the two-minute run time.&lt;/LI&gt;
&lt;LI&gt;The wbv parameter vector is the thing being optimized by proc nlpnra, and I think it has to be passed&amp;nbsp;from nlpnra to ml&amp;nbsp;as a vector.&amp;nbsp; When I try to pass it as a matrix, I get ERROR: NLPNRA call: Error in argument X0.&lt;/LI&gt;
&lt;LI&gt;OK, I did this.&amp;nbsp; Surprisingly, it increased the run time by more than a minute.&lt;/LI&gt;
&lt;LI&gt;My matrices aren't that big.&amp;nbsp;&amp;nbsp;My batch size (rows of x) and number of principal components (columns of x) will both be under 1000.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Regarding 3., I must be doing something wrong.&amp;nbsp; Here's my do loop.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;wbv = j(1,&amp;amp;pg*11,0.1);&lt;BR /&gt;do i = 1 to &amp;amp;nb;
	x[,1:&amp;amp;pc] = train[rows[i,],2:&amp;amp;pc+1];
	yp[,unique(train[rows[i,],1])+1] = design(train[rows[i,],1]);
	call nlpnra(rc,xrv,'ml',wbv);
	wbv = xrv;
	xr[i,] = xrv;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Commenting out the line wbv = xrv, so that wbv always starts as a constant matrix of 0.1 instead of starting at the last solution, speeds up the code instead of slowing it down.&amp;nbsp; Why would that be?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 16:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318990#M3138</guid>
      <dc:creator>mcs</dc:creator>
      <dc:date>2016-12-14T16:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: TensorFlow MNIST</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318991#M3139</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't figure out how to use NLPQN.&amp;nbsp; When I submit&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; nlpqn(rc,xrv,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'ml'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,wbv);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I get the following errors.&lt;/P&gt;
&lt;P&gt;ERROR: QUANEW Optimization cannot be completed.&lt;/P&gt;
&lt;P&gt;ERROR: The function value of the objective function cannot be computed during the optimization process.&lt;/P&gt;
&lt;P&gt;ERROR: Execution error as noted previously. (rc=100)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 16:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/318991#M3139</guid>
      <dc:creator>mcs</dc:creator>
      <dc:date>2016-12-14T16:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: TensorFlow MNIST</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/319031#M3141</link>
      <description>&lt;P&gt;Regarding (3), I said "&lt;SPAN&gt;&lt;EM&gt;If you are doing an iterative method&lt;/EM&gt;, use estimates from the previous iteration to seed the next iteration." It is hard to tell from your code, but it looks like you might be looking new data each time in the loop? &amp;nbsp;If so, you might be using parameters from a bitmap that shows a "1" as an initial guess for a bitmap that shows an "8." That might explain the decrease in performance.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My point is to be smart about the &amp;nbsp;initial guess. &amp;nbsp;Often you can come up with heuristics that work better than a&amp;nbsp;constant matrix.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Sorry about the wrong suggestion for (2). &amp;nbsp;I think you are right: the argument should be a vector,&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 19:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/319031#M3141</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-12-14T19:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: TensorFlow MNIST</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/319048#M3150</link>
      <description>&lt;P&gt;I am doing an interative method.&amp;nbsp; At each step, I'm passing in a block of x values together with yp digit labels, and optimizing a weight matrix wb.&amp;nbsp; Then I'm passing a new block of x and yp, and again optimizing wb, and so on.&amp;nbsp; For 20 principal components (plus 1&amp;nbsp;constant), 10 digit labes,&amp;nbsp;and 100 block size, the matrix math&amp;nbsp;inside each optimization step&amp;nbsp;looks like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;y (100 rows, 10 columns) = softmax of x (100 rows, 20+1 columns) * wb (20+1 rows, 10 columns).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think your suggestion in (3) makes sense.&amp;nbsp; I would expect the wb matrix to be stable from block to block. It's supposed to generalize to out-of-sample data.&amp;nbsp; That's why it surprises me that starting from the previous iteration is so much slower than starting from a constant.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 21:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/319048#M3150</guid>
      <dc:creator>mcs</dc:creator>
      <dc:date>2016-12-14T21:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: TensorFlow MNIST</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/319241#M3151</link>
      <description>&lt;P&gt;You could do the following experiment: Let&lt;/P&gt;
&lt;P&gt;diff = norm( x0 - xf&amp;nbsp;)&lt;/P&gt;
&lt;P&gt;be the vector norm of the difference between the initial guess (x) and the optimal&amp;nbsp;parameter values (xf).&lt;/P&gt;
&lt;P&gt;A plot of diff vs iteration number will tell you how close the initial guess was to the final guess for each step in the iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If&amp;nbsp;the optimal solution at step (i+1) is close to the optimal solution at step i, you should see small differences. &amp;nbsp; &amp;nbsp;You can do the experiment twice: once using a constant initial guess and once using the optimal solution at the previous iteration.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 12:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/TensorFlow-MNIST/m-p/319241#M3151</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-12-15T12:47:04Z</dc:date>
    </item>
  </channel>
</rss>

