def condensation_nx( G, components) :
	"""
	G : DiGraph object. the nx.DiGraph attribute is extracted from this.

	components : 	Given components C_1 .. C_k which partition the nodes of G, the
	condensation graph cG has nodes <C_1> .. <C_k> and has edge
	(<C_i>,<C_j>) iff there was an edge in G from a node in C_i to a
	node in C_j.
	"""
	cG = DiGraph()
	cG.graph = nx.condensation( G.graph, components )
	return cG
Beispiel #2
0
    def prepare_regions( self ):
        """
        Partition the phase space into disjoint, recurrent regions.

        Must have initialized self with index_map matrix and
        region2gen dictionary, or used one of the load_from_* methods
        to initialize these values.
        """
        # returns a DiGraph
        self.map_on_regions = utils.index_map_to_region_map( self.index_map,
                                                             self.region2gen )

        # graph_mis from graphs.algorithms
        scc_list, scc_components, recurrent_regions = graph_mis( self.map_on_regions,
                                                                 return_rsccs=True )
        nbunch = [ scc_components[i] for i in recurrent_regions ]
        self.recurrent_subgraphs = []

        # the actual partition of phase space in graph format
        for n in nbunch:
            # ignore disjoint regions/nodes that have self-loops => no
            # entropy
            if len( n ) == 1:
                continue
            G = DiGraph()
            G.graph = self.map_on_regions.graph.subgraph( n )
            self.recurrent_subgraphs.append( G )

        # construct IndexMapProcessor for each disjoint region
        # assign entropies  of -1 to each recurrent region. 
        for region in self.recurrent_subgraphs:
            self.phase_space.append( [ IndexMapProcessor( self.index_map,
                                                          self.region2gen,
                                                          region,
                                                          debug=self.debug,
                                                          verbose=self.verbose ),
                                      -1  # initial entropy for region
                                       ] )
Beispiel #3
0
    ########################

debug = True
verbose = False

scc_list, scc_components, recurrent_regions = algorithms.graph_mis( map_on_regions,
                                                                    return_rsccs=True )
# separate nodes by recurrent component
nbunch = [ scc_components[i] for i in recurrent_regions ]
recurrent_subgraphs = []
for n in nbunch:
    # ignore self-loops, no entropy
    if len( n ) == 1:
        continue
    G = DiGraph()
    G.graph = map_on_regions.graph.subgraph( n )
    recurrent_subgraphs.append( G )

# compute entropy for each scc in the symbolic system
all_regions = []
for scc in recurrent_subgraphs:
    all_regions.append( IndexMapProcessor( hom_matrix, region2gen,
                                           scc, debug=debug, verbose=verbose ) )

# PARALLELIZE ME!
for job in all_regions:
    job.find_bad_edge_sets( 4 )  # argument == max path length
    job.cut_bad_edge_sets()

# print the best entropy for each SCC
for imp in all_regions: