#NEWLINE# @ timeit ( logging . DEBUG ) #NEWLINE# def find_bmu( self , input_matrix , njb = 1 ) : #NEWLINE# #INDENT# '\n        Finds the best matching unit (bmu) for each input data from the input matrix. It does all at once parallelizing\n        the calculation instead of going through each input and running it against the codebook.\n\n        :param input_matrix: numpy matrix representing inputs as rows and features/dimension as cols\n        :param njb: number of jobs to parallelize the search\n        :returns: the best matching unit for each input\n        ' #NEWLINE# dlen = input_matrix . shape [ 0 ] #NEWLINE# y2 = np . einsum ( 'ij,ij->i' , self . codebook . matrix , self . codebook . matrix ) #NEWLINE# parallelizer = Parallel ( n_jobs = njb , pre_dispatch = '3*n_jobs' ) #NEWLINE# chunk_bmu_finder = delayed ( _chunk_based_bmu_find ) #NEWLINE# row_chunk = ( lambda part : ( ( part * dlen ) // njb ) ) #NEWLINE# col_chunk = ( lambda part : min ( ( ( ( part + 1 ) * dlen ) // njb ) , dlen ) ) #NEWLINE# b = parallelizer ( ( chunk_bmu_finder ( input_matrix [ row_chunk ( i ) : col_chunk ( i ) ] , self . codebook . matrix , y2 ) for i in xrange ( njb ) ) ) #NEWLINE# bmu = np . asarray ( list ( itertools . chain ( * b ) ) ) . T #NEWLINE# del b #NEWLINE# return bmu