#NEWLINE# def test_factor_graph( self ) : #NEWLINE# #INDENT# phi1 = Factor ( [ 'Alice' , 'Bob' ] , [ 3 , 2 ] , np . random . rand ( 6 ) ) #NEWLINE# phi2 = Factor ( [ 'Bob' , 'Charles' ] , [ 2 , 2 ] , np . random . rand ( 4 ) ) #NEWLINE# self . graph . add_edges_from ( [ ( 'Alice' , 'Bob' ) , ( 'Bob' , 'Charles' ) ] ) #NEWLINE# self . graph . add_factors ( phi2 , phi2 ) #NEWLINE# factor_graph = self . graph . to_factor_graph ( ) #NEWLINE# self . assertIsInstance ( factor_graph , FactorGraph ) #NEWLINE# self . assertListEqual ( sorted ( factor_graph . nodes ( ) ) , [ 'Alice' , 'Bob' , 'Charles' , 'phi_Alice_Bob' , 'phi_Bob_Charles' ] ) #NEWLINE# self . assertListEqual ( hf . recursive_sorted ( factor_graph . edges ( ) ) , [ [ 'Alice' , 'phi_Alice_Bob' ] , [ 'Bob' , 'phi_Alice_Bob' ] , [ 'Bob' , 'phi_Bob_Charles' ] , [ 'Charles' , 'phi_Bob_Charles' ] ] ) #NEWLINE# self . assertListEqual ( factor_graph . get_factors ( ) , [ phi1 , phi2 ] )