sevamoo / SOMPY

A Python Library for Self Organizing Map (SOM)
Apache License 2.0
535 stars 242 forks source link

HitMapView and BmuHitsView have inverted positions #98

Open ricardomourarpm opened 5 years ago

ricardomourarpm commented 5 years ago

Dear all,

When performing a clusterization of underwater acoustic files I wanted to observe the hitsmap of all the nodes and see it conjointly with the cluster atribution by node.

That is, the HitMapView and the BmuHitsView.

If you see the images bellow

image

image

what happens is that the node with 14 hits is in fact located in cluster 7, that is, in the opposite direction. With carefull watching, observing the location of every individual in the node atribution and the cluster atribution, I concluded that they are all in inverted position.

I'm going to observe the code and see where it may be corrected. Meanwhile if you may find it first I appreciate.

Thank you,

Ricardo

ricardomourarpm commented 5 years ago

I observed that in bmuhits.py we have,

    elif som.codebook.lattice == "hexa":
        ax, cents = plot_hex_map(mp[::-1], colormap=cmap, fig=self._fig)
        if anotate:
            self._set_labels(cents, ax, reversed(counts), onlyzeros, labelsize, hex=True)

That is, we have reversed(counts) while in hitmap.py

    elif som.codebook.lattice == "hexa":
        ax, cents = plot_hex_map(np.flip(clusters.reshape(msz[0], msz[1])[::], axis=1),  fig=self._fig, 
                                                 colormap=cmap, colorbar=False)
        if anotate:
            self._set_labels(cents, ax, clusters, onlyzeros, labelsize, hex=True)

That is we do not have reversed. By replacing reversed(counts) by only counts, the maps now coincide.

Should I instead put reversed(clusters)? (nodes position can star from bottom right)

Thank you!

ricardomourarpm commented 5 years ago

Ok! Now that I have been thorough through the code I observed the following:

plot_hex_map should be called like

     plot_hex_map(np.flip(Nodes_with_selected_variables.values.reshape(som_chosen.codebook.mapsize +
                                                          [Nodes_with_selected_variables.values.shape[-1]]),axis=0),
         titles=Nodes_with_selected_variables.columns, shape=[1, 3], colormap=None)

we shoud flip across axis=0

and the file hitmap.py should be changed also in the end as

    elif som.codebook.lattice == "hexa":
        ax, cents = plot_hex_map(np.flip(clusters.reshape(msz[0], msz[1])[::], axis=0),  fig=self._fig, colormap=cmap, colorbar=False)
        if anotate:
            self._set_labels(cents, ax, reversed(clusters), onlyzeros, labelsize, hex=True)

also flipping across axis=0 and putting reversed(clusters) to match the visualizations produced in bmuhits.py.

Please check this!

Thanks for your work!