<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240921</link>
    <title>MATLAB Central Newsreader - sparse matrix reordering</title>
    <description>Feed for thread: sparse matrix reordering</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 12 Dec 2008 16:28:02 -0500</pubDate>
      <title>sparse matrix reordering</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240921#616672</link>
      <author>A B</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
I'm having a symmetric sparse matrix and I want to reorder it, which I am doing&lt;br&gt;
with:&lt;br&gt;
&lt;br&gt;
A = sparse(row,col,val);&lt;br&gt;
p=symamd(A);&lt;br&gt;
&lt;br&gt;
That of course works fine...&lt;br&gt;
&lt;br&gt;
Now, as I often change the values of the matrix A, but not it's structure I wanted to keep the three vectors, row, col, val and just reorder in the vectors row and col. That way I only have to work with the vector val and not perform operations on a sparse matrix.&lt;br&gt;
&lt;br&gt;
So I did:&lt;br&gt;
reorder_row = p(row);&lt;br&gt;
reorder_col = p(col);&lt;br&gt;
&lt;br&gt;
However the matrices&lt;br&gt;
&lt;br&gt;
A1 = sparse(reorder_row,reorder_col,val);&lt;br&gt;
A2 = A(p,p)&lt;br&gt;
&lt;br&gt;
don't have the same structure. Obviously, A2's structure is as expected, but A1 is completly wrong.&lt;br&gt;
&lt;br&gt;
I just got some knot in my brain and don't see the reason for this. Can anyone help me and explain me why it's different and how I would properly do it.&lt;br&gt;
&lt;br&gt;
Thank you very very much</description>
    </item>
    <item>
      <pubDate>Fri, 12 Dec 2008 22:31:02 -0500</pubDate>
      <title>Re: sparse matrix reordering</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240921#616726</link>
      <author>Tim Davis</author>
      <description>&quot;A B&quot; &amp;lt;gitsnedbutzi@hotmail.com&amp;gt; wrote in message &amp;lt;ghu3ei$nl7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'm having a symmetric sparse matrix and I want to reorder it, which I am doing&lt;br&gt;
&amp;gt; with:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A = sparse(row,col,val);&lt;br&gt;
&amp;gt; p=symamd(A);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; That of course works fine...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Now, as I often change the values of the matrix A, but not it's structure I wanted to keep the three vectors, row, col, val and just reorder in the vectors row and col. That way I only have to work with the vector val and not perform operations on a sparse matrix.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So I did:&lt;br&gt;
&amp;gt; reorder_row = p(row);&lt;br&gt;
&amp;gt; reorder_col = p(col);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However the matrices&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A1 = sparse(reorder_row,reorder_col,val);&lt;br&gt;
&amp;gt; A2 = A(p,p)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; don't have the same structure. Obviously, A2's structure is as expected, but A1 is completly wrong.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I just got some knot in my brain and don't see the reason for this. Can anyone help me and explain me why it's different and how I would properly do it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you very very much&lt;br&gt;
&lt;br&gt;
The vector p can be considered a function whose input is k where k is a row/column index in the *new* matrix, and the output is i where i is a row/column of the old (unpermuted) matrix.  that is, i=p(k).  But if you want to change the *old* row/column indices to the *new* ones to use in sparse(...) then you need the inverse of this function, k=inverse_of_p(i).  You can compute the inverse permutation vector using:&lt;br&gt;
&lt;br&gt;
n = size(A,1);&lt;br&gt;
invp = zeros (1,n) ;&lt;br&gt;
invp (p) = 1:n ;&lt;br&gt;
&lt;br&gt;
then do&lt;br&gt;
&lt;br&gt;
A1 = sparse (invp (row), invp (col), val) ;&lt;br&gt;
&lt;br&gt;
by the way, p=amd(A) is faster than symamd.</description>
    </item>
    <item>
      <pubDate>Sun, 14 Dec 2008 08:38:03 -0500</pubDate>
      <title>Re: sparse matrix reordering</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240921#616896</link>
      <author>A B</author>
      <description>&amp;gt; The vector p can be considered a function whose input is k where k is a row/column index in the *new* matrix, and the output is i where i is a row/column of the old (unpermuted) matrix.  that is, i=p(k).  But if you want to change the *old* row/column indices to the *new* ones to use in sparse(...) then you need the inverse of this function, k=inverse_of_p(i).  You can compute the inverse permutation vector using:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; n = size(A,1);&lt;br&gt;
&amp;gt; invp = zeros (1,n) ;&lt;br&gt;
&amp;gt; invp (p) = 1:n ;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; then do&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A1 = sparse (invp (row), invp (col), val) ;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; by the way, p=amd(A) is faster than symamd.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
if there's a sparse matrix problem, there's always a tim davis :-)&lt;br&gt;
&lt;br&gt;
i would never have come up with using the inverse, as i always considered the vector p to be a function whose's input is the row/column index of the old matrix and the output the indices of the new one.&lt;br&gt;
&lt;br&gt;
thanks, that helped a lot. </description>
    </item>
  </channel>
</rss>

