#NEWLINE# def _compute_period( self ) : #NEWLINE# #INDENT# '\n        Set ``self._period`` and ``self._cyclic_components_proj``.\n\n        Use the algorithm described in:\n        J. P. Jarvis and D. R. Shier,\n        "Graph-Theoretic Analysis of Finite Markov Chains," 1996.\n\n        ' #NEWLINE# if ( self . n == 1 ) : #NEWLINE# #INDENT# if ( self . csgraph [ ( 0 , 0 ) ] == 0 ) : #NEWLINE# #INDENT# self . _period = 1 #NEWLINE# self . _cyclic_components_proj = np . zeros ( self . n , dtype = int ) #NEWLINE# return None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _period = 1 #NEWLINE# self . _cyclic_components_proj = np . zeros ( self . n , dtype = int ) #NEWLINE# return None #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . is_strongly_connected ) : #NEWLINE# #INDENT# raise NotImplementedError ( 'Not defined for a non strongly-connected digraph' ) #NEWLINE# #UNINDENT# if np . any ( ( self . csgraph . diagonal ( ) > 0 ) ) : #NEWLINE# #INDENT# self . _period = 1 #NEWLINE# self . _cyclic_components_proj = np . zeros ( self . n , dtype = int ) #NEWLINE# return None #NEWLINE# #UNINDENT# ( node_order , predecessors ) = csgraph . breadth_first_order ( self . csgraph , i_start = 0 ) #NEWLINE# bfs_tree_csr = csgraph . reconstruct_path ( self . csgraph , predecessors ) #NEWLINE# non_bfs_tree_csr = ( self . csgraph - bfs_tree_csr ) #NEWLINE# non_bfs_tree_csr . eliminate_zeros ( ) #NEWLINE# level = np . zeros ( self . n , dtype = int ) #NEWLINE# for i in range ( 1 , self . n ) : #NEWLINE# #INDENT# level [ node_order [ i ] ] = ( level [ predecessors [ node_order [ i ] ] ] + 1 ) #NEWLINE# #UNINDENT# d = 0 #NEWLINE# for ( node_from , node_to ) in _csr_matrix_indices ( non_bfs_tree_csr ) : #NEWLINE# #INDENT# value = ( ( level [ node_from ] - level [ node_to ] ) + 1 ) #NEWLINE# d = gcd ( d , value ) #NEWLINE# if ( d == 1 ) : #NEWLINE# #INDENT# self . _period = 1 #NEWLINE# self . _cyclic_components_proj = np . zeros ( self . n , dtype = int ) #NEWLINE# return None #NEWLINE# #UNINDENT# #UNINDENT# self . _period = d #NEWLINE# self . _cyclic_components_proj = ( level % d )