#NEWLINE# def _build_table( analysis , duration , start , target , out_penalty ) : #NEWLINE# #INDENT# beats = analysis [ 'beats' ] #NEWLINE# trans_cost = np . copy ( analysis [ 'dense_dist' ] ) #NEWLINE# trans_cost [ : ( - 1 ) , : ] = trans_cost [ 1 : , : ] #NEWLINE# trans_cost [ ( - 1 ) , : ] = np . inf #NEWLINE# cost = np . empty ( ( len ( beats ) , len ( target ) ) ) #NEWLINE# prev_node = np . empty ( ( len ( beats ) , len ( target ) ) ) #NEWLINE# first_target = target [ 0 ] #NEWLINE# init = ( [ 0 ] * len ( start ) ) #NEWLINE# for ( i , label ) in enumerate ( start ) : #NEWLINE# #INDENT# if ( ( label == first_target ) or ( label is None ) or ( first_target is None ) ) : #NEWLINE# #INDENT# init [ i ] = 0.0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# init [ i ] = 1.0 #NEWLINE# #UNINDENT# #UNINDENT# cost [ : , 0 ] = init #NEWLINE# np . fill_diagonal ( trans_cost , np . inf ) #NEWLINE# min_jump = 4 #NEWLINE# if ( min_jump and ( min_jump > 0 ) ) : #NEWLINE# #INDENT# total_len = np . shape ( trans_cost ) [ 0 ] #NEWLINE# for idx in range ( total_len ) : #NEWLINE# #INDENT# for diag_idx in range ( ( - ( min_jump - 1 ) ) , min_jump ) : #NEWLINE# #INDENT# if ( ( 0 < ( idx + diag_idx ) < total_len ) and ( diag_idx != 1 ) ) : #NEWLINE# #INDENT# trans_cost [ ( idx , ( idx + diag_idx ) ) ] = np . inf #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# penalty = ( np . ones ( ( len ( beats ) , len ( target ) ) ) * np . array ( out_penalty ) ) #NEWLINE# penalty_window = 4 #NEWLINE# for n_i in xrange ( len ( beats ) ) : #NEWLINE# #INDENT# node_label = start [ n_i ] #NEWLINE# for l in xrange ( 1 , ( len ( target ) - 1 ) ) : #NEWLINE# #INDENT# prev_target = target [ ( l - 1 ) ] #NEWLINE# next_target = target [ ( l + 1 ) ] #NEWLINE# target_label = target [ l ] #NEWLINE# if ( ( node_label == target_label ) or ( target_label is None ) ) : #NEWLINE# #INDENT# penalty [ ( n_i , l ) ] = 0.0 #NEWLINE# #UNINDENT# #UNINDENT# for l in [ 0 , ( len ( target ) - 1 ) ] : #NEWLINE# #INDENT# target_label = target [ l ] #NEWLINE# if ( ( node_label == prev_target ) or ( target_label is None ) ) : #NEWLINE# #INDENT# penalty [ ( n_i , l ) ] = 0.0 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for l in xrange ( 1 , len ( target ) ) : #NEWLINE# #INDENT# tc = ( ( penalty [ : , l ] + trans_cost ) + cost [ : , ( l - 1 ) ] [ : , np . newaxis ] ) #NEWLINE# min_nodes = __fast_argmin_axis_0 ( tc ) #NEWLINE# min_vals = np . amin ( tc , axis = 0 ) #NEWLINE# cost [ : , l ] = min_vals #NEWLINE# prev_node [ : , l ] = min_nodes #NEWLINE# #UNINDENT# return ( cost , prev_node )