JustGlowing / minisom

:red_circle: MiniSom is a minimalistic implementation of the Self Organizing Maps
MIT License
1.45k stars 422 forks source link

Proper interpretation of the bubble neighborhood function and sigma #61

Open AWSisco opened 4 years ago

AWSisco commented 4 years ago

I have a question regarding the bubble neighborhood function and how to interpret the value of sigma. Take the following SOM, for example:

som = MiniSom(x = 4, y = 3, input_len = 1000, sigma = 3, learning_rate = 0.05, neighborhood_function = "bubble")

This triggers a warning since sigma >= y, and minisom.py does note that sigma should be an odd integer for the bubble neighborhood function but I'm not entirely sure why. Is sigma for the bubble function just the radius from the winning node? E.g., if instead I set sigma = 1, would that mean just the immediately neighboring nodes of the winner are updated? After sigma decreases to less than 1, is only the winning node updated?

Thanks so much for any clarification you can provide!

JustGlowing commented 4 years ago

hi Adam,

You get that warning because the current implementation of the bubble and triangle functions doesn't center the values properly when sigma is even.

If sigma=1 only the winning node is updated if you use bubble or triangle, This strategy is called "winner takes all" (Haykin 1999). With gaussian and mexican_hat the neighbours of the winner will still have a small update. If sigma<1 one gaussian and mexican_hat will only update the winner but bubble or triangle will not work.

AWSisco commented 4 years ago

Thank so much @JustGlowing. That clears up sigma=1 for me.

However, you say above that bubble does not center properly when sigma is odd, but I'm still confused since lines 208-211 in minisom.py seem to state that sigma should be odd.

def _bubble(self, c, sigma):
        """Constant function centered in c with spread sigma.
        sigma should be an odd value.
        """
JustGlowing commented 4 years ago

My bad, I meant when sigma is even. I also corrected my first answer for future readers.

omerbt commented 4 years ago

hi Adam,

You get that warning because the current implementation of the bubble and triangle functions doesn't center the values properly when sigma is even.

If sigma=1 only the winning node is updated if you use bubble or triangle, This strategy is called "winner takes all" (Haykin 1999). With gaussian and mexican_hat the neighbours of the winner will still have a small update. If sigma<1 one gaussian and mexican_hat will only update the winner but bubble or triangle will not work.

I trained the model with 'gaussian' and sigma = 0.8,0.6,0.4,0.2, and the results I get are completely different (all other parameters were not changed, and I use the same random seed). How are different values [that are all <1] change the training process?

JustGlowing commented 4 years ago

hi @omerbt small changes in sigma can have big impacts on the results of training even when sigma is kept below 1. It all depends on the size of the map and the data that you have.

omerbt commented 4 years ago

Hi, thank you for the answer. just to make sure I get it right - isn't sigma only relevant for the choice of neurons to update in each step?

JustGlowing commented 4 years ago

Yes, sigma is the spread of the neighbourhood function. The bigger sigma, the more bigger the neighbourhood that will be affected by the training step.

omerbt commented 4 years ago

So if sigma < 1 implies updating only the winner, then why should I expect different values in that range to lead to different results (since anyway only the winner will be updated)? thanks

JustGlowing commented 4 years ago

If sigma < 1 you don't update only the winner but also other neurons by just a small amount. If you want to update only the winner you can user the triangle function with sigma=1.

omerbt commented 4 years ago

great, thanks!