<?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: Overflow in matrix multiplication in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828663#M5854</link>
    <description>&lt;P&gt;The error occurs while you are attempting a nonlinear optimization with a nonlinear constraint. Without seeing the full program, I cannot determine why the error occurs.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Aug 2022 10:59:29 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2022-08-15T10:59:29Z</dc:date>
    <item>
      <title>Overflow in matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828638#M5851</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some code that tries to minimize a function.&lt;/P&gt;&lt;P&gt;The code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;start odr_yrly (matrix, year);
		yr_odr = j(nrow(matrix), year + 1, 0);
		yr_odr[,1] = matrix[,ncol(matrix)];
		do i = 1 to year;
			yr_odr[,i + 1] = matrix ** 4 * yr_odr[,i];
		end;
		yr_odr = yr_odr[,2:6];
		return(yr_odr);
	finish;

	start multi_year_dr_error(odr, full_matrix, year, pop);
		odr_last = j(1,ncol(odr),1);
		odr_full = odr // odr_last;
		pop_dist = pop[,5] // {0};
		odr_eff = odr_full[,3:6];
		idx = loc(odr_eff &amp;gt; 0);
		log_odr	= j(nrow(odr_eff),ncol(odr_eff),0);
		if ncol(idx) &amp;gt; 0 then log_odr[idx] = log(odr_eff[idx]);
		odr_est = odr_yrly(full_matrix, year);
		idx2 = loc(odr_est &amp;gt; 0);
		log_odr_est	= j(nrow(odr_est),ncol(odr_est),0);
		if ncol(idx2) &amp;gt; 0 then log_odr_est[idx2] = log(odr_est[idx2]);
		diff = (log_odr - log_odr_est[,2:5]) # pop_dist;
		print log_odr diff pop_dist log_odr_est;
		diff_sq = diff ## 2;
		ssq = diff_sq[+];
		return(ssq);
	finish;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now I can't see any problem with my matrix multiplication line&amp;nbsp;&lt;CODE class=""&gt;yr_odr[,i + 1] = matrix ** 4 * yr_odr[,i];&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;however it is giving me errors saying it overflowed.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cherrie_0-1660523252208.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74426iE2C2B8122C80EF29/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cherrie_0-1660523252208.png" alt="Cherrie_0-1660523252208.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;anyone has any idea why that is the case? Happy to post the full optimisation code here but its some long code with multiple parts to the optimisation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Cherrie&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 00:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828638#M5851</guid>
      <dc:creator>Cherrie</dc:creator>
      <dc:date>2022-08-15T00:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Overflow in matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828650#M5852</link>
      <description>&lt;P&gt;The syntax "matrix ** 4" is taking the 4th power of the matrix - so the whole matrix multiplied by itself 4 times.&amp;nbsp; This might not be what you intend and could potentially lead to an overflow.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 07:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828650#M5852</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2022-08-15T07:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Overflow in matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828652#M5853</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply. But this is what I intend to do though. However wouldn't overflow be on numbers that are extremely large? My matrix is a transition probability matrix with all entries less than 1...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's why I don't understand the error and how to solve it.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 09:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828652#M5853</guid>
      <dc:creator>Cherrie</dc:creator>
      <dc:date>2022-08-15T09:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Overflow in matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828663#M5854</link>
      <description>&lt;P&gt;The error occurs while you are attempting a nonlinear optimization with a nonlinear constraint. Without seeing the full program, I cannot determine why the error occurs.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 10:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828663#M5854</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-08-15T10:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Overflow in matrix multiplication</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828778#M5855</link>
      <description>&lt;P&gt;Thanks for the reply. I solved this issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What happens is I need to trial and error the migration matrix which supposed to be sum to 1 and have values between 0 and 1. however the optimisation program did not have this constraint programmed in so it gives me really large matrices (with individual cell even more than 3e60) which I used to 4th power. This resulted in an overflow.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have customised the error function so that when row sums of the matrix are more than 1 I force the error function to a really large value. This resolved this issue. Thanks for the reply!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 00:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Overflow-in-matrix-multiplication/m-p/828778#M5855</guid>
      <dc:creator>Cherrie</dc:creator>
      <dc:date>2022-08-16T00:44:59Z</dc:date>
    </item>
  </channel>
</rss>

