#NEWLINE# def truncated_KL( self , V , Y = None , obs = None ) : #NEWLINE# #INDENT# "\n        KL divergence between variation and true posterior, dropping terms that\n        don't depend on the variational parameters\n\n        Parameters\n        ----------\n        V : WRITEME\n        Y : WRITEME\n        obs : WRITEME\n\n        Returns\n        -------\n        WRITEME\n        " #NEWLINE# assert ( Y is None ) #NEWLINE# assert ( obs is not None ) #NEWLINE# H_hat = obs [ 'H_hat' ] #NEWLINE# var_s0_hat = obs [ 'var_s0_hat' ] #NEWLINE# var_s1_hat = obs [ 'var_s1_hat' ] #NEWLINE# S_hat = obs [ 'S_hat' ] #NEWLINE# model = self . model #NEWLINE# for H_hat_v in get_debug_values ( H_hat ) : #NEWLINE# #INDENT# assert ( H_hat_v . min ( ) >= 0.0 ) #NEWLINE# assert ( H_hat_v . max ( ) <= 1.0 ) #NEWLINE# #UNINDENT# entropy_term = ( - model . entropy_hs ( H_hat = H_hat , var_s0_hat = var_s0_hat , var_s1_hat = var_s1_hat ) ) #NEWLINE# energy_term = model . expected_energy_vhs ( V , H_hat = H_hat , S_hat = S_hat , var_s0_hat = var_s0_hat , var_s1_hat = var_s1_hat ) #NEWLINE# for ( entropy , energy ) in get_debug_values ( entropy_term , energy_term ) : #NEWLINE# #INDENT# debug_assert ( ( not contains_nan ( entropy ) ) ) #NEWLINE# debug_assert ( ( not contains_nan ( energy ) ) ) #NEWLINE# #UNINDENT# KL = ( entropy_term + energy_term ) #NEWLINE# return KL