<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/153821</link>
    <title>MATLAB Central Newsreader - Clustering Pairs</title>
    <description>Feed for thread: Clustering Pairs</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The 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>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 02 Aug 2007 06:16:03 -0400</pubDate>
      <title>Re: Clustering Pairs</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/153821#385972</link>
      <author>us</author>
      <description>Marie:&lt;br&gt;
&amp;lt;SNIP down to problem with example...&lt;br&gt;
&lt;br&gt;
&amp;gt; [1 10;1 11;1 12;2 11;5 10;5 15;6 18]&lt;br&gt;
&amp;gt; I want to cluster together all pairs of numbers that contain common values. For example, in this case this would be [1 2 5 10 11 12 15] and [6 18]...&lt;br&gt;
&lt;br&gt;
there are many solutions to this.&lt;br&gt;
however, your example does not make sense...&lt;br&gt;
can you be more clear?&lt;br&gt;
us&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 02 Aug 2007 02:16:44 -0400</pubDate>
      <title>Clustering Pairs</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/153821#385962</link>
      <author>Marie </author>
      <description>Greetings,&lt;br&gt;
I have a series of pairs of numbers, e.g.:&lt;br&gt;
[1 10;1 11;1 12;2 11;5 10;5 15;6 18]&lt;br&gt;
I want to cluster together all pairs of numbers that contain common values. For example, in this case this would be [1 2 5 10 11 12 15] and [6 18].&lt;br&gt;
Any help is appreciated!&lt;br&gt;
S&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 02 Aug 2007 01:51:12 -0400</pubDate>
      <title>Re: Clustering Pairs</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/153821#385976</link>
      <author>ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)</author>
      <description>In article &amp;lt;f8reqc$o08$1@fred.mathworks.com&amp;gt;, "Marie "&lt;br&gt;
&amp;lt;sarrowsmith@gmail.com&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; Greetings,&lt;br&gt;
&amp;gt; I have a series of pairs of numbers, e.g.:&lt;br&gt;
&amp;gt; [1 10;1 11;1 12;2 11;5 10;5 15;6 18]&lt;br&gt;
&amp;gt; I want to cluster together all pairs of numbers that contain common&lt;br&gt;
values. For example, in this case this would be [1 2 5 10 11 12 15] and [6&lt;br&gt;
18].&lt;br&gt;
&amp;gt; Any help is appreciated!&lt;br&gt;
&amp;gt; S&lt;br&gt;
----------------------&lt;br&gt;
&amp;nbsp;&amp;nbsp;I believe you are seeking what in mathematics is known as an equivalence&lt;br&gt;
relation, Marie.  For example, the 2 and the 15 are in the same&lt;br&gt;
equivalence class (cluster) because of a chain of pairings connecting&lt;br&gt;
them: (2,11), (11,1), (1,10), (10,5), and (5,15).  (Note that order within&lt;br&gt;
the pairs is not significant.)  If I am interpreting you correctly, the&lt;br&gt;
following is designed to carry out the desired clustering.  However, since&lt;br&gt;
my version of matlab does not have the cell array feature, I leave the&lt;br&gt;
last step to you.&lt;br&gt;
&lt;br&gt;
% Choose a two-columned array A of pairs regarded as equivalent&lt;br&gt;
A = [1 10;1 11;1 12;2 11;5 10;5 15;6 18];&lt;br&gt;
&lt;br&gt;
% Then develop a transitive, commutative (symmetric) matrix M.&lt;br&gt;
[B,ig,N] = unique(A(:)); % Find all the unique elements of A&lt;br&gt;
n = size(B,1);&lt;br&gt;
N = reshape(N,[],2); % N is same size as A with indices into B&lt;br&gt;
M = accumarray(N,1,[n,n]); % Place 1's in M corres. to pairs in N&lt;br&gt;
M = M+M.'; % Make M symmetric&lt;br&gt;
M(M~=0) = 1; % Set nonzeros equal to 1&lt;br&gt;
fg = true;&lt;br&gt;
while fg  % Loop until M is entirely transitive and symmetric&lt;br&gt;
&amp;nbsp;Mc = M; % Save copy of M&lt;br&gt;
&amp;nbsp;M = M*M+M; % Extend M transitively&lt;br&gt;
&amp;nbsp;M(M~=0) = 1; % Replace nonzeros with ones&lt;br&gt;
&amp;nbsp;fg = any(any(M~=Mc)); % Quit loop when M remains unchanged&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
% The unique rows of M indicate the desired equivalence sets (clusters)&lt;br&gt;
C = unique(M,'rows'); % Find unique rows of M&lt;br&gt;
&lt;br&gt;
% For each row of C, convert the 1's to the corresponding elements of A&lt;br&gt;
c{i} = B(C(i,:)~=0);&lt;br&gt;
% Presumably you will place each of these c{i}'s in a cell array, since&lt;br&gt;
they are of differing lengths.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;The truth is that I don't have the 'unique' and 'accumarray' functions&lt;br&gt;
either, so you should test this out carefully, since it is difficult for&lt;br&gt;
me to do so thoroughly.  I have only had the patience to carry out a&lt;br&gt;
simple test where the 'unique' and 'accumarrays' have been manually&lt;br&gt;
determined.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
