#NEWLINE# def main( model ) : #NEWLINE# #INDENT# store = pd . HDFStore ( model ) #NEWLINE# from_ = store [ 'from_' ] [ 0 ] [ 0 ] #NEWLINE# to = store [ 'to' ] [ 0 ] [ 0 ] #NEWLINE# assert ( from_ == 0 ) #NEWLINE# trace_fpath = store [ 'trace_fpath' ] [ 0 ] [ 0 ] #NEWLINE# Psi_oz = store [ 'Psi_sz' ] . values #NEWLINE# count_z = store [ 'count_z' ] . values [ : , 0 ] #NEWLINE# obj2id = dict ( store [ 'source2id' ] . values ) #NEWLINE# Psi_oz = ( Psi_oz / Psi_oz . sum ( axis = 0 ) ) #NEWLINE# Psi_zo = ( Psi_oz * count_z ) . T #NEWLINE# Psi_zo = ( Psi_zo / Psi_zo . sum ( axis = 0 ) ) #NEWLINE# mem_size = store [ 'Dts' ] . values . shape [ 1 ] #NEWLINE# probs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# ll = 0.0 #NEWLINE# n = 0.0 #NEWLINE# with open ( trace_fpath ) as trace_file : #NEWLINE# #INDENT# for ( i , l ) in enumerate ( trace_file ) : #NEWLINE# #INDENT# if ( i >= to ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# n += 1 #NEWLINE# spl = l . strip ( ) . split ( '\t' ) #NEWLINE# ( _ , _ , s , d ) = spl #NEWLINE# if ( ( obj2id [ d ] , obj2id [ s ] ) not in probs ) : #NEWLINE# #INDENT# probs [ ( obj2id [ d ] , obj2id [ s ] ) ] = ( Psi_oz [ obj2id [ d ] ] * Psi_zo [ : , obj2id [ s ] ] ) . sum ( ) #NEWLINE# #UNINDENT# ll += np . log ( probs [ ( obj2id [ d ] , obj2id [ s ] ) ] ) #NEWLINE# #UNINDENT# #UNINDENT# print ( ( ( ( - 2 ) * ll ) + ( n * np . log ( ( count_z . shape [ 0 ] + sum ( Psi_oz . shape ) ) ) ) ) ) #NEWLINE# store . close ( )