Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get bmu of testing data #164

Open
yanzastro opened this issue Sep 19, 2022 · 2 comments
Open

Get bmu of testing data #164

yanzastro opened this issue Sep 19, 2022 · 2 comments

Comments

@yanzastro
Copy link

I can use som.bmus to get the coordinates of bmus of the training data, but I want to calculate the coordinates of bmus of testing data from a pre-trained SOM. I can define something like:

def f(i, data):
    dmap = np.sum(((data[i] - som.codebook)**2)**0.5, axis=2)
    return np.asarray(np.unravel_index(np.argmin(dmap), dmap.shape, order='F'))

def get_test_bmus(som, data):    
    with Pool() as p:
        bmus = p.map(lambda i: f(i, data), np.arange(len(data)))  # use multiprocess since the testing data can be very large
    return np.asarray(bmus)

but I'm wondering if there is built-in method in a somoclu class that can do such job?

@xgdgsc
Copy link
Collaborator

xgdgsc commented Sep 20, 2022

@yanzastro
Copy link
Author

thank you for your reply! I tried this and found it's pretty slow when the data vector is very large, but using multiprocessing helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants