def test_rigorous_henon(depth, box, plot=False, fpath="../sandbox/henon_test"):

    # our tree, mapper, enclosure
    tree = Tree(box, full=True)
    m = HenonMapper()
    ce = CombEnc(tree, m)

    for d in range(depth):
        # print 'at depth', d
        ce.tree.subdivide()
        # print 'subdivided:', ce.tree.size, 'boxes'
        ce.update()
        # print 'enclosure updated'
        I = graph_mis(ce.mvm)
        # print 'len(I) = ', len(I)
        # print ''
        # now remove all boxes not in I (the maximal invariant set)
        ce.tree.remove(list(set(range(ce.tree.size)) - set(I)))

    if plot:
        # now display the tree!
        boxes = ce.tree.boxes()
        gfx.show_uboxes(boxes, col="c", ecol="b")
    print "done with rigorous henon @ depth", depth
    print ""

    fname = fpath + dot + "CE" + dot + str(depth)
    utils.write_dot(ce.mvm.graph, fname + ".dot")
    utils.pickle_tree(ce.tree, fname + ".pkl")
    def shift_equivalent_map( self ):
        """
        Graphical representation of the shift equivalence proved in
        Theorem 3.1 and Lemmas 3.2-3.4.

        The required sets of nodes V1, V2, and V3 are computed as
        follows:
            Given G = (V,E), with V = {V1,V2,V3},

            1. Find strongly connected components (scc) of G. Labeled
            by nodes V2.

            2. Perform a forward depth-first search; then perform
            backward depth-first search by reversing the orientation
            on the edges. This locates generators that are not
            connected to cycles. Labeled by nodes V1 \cup V3.

            3. Trim self.index_map to include only those nodes in
                     V2 = V\(V1 \cup V3)

            4. The nodes in V1 \cup V3 are stored in the attrribute
            'non_mis_nodes'.
        """
        # determine the maximal invariant set of generators in
        # self.index_map (1 & 2 above)
        mis_nodes = algorithms.graph_mis( self.index_map )
        nbunch = set( self.index_map.nodes() )
        # compute V2
        self.non_mis_nodes = nbunch.difference( mis_nodes )
        # remove nodes to form subgraph of map on generators
        # containing only nodes that are part of the maximally
        # invariant set.
        self.index_map.remove_nodes_from( self.non_mis_nodes )
Пример #3
0
def max_invariant_set( I, transition ):
    """Restrict a region I to the maximal invariant set within that
    region. 

    Return indices of nodes in the maximal invariant set.

    """
    R = transition.subgraph( I )
    S = algorithms.graph_mis( R )
    return set( S )
Пример #4
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
                                       ] )
    # convert nodes to integers starting at 0
    H = nx.convert_node_labels_to_integers( FR.mvm.graph, first_label=0 )
    
    # True Henon
    # our tree, mapper, enclosure
    tree = Tree(box,full=True)
    m = HenonMapper()
    ce = CombEnc(tree,m)

    for d in range(depth):
        print 'at depth', d
        ce.tree.subdivide()
        print 'subdivided:', ce.tree.size, 'boxes'
        ce.update()
        #print 'enclosure updated'
        I = graph_mis(ce.mvm)
        #print 'len(I) = ', len(I)
        print ''
        # now remove all boxes not in I (the maximal invariant set)
        ce.tree.remove(list(set(range(ce.tree.size))-set(I)))

    # now display the tree!
    boxes = ce.tree.boxes()
    gfx.show_uboxes(boxes, col='c', ecol='b')

    print "Plotting boxes... "
    fig = FR.show_boxes()
    fig = FR.show_error_boxes( color='r', fig=fig )

    confidence( ce.mvm, H )
 def graph_mis( self ):
     self.mis = alg.graph_mis( self.mvm )
Пример #7
0
if 0:
    hom_matrix = utils.load_matlab_matrix( 'leslie_index.mat', 'hom_matrix' )
    region2gen = utils.convert_matlab_gens( 'leslie_gens.mat' )
    map_on_regions = utils.index_map_to_region_map( hom_matrix, region2gen, shift=-1)


    ########################
    #  
    # APPEARS THAT BAD EDGE SETS ARE BEING THROWN INTO ONE (1) SET. CHECK THIS!!
    #
    ########################

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,
 def graph_maximal_inv_set(self):
     self.mis = alg.graph_mis(self.mvm)
import networkx as nx
from rads.graphs import DiGraph
from rads.graphs.algorithms import graph_mis

if __name__ == "__main__":
	E = [(0, 8), (0, 5), (1, 19), (1, 10), (1, 3), (1, 5), (2, 11), (2, 4), (2, 7), (4, 19), (6, 19), (6, 3), (6, 5), (7, 19), (7, 3), (8, 0), (9, 16), (9, 14), (9, 6), (10, 3), (10, 12), (11, 19), (11, 6), (12, 3), (12, 12), (13, 8), (13, 19), (13, 11), (13, 5), (14, 1), (14, 9), (16, 3), (17, 1), (18, 16), (18, 13), (19, 9)]
	G = DiGraph()
	G.add_edges_from(E)
	correct_answer = [0, 1, 6, 8, 9, 10, 12, 14, 19]
	my_answer = sorted(graph_mis(G))
	print 'graph_mis(G) =  ', my_answer
	print 'correct answer =', correct_answer

	E = [(0,1), (1,2), (2,0), (2,3), (3,4), (1,5), (5,6), (6,6), (7,0), (8,7)]
	G = DiGraph()
	G.add_edges_from(E)
	my_answer = sorted(graph_mis(G))
	print 'graph_mis(G) =  ', my_answer
	print 'correct answer =', [0,1,2,5,6]