#NEWLINE# def kl_est_sample( from_gen , of_gen , target_cells , constraints ) : #NEWLINE# #INDENT# 'Estimate Kullback-Liebler divergence of `of_gen` from `from_gen`.\n\n    Specifically, let P be the distribution over the given target\n    cells induced by the generator `from_gen` conditioned on the\n    constraints, and let Q be same induced by the `of_gen` generator.\n    This function computes and returns a one-point Monte-Carlo\n    estimate of the K-L of Q from P.\n    ' #NEWLINE# [ data ] = from_gen . simulate_joint ( target_cells , constraints ) #NEWLINE# targeted_data = [ ( i , j , x ) for ( ( i , j ) , x ) in zip ( target_cells , data ) ] #NEWLINE# from_assessment = from_gen . logpdf_joint ( targeted_data , constraints ) #NEWLINE# of_assessment = of_gen . logpdf_joint ( targeted_data , constraints ) #NEWLINE# return ( from_assessment - of_assessment )