Skip to content

Get bmu of testing data #164

@yanzastro

Description

@yanzastro

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions