#NEWLINE# def mutual_information( M_c , X_Ls , X_Ds , Q , get_next_seed , n_samples = 1000 ) : #NEWLINE# #INDENT# assert ( len ( X_Ds ) == len ( X_Ls ) ) #NEWLINE# n_postertior_samples = len ( X_Ds ) #NEWLINE# n_cols = len ( M_c [ 'column_metadata' ] ) #NEWLINE# MI = [ ] #NEWLINE# Linfoot = [ ] #NEWLINE# for query in Q : #NEWLINE# #INDENT# assert ( len ( query ) == 2 ) #NEWLINE# assert ( ( query [ 0 ] >= 0 ) and ( query [ 0 ] < n_cols ) ) #NEWLINE# assert ( ( query [ 1 ] >= 0 ) and ( query [ 1 ] < n_cols ) ) #NEWLINE# X = query [ 0 ] #NEWLINE# Y = query [ 1 ] #NEWLINE# MI_sample = [ ] #NEWLINE# Linfoot_sample = [ ] #NEWLINE# for sample in range ( n_postertior_samples ) : #NEWLINE# #INDENT# X_L = X_Ls [ sample ] #NEWLINE# X_D = X_Ds [ sample ] #NEWLINE# if ( column_is_bounded_discrete ( M_c , X ) and column_is_bounded_discrete ( M_c , Y ) ) : #NEWLINE# #INDENT# MI_s = calculate_MI_bounded_discrete ( X , Y , M_c , X_L , X_D ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# MI_s = estimate_MI_sample ( X , Y , M_c , X_L , X_D , get_next_seed , n_samples = n_samples ) #NEWLINE# #UNINDENT# linfoot = mutual_information_to_linfoot ( MI_s ) #NEWLINE# MI_sample . append ( MI_s ) #NEWLINE# Linfoot_sample . append ( linfoot ) #NEWLINE# #UNINDENT# MI . append ( MI_sample ) #NEWLINE# Linfoot . append ( Linfoot_sample ) #NEWLINE# #UNINDENT# assert ( len ( MI ) == len ( Q ) ) #NEWLINE# assert ( len ( Linfoot_sample ) == len ( Q ) ) #NEWLINE# return ( MI , Linfoot )