Confused about majorclust algorithm
Question: I would like to write my own code in matlab for "majorclust" algorithm. I have
document pairs having their cosine similarity. When i search through the web,
i encounter this web site.

<http://muse-amuse.in/~baali/MajorClustPost.html>

In the example(written in Python) in this web site, the clustering part is
given as follow:

    
    
    t = False
    indices = np.arange(num_of_samples)
    while not t:
      t = True
      for index in np.arange(num_of_samples):
        # aggregating edge weights 
        new_index = np.argmax(np.bincount(indices, 
        weights=cosine_distances[index]))
    if indices[new_index] != indices[index]:
      indices[index] = indices[new_index]
      t = False
    

When i examine the sample, i am a bit confused. When we consider the for loop:

    
    
    for index in np.arange(num_of_samples):
    

the first index will be "0". And maximum similarity is retrieved with "1". So
the new_index must be 1 and the index "0" will be replaced by "1".

On the next iteration index will be "1" and its maximum weight will come from
"0" which has the same index from the previous iteration. As a result, after
this point loop must terminate.

This algorithm is based on the paper (given on page 4):

<http://www.uni-weimar.de/medien/webis/publications/papers/stein_2002c.pdf>

On the paper, it is stated that index must be chosen randomly. But in the
example i could not see any random choice.

What am i missing?


Answer: Yes it would be good if you shuffle the indices and you can do the same using

    
    
    from random import shuffle
    shuffled_indices = np.arange(num_of_samples)
    shuffle(shuffled_indices)
    for index in shuffled_indices:
        # aggregating edge weights 
        new_index = np.argmax(np.bincount(indices,weights=cosine_distances[index]))
        if indices[new_index] != indices[index]:
            indices[index] = indices[new_index]
            t = False
    

Sorry for such a late reply.

